❤️
SecurityHeaders.nl

Speculation-Rules

The Speculation-Rules header allows a server to securely deliver a set of rules that tell the browser which resources to prefetch or prerender to speed up subsequent page loads.

How Speculation-Rules Works

Modern browsers can significantly improve user experience by speculatively fetching pages before the user even clicks a link. Traditionally, this was done using <link rel="prefetch"> tags in the HTML.

The Speculation-Rules header provides a safer, HTTP-level mechanism to deliver a JSON payload containing these rules. Because it operates at the HTTP level, it can be enforced before the HTML is even parsed, and it avoids issues with injected HTML tampering with prefetching logic.

Basic Example

Speculation-Rules: "/rules/prefetch.json"

The browser will fetch the JSON file at the specified URL and apply the prefetching rules defined within.

Security Implications

Speculative fetching can sometimes leak sensitive information (e.g., if an attacker triggers a prefetch to a logout endpoint). The Speculation Rules API requires explicit opt-in and strict same-origin (or CORS-enabled) policies to prevent cross-site request forgery via prefetching.

Check Your Header

Use the SecurityHeaders.nl scanner to verify if your application correctly implements modern HTTP security standards.