Authentication overview

Svix utilizes a two-pronged approach to authentication, addressing both API access and webhook event security. For interacting with the Svix management API (e.g., creating applications, endpoints, or sending messages), API keys are the primary mechanism. These keys act as bearer tokens, granting authorized access to your Svix resources. When Svix sends webhooks to your configured endpoints, it includes a digital signature in the request headers. This signature allows your application to verify the authenticity and integrity of the incoming webhook, ensuring it originated from Svix and was not altered during transmission. This dual strategy helps maintain secure communication for both programmatic control and event consumption within an event-driven architecture.

The use of separate authentication methods for API access and webhook verification aligns with the principle of least privilege. An API key grants broad permissions to manage your Svix account, while a webhook secret only enables verification of incoming events, preventing unauthorized manipulation of your Svix infrastructure. This distinction is fundamental to maintaining a secure and auditable event delivery system, as detailed in the Svix webhook verification documentation.

Supported authentication methods

Svix supports distinct authentication methods tailored for different interaction types:

  1. API Keys (Bearer Token Authentication): This method is used for authenticating requests made to the Svix management API. When you interact with the Svix API programmatically, whether directly via HTTP requests or through one of the Svix client libraries, an API key is included in the Authorization header as a Bearer token. These keys are associated with specific permissions (e.g., manage applications, manage messages) and should be treated as sensitive credentials.
  2. Webhook Signing (HMAC-SHA256): This method is used by your application to verify the authenticity and integrity of incoming webhooks sent by Svix. When Svix dispatches a webhook, it computes an HMAC-SHA256 signature using a unique signing secret associated with your webhook endpoint. This signature is included in the svix-signature HTTP header. Your application then recomputes the signature using the same secret and compares it to the one provided by Svix. A match confirms the webhook's origin and that its payload has not been tampered with, a critical step for securing webhook endpoints.

Authentication Methods Table

Method When to Use Security Level / Purpose
API Keys (Bearer Token) Accessing the Svix API to manage applications, endpoints, and send messages. High. Grants programmatic control over your Svix account. Requires secure storage and transmission.
Webhook Signing (HMAC-SHA256) Verifying incoming webhook payloads sent by Svix to your application endpoints. High. Ensures authenticity and integrity of webhook events. Prevents spoofing and tampering.

Getting your credentials

Accessing and managing your Svix credentials involves using the Svix Dashboard or the Svix API itself.

For API Keys:

  1. Through the Svix Dashboard:
    • Log in to your Svix Dashboard.
    • Navigate to the 'Settings' section.
    • Select 'API Keys' from the sidebar.
    • Click 'Create new API Key'. You will be prompted to give it a name and select the appropriate permissions (e.g., 'Application Management', 'Message Sending').
    • Once created, the API key will be displayed. Copy it immediately, as it will not be shown again for security reasons. Store this key securely.
  2. Through the Svix API:
    • You can programmatically create and manage API keys using an existing API key with sufficient permissions. Refer to the Svix API Reference for API Key management for detailed endpoint specifications and request examples.

For Webhook Signing Secrets:

Each webhook endpoint you create in Svix has an associated signing secret. This secret is crucial for verifying incoming webhooks.

  1. Through the Svix Dashboard:
    • Log in to your Svix Dashboard.
    • Go to 'Applications', then select the specific application that contains your webhook endpoint.
    • Under the 'Endpoints' tab, click on the endpoint you wish to configure.
    • The 'Signing Secret' will be displayed. You can copy it directly from this page. If you need to rotate the secret, there is an option to generate a new one.
  2. Through the Svix API:

Authenticated request example

This example demonstrates how to make an authenticated request to the Svix API using an API key to create a new application, and then how to verify an incoming webhook payload using a signing secret with Python.

1. Authenticating with an API Key (Python - Create Application)

To interact with the Svix API, you'll typically use one of their SDKs. Here's a Python example using the svix-python library to create a new application:


from svix.svix import Svix
from svix.internal.openapi.models import ApplicationIn
import os

# Retrieve your API key from environment variables for security
SVIX_API_KEY = os.environ.get("SVIX_AUTH_TOKEN")

if not SVIX_API_KEY:
    raise ValueError("SVIX_AUTH_TOKEN environment variable not set.")

# Initialize the Svix client with your API key
svix = Svix(SVIX_API_KEY)

try:
    # Define the new application data
    new_app = ApplicationIn(name="My New Webhook App")

    # Create the application
    application = svix.application.create(new_app)

    print(f"Application created successfully: {{application.name}} (ID: {{application.id}})")
