get_security_headers

View as MarkdownOpen in Claude

Get security headers to add to HTTP responses.

Parameters

is_https
boolDefaults to false

Whether the connection is over HTTPS. When True and use_hsts is enabled, the Strict-Transport-Security header is included.

Returns

dict[str, str] — Dictionary of security headers including X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, and optionally Strict-Transport-Security.

Example

from signalwire.core.security_config import SecurityConfig
security = SecurityConfig()
headers = security.get_security_headers(is_https=False)
https_headers = security.get_security_headers(is_https=True)
print(headers)
# {'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', ...}
print(https_headers)
# Includes 'Strict-Transport-Security' header when HSTS is enabled