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 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14286 from Slava/fix-14250
Strip cookies from requests fetch favicons
- Loading branch information
1 parent
9d9e336
commit e104f5a
Showing
8 changed files
with
187 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,34 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
|
||
<iframe id='test-frame' height=200 width=500></iframe> | ||
|
||
<script> | ||
var host = window.location.origin | ||
|
||
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 unwraps 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 unwraps 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) | ||
}) | ||
}) |