Skip to main content

A security-focused Python library for validating and handling webhooks safely

Project description

Webhook Guardian 🛡️

A beginner-friendly Python library for secure webhook handling and validation.

🎯 What is Webhook Guardian?

Webhook Guardian is a security-focused library that helps developers safely receive and validate webhooks from external services. It protects against common webhook security vulnerabilities like replay attacks, signature spoofing, and unauthorized requests.

🔒 Security Features

  • HMAC Signature Verification - Verify webhooks are from trusted sources
  • Replay Attack Prevention - Timestamp validation to prevent reused requests
  • Rate Limiting - Protect against webhook spam and abuse
  • IP Whitelist Validation - Only accept webhooks from authorized IPs
  • Request Size Limits - Prevent oversized payload attacks
  • Comprehensive Logging - Track and monitor webhook activity

🚀 Quick Start

Installation

pip install webhook-guardian

Basic Usage

from webhook_guardian import WebhookValidator

# Initialize the validator with your secret
validator = WebhookValidator(
    secret="your-webhook-secret",
    tolerance_seconds=300  # Allow 5 minutes clock skew
)

# In your webhook endpoint
def handle_webhook(request):
    # Validate the webhook
    if validator.verify_request(
        payload=request.body,
        signature=request.headers.get('X-Hub-Signature-256'),
        timestamp=request.headers.get('X-Timestamp')
    ):
        # Process the webhook safely
        process_webhook_data(request.body)
        return {"status": "success"}
    else:
        # Reject invalid webhook
        return {"error": "Invalid webhook"}, 401

Advanced Configuration

from webhook_guardian import WebhookGuardian

# Full-featured webhook handler
guardian = WebhookGuardian(
    secret="your-secret",
    allowed_ips=["192.168.1.100", "10.0.0.0/8"],
    max_payload_size=1024 * 1024,  # 1MB limit
    rate_limit={"requests": 100, "window": 3600},  # 100 req/hour
    enable_logging=True
)

# Validate with all security checks
result = guardian.validate_webhook(request)
if result.is_valid:
    process_webhook(request.body)
else:
    logger.warning(f"Invalid webhook: {result.error_message}")

📚 Documentation

🧪 Testing

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=webhook_guardian

🛠️ Development

# Clone the repository
git clone https://github.com/rebzie22/webhook-guardian.git
cd webhook-guardian

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by common webhook security vulnerabilities
  • Built for developers who want to handle webhooks securely
  • Designed with beginners in mind

📞 Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webhook_guardian-0.1.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webhook_guardian-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file webhook_guardian-0.1.0.tar.gz.

File metadata

  • Download URL: webhook_guardian-0.1.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for webhook_guardian-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6701b9b8d791d567cf43419e86287787a98caebdd151cc20d04e03253933bc00
MD5 984953fd65f3c75d78d73e3b2eec350c
BLAKE2b-256 890eb0e9fd2dc4bb1bed3e11365fd24bca43edca62d6379c964b8d42322ce7d7

See more details on using hashes here.

File details

Details for the file webhook_guardian-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for webhook_guardian-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 788926de1ee0ddb6a052ac92375cf0df5be35082a371ca2af7807462ac8f5489
MD5 e23757c72fc84880ed37cdd84dfc7388
BLAKE2b-256 7d2c894704f84210adcfe40b25711b6037a026d75a3b3b4b76ffd58c108462d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page