Skip to content

Commit

Permalink
fix: implement basic policy container (nodejs#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and metcoder95 committed Jul 21, 2023
1 parent 201a01c commit 0175581
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const util = require('../core/util')
const {
isValidHTTPToken,
sameOrigin,
normalizeMethod
normalizeMethod,
makePolicyContainer
} = require('./util')
const {
forbiddenMethods,
Expand Down Expand Up @@ -51,13 +52,14 @@ class Request {
input = webidl.converters.RequestInfo(input)
init = webidl.converters.RequestInit(init)

// TODO
// https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
this[kRealm] = {
settingsObject: {
baseUrl: getGlobalOrigin(),
get origin () {
return this.baseUrl?.origin
}
},
policyContainer: makePolicyContainer()
}
}

Expand Down
20 changes: 12 additions & 8 deletions lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,26 @@ function createOpaqueTimingInfo (timingInfo) {

// https://html.spec.whatwg.org/multipage/origin.html#policy-container
function makePolicyContainer () {
// TODO
return {}
// Note: the fetch spec doesn't make use of embedder policy or CSP list
return {
referrerPolicy: 'strict-origin-when-cross-origin'
}
}

// https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container
function clonePolicyContainer () {
// TODO
return {}
function clonePolicyContainer (policyContainer) {
return {
referrerPolicy: policyContainer.referrerPolicy
}
}

// https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
function determineRequestsReferrer (request) {
// 1. Let policy be request's referrer policy.
// TODO(@KhafraDev): referrerPolicy is supposed to be non-null & not an empty string.
// this is because we don't implement policyContainer.
const policy = request.referrerPolicy ?? 'strict-origin-when-cross-origin'
const policy = request.referrerPolicy

// Note: policy cannot (shouldn't) be null or an empty string.
assert(policy)

// 2. Let environment be request’s client.

Expand Down

0 comments on commit 0175581

Please sign in to comment.