This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip cookies from requests fetch favicons
Fixes #14250 Auditors: @diracdeltas Test Plan: Manually navigate to https://www.grc.com/cookies/forensics.htm and observe no problems in the report Navigate to a website with a favicon (such as github.com) and observe the favicon rendering Unit tests: run the faviconUtil unit tests Webdriver test: Runs a test page that sets a 3rd party cookie and checks if the favicon request carries over the cookies
- Loading branch information
Showing
8 changed files
with
190 additions
and
9 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
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,11 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const suffix = '#brave-favicon-fragment' | ||
|
||
module.exports = { | ||
wrapFaviconUrl: (url) => url && `${url}${suffix}`, | ||
unwrapFaviconUrl: (url) => url && url.substring(0, url.length - suffix.length), | ||
isWrappedFaviconUrl: (url) => !!(url && url.endsWith(suffix)) | ||
} |
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,17 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
cookies: | ||
<div id='cookie-favicon'> | ||
</div> | ||
|
||
<script> | ||
function setText (id, result) { | ||
document.getElementById(id).innerText = JSON.stringify(result) | ||
} | ||
|
||
setText('cookie-favicon', document.cookie) | ||
</script> | ||
</body> | ||
</html> |
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,37 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
|
||
<iframe id='test-frame' height=200 width=500></iframe> | ||
|
||
<script> | ||
var host = window.location + '' | ||
var parts = host.split('/') | ||
parts.splice(-1, 1) | ||
host = parts.join('/') | ||
|
||
function loadIco() { | ||
var faviconLocation = host.replace('127.0.0.1', 'localhost') + '/cookie-favicon.ico' | ||
var link = document.createElement('link') | ||
link.rel = 'shortcut icon' | ||
link.href = faviconLocation | ||
document.head.appendChild(link); | ||
} | ||
|
||
|
||
function loadFrame() { | ||
var testPageLocation = host.replace('127.0.0.1', 'localhost') + '/cookie-favicon-test.html' | ||
var frame = document.getElementById('test-frame') | ||
frame.onload = loadIco | ||
frame.src = testPageLocation | ||
} | ||
|
||
loadFrame() | ||
|
||
function setText (id, result) { | ||
document.getElementById(id).innerText = JSON.stringify(result) | ||
} | ||
</script> | ||
</body> | ||
</html> |
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,41 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global describe, it */ | ||
|
||
const faviconUtil = require('../../../../js/lib/faviconUtil') | ||
const assert = require('assert') | ||
|
||
require('../../braveUnit') | ||
|
||
describe('faviconUtil', function () { | ||
it('wraps, identifies and unwarps URLs', function () { | ||
const url = 'http://webserver.com/favicon.ico' | ||
const wrappedUrl = faviconUtil.wrapFaviconUrl(url) | ||
const unwrappedUrl = faviconUtil.unwrapFaviconUrl(wrappedUrl) | ||
|
||
assert.equal(faviconUtil.isWrappedFaviconUrl(url), false) | ||
assert.equal(faviconUtil.isWrappedFaviconUrl(wrappedUrl), true) | ||
assert.equal(faviconUtil.isWrappedFaviconUrl(unwrappedUrl), false) | ||
assert.equal(url, unwrappedUrl) | ||
}) | ||
it('wraps, identifies and unwarps URLs with query params', function () { | ||
const url = 'http://webserver.com/favicon.ico?qp=1&qp2=2' | ||
const wrappedUrl = faviconUtil.wrapFaviconUrl(url) | ||
const unwrappedUrl = faviconUtil.unwrapFaviconUrl(wrappedUrl) | ||
|
||
assert.equal(faviconUtil.isWrappedFaviconUrl(url), false) | ||
assert.equal(faviconUtil.isWrappedFaviconUrl(wrappedUrl), true) | ||
assert.equal(faviconUtil.isWrappedFaviconUrl(unwrappedUrl), false) | ||
assert.equal(url, unwrappedUrl) | ||
}) | ||
it('works with undefined', function () { | ||
const url = undefined | ||
const wrappedUrl = faviconUtil.wrapFaviconUrl(url) | ||
const unwrappedUrl = faviconUtil.unwrapFaviconUrl(wrappedUrl) | ||
|
||
assert.equal(faviconUtil.isWrappedFaviconUrl(url), false) | ||
assert.equal(wrappedUrl, undefined) | ||
assert.equal(unwrappedUrl, undefined) | ||
}) | ||
}) |