SecurityHeadersPlugin Schema

Schema definition for the Security Headers Plugin, which adds essential security HTTP headers to protect against common web vulnerabilities.

Schema Information

Property Value
Schema URL https://rustybeam.net/schema/SecurityHeadersPlugin
Parent Schema https://rustybeam.net/schema/UtilityPlugin
Description Security HTTP headers for protection against XSS, clickjacking, and other web vulnerabilities

Properties

Property Type Cardinality Description
csp_policy https://rustybeam.net/schema/Text 0..1 Content Security Policy directive. Defaults to "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'".
hsts_max_age https://rustybeam.net/schema/Number 0..1 HTTP Strict Transport Security max-age in seconds. Defaults to 31536000 (1 year). Set to 0 to disable HSTS.
hsts_include_subdomains https://rustybeam.net/schema/Boolean 0..1 Whether to include subdomains in HSTS policy. Defaults to true. Adds includeSubDomains directive.
hsts_preload https://rustybeam.net/schema/Boolean 0..1 Whether to enable HSTS preload. Defaults to false. Adds preload directive for browser preload lists.
frame_options https://rustybeam.net/schema/Text 0..1 X-Frame-Options header value: "DENY", "SAMEORIGIN", or "ALLOW-FROM uri". Defaults to "SAMEORIGIN". Prevents clickjacking.
content_type_options https://rustybeam.net/schema/Boolean 0..1 Whether to add X-Content-Type-Options: nosniff header. Defaults to true. Prevents MIME type sniffing attacks.
referrer_policy https://rustybeam.net/schema/Text 0..1 Referrer-Policy header value: "no-referrer", "origin", "strict-origin-when-cross-origin", etc. Controls referrer information sent.
permissions_policy https://rustybeam.net/schema/Text 0..1 Permissions-Policy header (formerly Feature-Policy). Controls browser feature access like camera, microphone, geolocation.
name https://rustybeam.net/schema/Text 0..1 Plugin instance name for identification. Defaults to "security-headers" if not specified.

Usage Examples

Basic Security Headers (Recommended Defaults)

<tr itemscope itemtype="https://rustybeam.net/schema/SecurityHeadersPlugin">
    <span itemprop="library">file://./plugins/librusty_beam_security_headers.so</span>
</tr>

Strict Security Configuration

<tr itemscope itemtype="https://rustybeam.net/schema/SecurityHeadersPlugin">
    <span itemprop="library">file://./plugins/librusty_beam_security_headers.so</span>
    <span itemprop="csp_policy">default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'</span>
    <span itemprop="hsts_max_age">63072000</span>
    <span itemprop="hsts_include_subdomains">true</span>
    <span itemprop="hsts_preload">true</span>
    <span itemprop="frame_options">DENY</span>
    <span itemprop="referrer_policy">no-referrer</span>
</tr>

API-focused Security

<tr itemscope itemtype="https://rustybeam.net/schema/SecurityHeadersPlugin">
    <span itemprop="library">file://./plugins/librusty_beam_security_headers.so</span>
    <span itemprop="csp_policy">default-src 'none'; frame-ancestors 'none'</span>
    <span itemprop="frame_options">DENY</span>
    <span itemprop="content_type_options">true</span>
    <span itemprop="referrer_policy">no-referrer</span>
    <span itemprop="name">api_security</span>
</tr>

Development-friendly Configuration

<tr itemscope itemtype="https://rustybeam.net/schema/SecurityHeadersPlugin">
    <span itemprop="library">file://./plugins/librusty_beam_security_headers.so</span>
    <span itemprop="csp_policy">default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: https:</span>
    <span itemprop="hsts_max_age">0</span>
    <span itemprop="frame_options">SAMEORIGIN</span>
    <span itemprop="name">dev_security</span>
</tr>

Advanced Permissions Policy

<tr itemscope itemtype="https://rustybeam.net/schema/SecurityHeadersPlugin">
    <span itemprop="library">file://./plugins/librusty_beam_security_headers.so</span>
    <span itemprop="permissions_policy">camera=(), microphone=(), geolocation=(), payment=()</span>
    <span itemprop="referrer_policy">strict-origin-when-cross-origin</span>
