Skip to content

Commit

Permalink
refactor: apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Mar 8, 2022
1 parent e48aa59 commit 3aca452
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ function clonePolicyContainer () {

// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
function determineRequestsReferrer (request) {
// TODO
// 1. Let policy be request's referrer policy.
const policy = request.referrerPolicy

Expand Down Expand Up @@ -351,35 +350,34 @@ function determineRequestsReferrer (request) {
switch (policy) {
case 'origin': return referrerOrigin
case 'unsafe-url': return referrerUrl
case 'same-origin':
return areSameOrigin ? referrerOrigin : 'no-referrer'
case 'origin-when-cross-origin':
return areSameOrigin ? referrerUrl : referrerOrigin
case 'strict-origin-when-cross-origin':
/**
* 1. If the origin of referrerURL and the origin of request’s current URL are the same,
* then return referrerURL.
* 2. If referrerURL is a potentially trustworthy URL and request’s current URL is not a
* potentially trustworthy URL, then return no referrer.
* 3. Return referrerOrigin
*/
if (areSameOrigin) return referrerOrigin
case 'strict-origin':
/**
* 1. If referrerURL is a potentially trustworthy URL and
* request’s current URL is not a potentially trustworthy URL,
* then return no referrer.
* 2. Return referrerOrigin
*/
return isNonPotentiallyTrustWorthy ? 'no-referrer' : referrerOrigin
case 'strict-origin-when-cross-origin':
/**
* 1. If the origin of referrerURL and the origin of request’s current URL are the same,
* then return referrerURL.
* 2. If referrerURL is a potentially trustworthy URL and request’s current URL is not a
* potentially trustworthy URL, then return no referrer.
* 3. Return referrerOrigin
*/
if (areSameOrigin) return referrerOrigin
else return isNonPotentiallyTrustWorthy ? 'no-referrer' : referrerOrigin
case 'same-origin':
return areSameOrigin ? referrerOrigin : 'no-referrer'
case 'origin-when-cross-origin':
return areSameOrigin ? referrerUrl : referrerOrigin
case 'no-referrer-when-downgrade':
/**
* 1. If referrerURL is a potentially trustworthy URL and
* request’s current URL is not a potentially trustworthy URL,
* then return no referrer.
* 2. Return referrerOrigin
*/
default:
return isNonPotentiallyTrustWorthy ? 'no-referrer' : referrerOrigin
}

Expand Down

0 comments on commit 3aca452

Please sign in to comment.