Referrer-Policy
What is Referrer-Policy?
The Referrer-Policy header is an HTTP security and privacy header that controls how much referrer information (the URL of the page that linked to the resource being requested) is included with requests. This header helps balance the need for analytics and debugging with user privacy concerns.
When a user navigates from one page to another, browsers typically send the originating page's URL in the Referer header (note the historical misspelling). The Referrer-Policy header allows website owners to specify what referrer information should be included in these requests.
Header Syntax
The Referrer-Policy header supports several directives:
Referrer-Policy: no-referrer
Referrer-Policy: no-referrer-when-downgrade
Referrer-Policy: origin
Referrer-Policy: origin-when-cross-origin
Referrer-Policy: same-origin
Referrer-Policy: strict-origin
Referrer-Policy: strict-origin-when-cross-origin
Referrer-Policy: unsafe-url
Policy Directives Explained
| Directive | Behavior |
|---|---|
| no-referrer | Never sends the Referer header |
| no-referrer-when-downgrade | Default behavior - sends full URL except when navigating from HTTPS to HTTP |
| origin | Sends only the origin (scheme + host + port) |
| origin-when-cross-origin | Sends full URL for same-origin requests, origin only for cross-origin requests |
| same-origin | Sends referrer information only for same-origin requests |
| strict-origin | Sends origin only when security level remains the same (HTTPS→HTTPS) |
| strict-origin-when-cross-origin | Sends full URL for same-origin, origin for secure cross-origin, nothing for insecure cross-origin |
| unsafe-url | Always sends full URL (insecure - can leak sensitive information) |
Security and Privacy Considerations
Privacy benefits:
- Prevents leakage of sensitive information in URLs
- Reduces tracking capabilities across different domains
- Enhances user privacy by limiting referrer information
Security implications:
- Can help prevent CSRF attacks by limiting referrer information
- Reduces information leakage that could be exploited in targeted attacks
- Prevents exposure of internal URLs and parameters
Potential drawbacks:
- May break some analytics and tracking systems
- Can affect functionality of third-party services that rely on referrer information
- May impact SEO if search engines rely on referrer data
Best Practices
- Use strict policies for sensitive applications:
Referrer-Policy: strict-origin-when-cross-origin - Avoid
unsafe-urlas it can leak sensitive information in URLs - Consider your analytics needs - stricter policies may impact tracking capabilities
- Test different policies to ensure they don't break required functionality
- Combine with other security headers for comprehensive protection:
Example Implementations
HTTP Response Header:
Referrer-Policy: strict-origin-when-cross-origin
Web Server Configuration Examples:
Apache (.htaccess):
Header set Referrer-Policy "strict-origin-when-cross-origin"
Nginx:
add_header Referrer-Policy "strict-origin-when-cross-origin";
Express.js (Node.js):
app.use((req, res, next) => {
res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
next();
});
HTML Meta Tag:
<meta name="referrer" content="strict-origin-when-cross-origin">
Common Use Cases
- E-commerce websites: Protect user privacy while maintaining necessary analytics
- Healthcare applications: Prevent leakage of sensitive information in URLs
- Government websites: Enhance citizen privacy and security
- Banking applications: Reduce information leakage that could aid phishing attacks
- Social media platforms: Balance analytics needs with user privacy expectations
Browser Support
The Referrer-Policy header is widely supported in modern browsers:
- Chrome 53+
- Firefox 50+
- Safari 11+
- Edge 79+
- Internet Explorer 11 (partial support)
Related Security Concepts
- HTTP Security Headers - Overview of important security headers
- Cross-Site Request Forgery (CSRF) - Attack prevented by proper referrer policies
- Content Security Policy (CSP) - Complementary security header
- Same-Origin Policy (SOP) - Fundamental web security model
- Privacy Enhancing Technologies - Technologies that protect user privacy
- Cross-Origin Resource Sharing (CORS) - Cross-origin resource sharing mechanism
- HTTP/2 - Modern web protocol with enhanced security features
Rate Limiting
Security mechanism that controls the number of requests a client can make to a server within a specific time window.
Reflected XSS (Non-Persistent XSS)
Reflected XSS (Non-Persistent Cross-Site Scripting) is a web security vulnerability where malicious scripts are reflected immediately in a web application response, requiring user interaction to execute and enabling targeted attacks through social engineering.
