Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Spoof referer header on cross-origin navigations #10726

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ module.exports.applyCookieSetting = (requestHeaders, url, firstPartyUrl, isPriva
if (cookieSetting) {
const parsedTargetUrl = urlParse(url || '')
const parsedFirstPartyUrl = urlParse(firstPartyUrl)
const targetOrigin = getOrigin(url)

if (cookieSetting === 'blockAllCookies' ||
isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) {
let hasCookieException = false
const firstPartyOrigin = getOrigin(firstPartyUrl)
const targetOrigin = getOrigin(url)
if (cookieExceptions.hasOwnProperty(firstPartyOrigin)) {
const subResources = cookieExceptions[firstPartyOrigin]
for (let i = 0; i < subResources.length; ++i) {
Expand All @@ -267,10 +267,16 @@ module.exports.applyCookieSetting = (requestHeaders, url, firstPartyUrl, isPriva
firstPartyOrigin !== pdfjsOrigin && !hasCookieException) {
requestHeaders['Cookie'] = undefined
}
if (requestHeaders['Referer'] &&
!refererExceptions.includes(parsedTargetUrl.hostname)) {
requestHeaders['Referer'] = targetOrigin
}
}

const referer = requestHeaders['Referer']
if (referer &&
cookieSetting !== 'allowAllCookies' &&
!refererExceptions.includes(parsedTargetUrl.hostname) &&
targetOrigin !== getOrigin(referer)) {
// Unless the setting is 'allow all cookies', spoof the referer if it
// is a cross-origin referer
requestHeaders['Referer'] = targetOrigin
}
}

Expand Down