New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network Security : Implement StrictOrigin and StrictOriginWhenCrossOr… #14059
Changes from 1 commit
c24aa56
26dac98
e0e734f
e0132b9
File filter...
Jump to…
Network Security : Implement StrictOrigin and StrictOriginWhenCrossOr…
…igin Referer policy strict-origin and strict-origin-when-cross-origin changes have been implemented. Relevant unit test cases have been added. Enum for RefererPolicy has been added to hyper codebase and v 0.9.11 of hyper contains these changes. This commit also contains changes related to upgrade of hyper from v0.9.10 to v0.9.11. Other dependencies changed are rayon, utils, num_cpus.
- Loading branch information
| @@ -437,6 +437,27 @@ fn no_referrer_when_downgrade_header(referrer_url: Url, url: Url) -> Option<Url> | ||
| return strip_url(referrer_url, false); | ||
| } | ||
|
|
||
| /// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-strict-origin | ||
| fn strict_origin(referrer_url: Url, url: Url) -> Option<Url> { | ||
| if referrer_url.scheme() == "https" && url.scheme() != "https" { | ||
| return None; | ||
| } | ||
| return strip_url(referrer_url, true); | ||
nmvk
Author
Contributor
|
||
| } | ||
|
|
||
| /// https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-strict-origin-when-cross-origin | ||
| fn strict_origin_when_cross_origin(referrer_url: Url, url: Url) -> Option<Url> { | ||
| let cross_origin = referrer_url.origin() != url.origin(); | ||
|
||
| if referrer_url.scheme() == "https" && url.scheme() != "https" { | ||
| return None; | ||
| } else { | ||
|
||
| if cross_origin { | ||
| return strip_url(referrer_url, true); | ||
| } | ||
| return strip_url(referrer_url, false); | ||
nox
Member
|
||
| } | ||
| } | ||
|
|
||
| /// https://w3c.github.io/webappsec-referrer-policy/#strip-url | ||
| fn strip_url(mut referrer_url: Url, origin_only: bool) -> Option<Url> { | ||
| if referrer_url.scheme() == "https" || referrer_url.scheme() == "http" { | ||
| @@ -467,6 +488,8 @@ pub fn determine_request_referrer(headers: &mut Headers, | ||
| Some(ReferrerPolicy::SameOrigin) => if cross_origin { None } else { strip_url(ref_url, false) }, | ||
| Some(ReferrerPolicy::UnsafeUrl) => strip_url(ref_url, false), | ||
| Some(ReferrerPolicy::OriginWhenCrossOrigin) => strip_url(ref_url, cross_origin), | ||
| Some(ReferrerPolicy::StrictOrigin) => strict_origin(ref_url, url), | ||
| Some(ReferrerPolicy::StrictOriginWhenCrossOrigin) => strict_origin_when_cross_origin(ref_url, url), | ||
| Some(ReferrerPolicy::NoReferrerWhenDowngrade) | None => | ||
| no_referrer_when_downgrade_header(ref_url, url), | ||
| }; | ||
Some generated files are not rendered by default. Learn more.
Nit:
returnis useless here.