The SignalWire .NET SDK provides a unified security configuration system with secure defaults for HTTPS, basic authentication, and security headers.
using SignalWire.Agent;
using System.Collections.Generic;
// Shared context for the fragments below: a constructed `agent`.
AgentBase agent = new AgentBase(new AgentOptions { Name = "a", Route = "/a" });export SWML_SSL_ENABLED=true
export SWML_SSL_CERT_PATH=/path/to/cert.pem
export SWML_SSL_KEY_PATH=/path/to/key.pem
export SWML_DOMAIN=yourdomain.comBasic auth is enabled by default with auto-generated credentials:
export SWML_BASIC_AUTH_USER=myusername
export SWML_BASIC_AUTH_PASSWORD=mysecurepassword| Variable | Default | Description |
|---|---|---|
SWML_SSL_ENABLED |
false |
Enable HTTPS |
SWML_SSL_CERT_PATH |
- | Path to SSL certificate |
SWML_SSL_KEY_PATH |
- | Path to SSL private key |
SWML_SSL_VERIFY_MODE |
CERT_REQUIRED |
Peer-certificate verification mode |
SWML_DOMAIN |
- | Domain name for URL generation |
When your SignalWire endpoint presents a certificate issued by a private or
self-signed CA (a dedicated space, an on-prem deployment, or a TLS-terminating
proxy), point the client at the issuing CA bundle with these env vars. Each names
a PEM/DER file whose CA is added as an additional trust anchor: a chain that
already validates under the OS trust store is accepted unchanged, and a chain
whose only defect is an untrusted root is re-validated against the supplied CA.
Any other TLS defect (hostname mismatch, expired/unavailable cert) still fails —
setting these does not disable verification. Unset → the OS trust store alone
is used. These are the .NET analogue of pointing Python's REST session at a
verify CA bundle and building the RELAY SSL context from a cafile.
| Variable | Default | Description |
|---|---|---|
SIGNALWIRE_REST_CA_FILE |
- | Path to a CA trust bundle (PEM/DER) added as an extra trust anchor for the REST HTTP client |
SIGNALWIRE_RELAY_CA_FILE |
- | Path to a CA trust bundle (PEM/DER) added as an extra trust anchor for the RELAY WebSocket client |
| Variable | Default | Description |
|---|---|---|
SWML_BASIC_AUTH_USER |
signalwire |
Basic auth username |
SWML_BASIC_AUTH_PASSWORD |
auto-generated | Basic auth password (32-char token) |
SIGNALWIRE_SIGNING_KEY |
- | Signing key used to validate inbound webhook signatures |
| Variable | Default | Description |
|---|---|---|
SWML_RATE_LIMIT |
60 |
Requests per minute per IP |
SWML_USE_HSTS |
true |
Emit the HTTP Strict-Transport-Security header |
SWML_HSTS_MAX_AGE |
31536000 |
HSTS max-age in seconds (default 1 year) |
| Variable | Default | Description |
|---|---|---|
SWML_MAX_REQUEST_SIZE |
10485760 |
Maximum inbound request body size in bytes (default 10MB) |
SWML_REQUEST_TIMEOUT |
30 |
Per-request timeout in seconds |
SWML_ALLOW_PRIVATE_URLS |
false |
Allow SWML/webhook URLs that resolve to private/loopback addresses (SSRF guard bypass) |
When no credentials are provided, the SDK generates secure credentials automatically:
using System;
using SignalWire.Agent;
var agent = new AgentBase(new AgentOptions { Name = "my-agent" });
// Credentials are auto-generated; GetBasicAuthCredentials() returns the resolved pair
var (user, password) = agent.GetBasicAuthCredentials();
Console.WriteLine($"User: {user}");
Console.WriteLine($"Pass: {password}");using System;
using SignalWire.Agent;
var agent = new AgentBase(new AgentOptions
{
Name = "my-agent",
BasicAuthUser = "custom-user",
BasicAuthPassword = "custom-password-123",
});SWAIG webhook URLs automatically include basic auth credentials:
http://signalwire:abc123@localhost:3000/agent/swaig
This ensures that only SignalWire can call your SWAIG endpoints.
All responses include security headers:
| Header | Value | Purpose |
|---|---|---|
X-Content-Type-Options |
nosniff |
Prevent MIME sniffing |
X-Frame-Options |
DENY |
Prevent clickjacking |
Cache-Control |
no-store |
Prevent caching of sensitive data |
Content-Type |
application/json |
Explicit content type |
When behind a reverse proxy, set the proxy URL manually:
agent.ManualSetProxyUrl("https://myagent.example.com");This ensures SWAIG webhook URLs and post-prompt URLs use the correct public address.
- Enable HTTPS via
SWML_SSL_ENABLED=true - Set explicit basic auth credentials (do not rely on auto-generated in production)
- Configure a reverse proxy (nginx, Caddy, etc.) for TLS termination
- Set
SWML_DOMAINto your public domain - Use
ManualSetProxyUrl()when behind a load balancer - Store credentials in environment variables, not in source code