except Exception as e:
    print(f"Error creating application: {{e}}")

In this example, the SVIX_API_KEY is passed during the initialization of the Svix client, which then automatically includes it as a Bearer token in the Authorization header for subsequent API calls. This is the standard way to authenticate with the Svix management API using their SDKs, as detailed in the Svix SDK documentation.

2. Verifying an Incoming Webhook (Python - Flask)

When Svix sends a webhook to your endpoint, you must verify its signature. Here's a Python Flask example:


from flask import Flask, request, abort
from svix.webhooks import Webhook, WebhookVerificationError
import os

app = Flask(__name__)

# Retrieve your webhook signing secret from environment variables
# This secret is specific to the endpoint receiving the webhook
WEBHOOK_SECRET = os.environ.get("SVIX_WEBHOOK_SECRET")

if not WEBHOOK_SECRET:
    raise ValueError("SVIX_WEBHOOK_SECRET environment variable not set.")

@app.route('/webhook', methods=['POST'])
def webhook_receiver():
    try:
        # Get the payload, headers, and signature from the request
        payload = request.data
        headers = request.headers
        
        # Initialize the Webhook verifier with your secret
        wh = Webhook(WEBHOOK_SECRET)
        
        # Verify the webhook payload
        verified_payload = wh.verify(payload, headers)
        
        print("Webhook verified successfully!")
        print(f"Received event: {{verified_payload}}")
        
        # Process the event...
        
        return "OK", 200
        
    except WebhookVerificationError as e:
        print(f"Webhook verification failed: {{e}}")
        abort(400) # Bad Request
    except Exception as e:
        print(f"An unexpected error occurred: {{e}}")
        abort(500) # Internal Server Error

if __name__ == '__main__':
    app.run(port=5000)

In this webhook example, the Webhook class from the svix-python library handles the complex cryptographic operations. It extracts the signature from the svix-signature header, the timestamp from svix-timestamp, and uses your provided WEBHOOK_SECRET to recompute and compare the signature. If verification fails, a WebhookVerificationError is raised, preventing the processing of potentially malicious or invalid webhooks. This process is crucial for secure webhook processing.

Security best practices

Adhering to security best practices is essential when integrating with Svix to protect your API keys, webhook secrets, and the integrity of your event-driven systems.

  • API Key Management:
    • Environment Variables: Never hardcode API keys directly into your source code. Store them as environment variables (e.g., SVIX_AUTH_TOKEN) or use a secure secrets management service.
    • Least Privilege: Create API keys with the minimum necessary permissions. For example, if an application only needs to send messages, grant it only 'Message Sending' permissions, not 'Application Management'.
    • Rotation: Regularly rotate your API keys, especially if there's any suspicion of compromise. The Svix Dashboard and API allow you to generate new keys and revoke old ones.
    • Access Control: Restrict access to API keys to only authorized personnel and systems.
  • Webhook Secret Management and Verification:
    • Unique Secrets Per Endpoint: Use a unique signing secret for each webhook endpoint. This limits the blast radius if one secret is compromised.
    • Environment Variables/Secrets Manager: Like API keys, store webhook secrets securely in environment variables or a secrets manager.
    • Always Verify Signatures: Implement signature verification for every incoming webhook from Svix. Never process a webhook payload without first verifying its authenticity and integrity. This prevents attackers from sending forged webhooks.
    • Timestamp Verification: Svix includes a timestamp in the svix-timestamp header. When verifying, ensure this timestamp is recent (e.g., within 5 minutes) to mitigate replay attacks. The Svix SDKs typically handle this automatically during verification.
    • Secret Rotation: Periodically rotate your webhook signing secrets. The Svix Dashboard provides an option to generate new secrets for your endpoints.
  • Endpoint Security:
    • HTTPS Only: Ensure your webhook receiving endpoints are served over HTTPS to encrypt data in transit. Svix only sends webhooks to HTTPS endpoints.
    • Firewall/Network Restrictions: If possible, restrict network access to your webhook endpoints to only allow traffic from Svix's known IP ranges. While Svix uses a CDN, checking the User-Agent header for Svix-Webhook can also provide an initial layer of filtering, though it's not a substitute for signature verification.
    • Error Handling: Implement robust error handling and logging for webhook processing, including verification failures. This helps in identifying potential attacks or misconfigurations.
  • Logging and Monitoring:
    • Monitor access logs for your Svix API keys and webhook endpoints for unusual activity.
    • Log all webhook verification attempts and their outcomes. Alert on repeated verification failures.