Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rack::Protection::ReferrerPolicy. (#1291)
- Loading branch information
1 parent
3cc2394
commit fade5fe
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rack/protection' | ||
|
||
module Rack | ||
module Protection | ||
## | ||
# Prevented attack:: Secret leakage, third party tracking | ||
# Supported browsers:: mixed support | ||
# More infos:: https://www.w3.org/TR/referrer-policy/ | ||
# https://caniuse.com/#search=referrer-policy | ||
# | ||
# Sets Referrer-Policy header to tell the browser to limit the Referer header. | ||
# | ||
# Options: | ||
# referrer_policy:: The policy to use (default: 'strict-origin-when-cross-origin') | ||
class ReferrerPolicy < Base | ||
default_options :referrer_policy => 'strict-origin-when-cross-origin' | ||
|
||
def call(env) | ||
status, headers, body = @app.call(env) | ||
headers['Referrer-Policy'] ||= options[:referrer_policy] | ||
[status, headers, body] | ||
end | ||
end | ||
end | ||
end |