SecurityConfig

View as MarkdownOpen in Claude

SecurityConfig provides centralized security settings for all SignalWire services. It loads settings from environment variables and optional config files, handling SSL/TLS, CORS, host allowlists, rate limiting, HSTS, and basic authentication credentials.

1from signalwire.core.security_config import SecurityConfig

A global default instance is available at signalwire.core.security_config.security_config for backward compatibility. Services can create their own instances with service-specific config files.

Properties

ssl_enabled
boolDefaults to false

Whether HTTPS is enabled.

ssl_cert_path
Optional[str]

Path to the SSL certificate file. Required when ssl_enabled is True.

ssl_key_path
Optional[str]

Path to the SSL private key file. Required when ssl_enabled is True.

domain
Optional[str]

Domain name for SSL certificates and URL generation.

ssl_verify_mode
strDefaults to CERT_REQUIRED

SSL certificate verification mode.

allowed_hosts
list[str]Defaults to ["*"]

List of allowed hostnames. ["*"] accepts all hosts.

cors_origins
list[str]Defaults to ["*"]

List of allowed CORS origins. ["*"] accepts all origins.

max_request_size
intDefaults to 10485760

Maximum request body size in bytes (default 10 MB).

rate_limit
intDefaults to 60

Rate limit in requests per minute.

request_timeout
intDefaults to 30

Request timeout in seconds.

use_hsts
boolDefaults to true

Enable HTTP Strict Transport Security when serving over HTTPS.

hsts_max_age
intDefaults to 31536000

HSTS max-age in seconds (default 1 year).

basic_auth_user
Optional[str]

Basic auth username. Defaults to "signalwire" when accessed via get_basic_auth().

basic_auth_password
Optional[str]

Basic auth password. Auto-generated if not set when accessed via get_basic_auth().

Methods

Example

1from signalwire.core.security_config import SecurityConfig
2
3# Auto-discover config file
4security = SecurityConfig()
5print(f"SSL: {security.ssl_enabled}, HSTS: {security.use_hsts}")
6
7# Explicit config file
8security = SecurityConfig(config_file="/etc/myapp/config.json")
9
10# Service-specific config
11security = SecurityConfig(service_name="mcp")