Security
Security for voice AI agents requires thinking beyond traditional web application security. Voice interfaces introduce unique attack vectors: social engineering through conversation, toll fraud, unauthorized data access via verbal manipulation, and compliance concerns around recorded conversations.
This chapter covers the security mechanisms built into the SDK and best practices for building secure voice agents.
Threat Model for Voice AI Agents
Understanding potential threats helps you design appropriate defenses:
Security Layers
The SignalWire Server SDK implements multiple security layers:
Layer 1: Transport Security (HTTPS)
- TLS encryption in transit
- Certificate validation
Layer 2: Request signature validation
- HMAC signature on the POST requests SignalWire sends to your agent
- Checked against your project’s signing key
Layer 3: HTTP Basic Authentication
- Username/password validation
- Applied to all webhook endpoints
Layer 4: Function Token Security (Optional)
- Per-function security tokens
- Cryptographic validation
Request signature validation
SignalWire signs the POST requests it sends to your agent: the request for its SWML, each SWAIG
function call, and the post-prompt summary. Each request carries an X-Signalwire-Signature header
and an X-Signalwire-SHA256-Signature header, HMAC digests computed with your project’s signing
key over the request URL and the raw body. There is no setting to enable signing, so the only step
is giving the agent the key. In the rare case SignalWire can’t compute a signature, it sends the
request unsigned, as described in
Plan for unsigned requests, redirects, and retries.
With a signing key set, the agent checks the signature on every POST to its SWML, SWAIG, and
post-prompt endpoints. An unsigned or mis-signed request gets 403 Forbidden and never reaches your
code. Without a key, the agent logs a warning at startup and accepts unsigned requests.
Copy the key from the Signing Key field on the API Credentials page of your Dashboard. Each project has its own key, so use the key belonging to the project that handles the call.
Configuring the signing key
Option 1: Environment variable (recommended)
Option 2: Pass it to the agent
Install the latest Server SDK to get signature validation.
The signature covers the exact URL SignalWire requested. Behind a reverse proxy or a tunnel, set
SWML_PROXY_URL_BASE to your public base URL, as described under HTTPS configuration below, so the
agent checks the signature against that URL rather than the one the proxy forwarded to it.
For the full list of signed requests, how the signature is computed, and how unsigned and redirected requests behave, see Verify SWML request signatures.
HTTP Basic Authentication
Every request to your agent is protected by HTTP Basic Auth.
How It Works
- SignalWire sends request with
Authorization: Basic <base64-encoded-credentials>header - Agent extracts header and Base64 decodes credentials
- Agent splits the decoded string into username and password
- Agent compares credentials against configured values
- Result: Match returns 200 + response; No match returns 401 Denied
Configuring Credentials
Option 1: Environment Variables (Recommended for production)
Option 2: Let SDK Generate Credentials (Development)
If you don’t set credentials, the SDK:
- Uses username:
signalwire - Generates a random password on each startup
- Prints the password to the console
Use generated credentials only in development. The agent puts its credentials in every webhook URL it generates, so when a restart generates a new password, the calls already in progress fail their next function call and their post-prompt summary. Set fixed credentials in production.
Credentials in Your Agent
Python
TypeScript
Function Token Security
For sensitive operations, enable per-function token validation.
How Function Tokens Work
SWML Generation (GET /)
- Agent generates SWML
- For each secure function, generate unique token
- Token embedded in function’s
web_hook_url
Function Call (POST /swaig)
- SignalWire calls webhook URL with token
- Agent extracts token from request
- Agent validates token cryptographically
- If valid, execute function
- If invalid, reject with 403
Enabling Token Security
Enable per-function token validation with the secure flag:
Python
TypeScript
Token Generation
Tokens are generated using cryptographic hashing:
Token secret and lifetime
The agent signs function tokens, and the token on its post-prompt URL, with a secret. If you don’t set one, each process generates its own at startup. Tokens issued before a restart then stop validating, and so do tokens issued by another replica behind the same load balancer, so calls in progress fail their next secure function call and their post-prompt summary.
Tokens also expire, one hour after the agent issues them by default. A call that outlasts its tokens loses its secure functions and its post-prompt summary.
In production, set a fixed secret, the same on every replica, and a token lifetime longer than your longest call:
The token secret is separate from your project’s signing key: the signing key proves a request came from SignalWire, and the token secret proves a function call belongs to the call your agent issued the token for.
HTTPS Configuration
For production, enable HTTPS:
Using SSL Certificates
The TypeScript AgentBase does not expose SSL directly — agent.serve()
accepts only { host, port }. For production TypeScript deployments, use
the reverse-proxy pattern below (recommended) or see the WebService
reference for programmatic SSL.
Using a Reverse Proxy (Recommended)
Most production deployments use a reverse proxy for SSL:
Traffic Flow: SignalWire -> HTTPS -> nginx/Caddy (SSL termination) -> HTTP -> Your Agent (localhost:3000)
Benefits:
- SSL handled by proxy
- Easy certificate management
- Load balancing
- Additional security headers
Set the proxy URL so your agent generates correct webhook URLs and checks request signatures against the public URL:
Security Best Practices
1. Never Commit Credentials
2. Use Strong Passwords
3. Validate All Inputs
4. Use Secure Functions for Sensitive Operations
5. Log Security Events
6. Implement Rate Limiting
Configuring SignalWire Webhooks
When setting up your phone number in SignalWire:
Voice AI Security Considerations (OWASP-Style)
Voice AI agents face unique security challenges. Apply these principles:
1. Never Trust Voice Input
Voice input can be manipulated through:
- Prompt injection via speech
- Playing audio recordings
- Background noise injection
Mitigation:
2. Limit Function Capabilities
Only give the agent functions it needs:
3. Verify Caller Identity
Don’t assume caller ID is trustworthy for sensitive operations:
4. Implement Action Confirmation
For destructive or financial operations, require verbal confirmation:
Audit Logging
Comprehensive logging is essential for security monitoring and incident response.
What to Log
Log Security Events
Incident Response
Prepare for security incidents with these practices:
1. Detection
Monitor for anomalies:
- Unusual call volumes
- High function call rates
- Failed authentication attempts
- Large transaction attempts
- After-hours activity
2. Response Plan
Document how to respond:
- Identify: What happened and scope of impact
- Contain: Disable affected functions or agent
- Investigate: Review audit logs
- Remediate: Fix vulnerabilities
- Recover: Restore normal operation
- Document: Record lessons learned
3. Emergency Shutdown
Implement ability to quickly disable sensitive operations:
Production Hardening Checklist
Before deploying to production:
Infrastructure
- HTTPS enabled with valid certificates
- Signing key set, so request signatures are validated
- Strong, fixed Basic Auth credentials (32+ characters), the same on every replica
- Fixed function token secret (
SIGNALWIRE_SWAIG_SECRET), the same on every replica - Token lifetime longer than your longest call
- Reverse proxy configured (nginx, Caddy)
- Firewall rules limit access
- Monitoring and alerting configured
Application
- All sensitive functions use
secure=True - Input validation on all function parameters
- Rate limiting implemented
- Audit logging enabled
- Error messages don’t leak internal details
Prompts
- Security boundaries defined in prompts
- Confirmation required for sensitive actions
- System prompt instructions protected
- No excessive capability disclosure
Operational
- Credentials rotated regularly
- Logs collected and monitored
- Incident response plan documented
- Regular security reviews scheduled
- Dependencies kept updated
Summary
Next Steps
You now understand the core concepts of the SignalWire Server SDK. Let’s move on to building agents.