</tr>

Security Headers Generated

Header Purpose Example Value
Content-Security-Policy Prevents XSS and injection attacks default-src 'self'; script-src 'self'
Strict-Transport-Security Enforces HTTPS connections max-age=31536000; includeSubDomains
X-Frame-Options Prevents clickjacking attacks SAMEORIGIN
X-Content-Type-Options Prevents MIME sniffing nosniff
Referrer-Policy Controls referrer information strict-origin-when-cross-origin
Permissions-Policy Controls browser feature access camera=(), microphone=()
Default Security Stance
The Security Headers Plugin applies security-first defaults that provide good protection while maintaining compatibility. For production applications, review and customize each header based on your specific security requirements.

Content Security Policy (CSP) Guidelines

Common CSP Directives

Directive Purpose Example
default-src Fallback for other directives 'self'
script-src JavaScript execution sources 'self' 'unsafe-inline'
style-src CSS stylesheet sources 'self' 'unsafe-inline'
img-src Image sources 'self' data: https:
connect-src AJAX, WebSocket sources 'self' wss://api.example.com
frame-ancestors Embedding restrictions 'none'

CSP Security Levels

Level Policy Use Case
Strict default-src 'none'; script-src 'self'; style-src 'self' High-security applications
Balanced default-src 'self'; script-src 'self' 'unsafe-inline' Most web applications
Permissive default-src 'self' 'unsafe-inline' 'unsafe-eval' Development, legacy apps

HSTS Configuration

HSTS Deployment Strategy

  1. Start Small: max-age=300 (5 minutes) for testing
  2. Increase Gradually: max-age=86400 (1 day) after testing
  3. Production: max-age=31536000 (1 year) with subdomains
  4. Preload: Add preload directive for maximum security

HSTS Examples

# Testing
Strict-Transport-Security: max-age=300

# Development
Strict-Transport-Security: max-age=86400; includeSubDomains

# Production
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Schema Inheritance

This schema inherits from the UtilityPlugin schema, which provides:

And ultimately from the base Plugin schema, which provides:

Security Best Practices

Security Considerations

Progressive Security Enhancement

  1. Phase 1: Basic headers (Content-Type-Options, Frame-Options)
  2. Phase 2: Referrer Policy and basic CSP
  3. Phase 3: HSTS with short max-age
  4. Phase 4: Strict CSP and full HSTS
  5. Phase 5: Permissions Policy and HSTS preload

Validation Rules

Plugin Pipeline Placement
The Security Headers Plugin should be placed late in the plugin pipeline, after content generation but before compression. This ensures security headers are applied to all responses while allowing compression to work on the final response.

Common Security Header Values

Referrer Policy Options

Permissions Policy Examples

# Disable all features
camera=(), microphone=(), geolocation=(), payment=()

# Allow for same origin only
camera=(self), microphone=(self)

# Allow for specific origins
camera=(self "https://trusted.example.com")

# Mixed permissions
camera=(), microphone=(self), geolocation=(self "https://maps.example.com")

Testing Security Headers

Browser Developer Tools

# Check headers in browser console
console.log(document.querySelectorAll('*').length); // Should work with proper CSP
console.log(document.domain); // Check HSTS enforcement

Online Security Scanners

Command Line Testing

# Check headers with curl
curl -I https://example.com/

# Test CSP enforcement
curl -H "Content-Security-Policy-Report-Only: default-src 'self'" https://example.com/

# Verify HSTS
curl -I -H "Host: example.com" http://example.com/

Integration with Other Plugins

Troubleshooting

Issue Symptom Solution
CSP violations Console errors, blocked resources Use CSP report-only mode, adjust policy
HSTS not working HTTP requests not redirected Ensure HTTPS is available, check max-age
Frame embedding blocked iframes don't load Adjust frame_options or use CSP frame-ancestors
Mixed content warnings HTTPS page loading HTTP resources Update CSP to use HTTPS sources only

See Also