-
-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protect from Link Tracking on Tumblr #2733
Open
ablanathtanalba
wants to merge
4
commits into
master
Choose a base branch
from
tumblr_link_tracking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4256f90
add firstparty script for cleaning links on tumblr and tumblr subs
ablanathtanalba 7b4d164
add tumblr firstparty blob to manifest
ablanathtanalba 2d89cf8
fix linting errs
ablanathtanalba 9dc43d3
add test for tumblr link unwrapping firstparty script
ablanathtanalba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// only observed links with this format out in the wild | ||
let tumblr_links = "a[href^='https://t.umblr.com/redirect?']"; | ||
|
||
// reassigns the href and scrubs link of all unnecessary attributes | ||
function unwrapLink(a) { | ||
let href = new URL(a.href).searchParams.get('z'); | ||
if (!window.isURL(href)) { | ||
return; | ||
} | ||
|
||
for (let attr of a.attributes) { | ||
if (!['target', 'class', 'style'].includes(attr.name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also keep ARIA attributes? |
||
a.removeAttribute(attr.name); | ||
} | ||
} | ||
|
||
a.rel = "noreferrer"; | ||
a.href = href; | ||
} | ||
|
||
// main handler to target each link on page and launder them through the unwrapLink func | ||
function unwrapAll() { | ||
document.querySelectorAll(tumblr_links).forEach((a) => { | ||
unwrapLink(a); | ||
}); | ||
} | ||
|
||
chrome.runtime.sendMessage({ | ||
type: "checkEnabled" | ||
}, function (enabled) { | ||
if (!enabled) { | ||
return; | ||
} | ||
unwrapAll(); | ||
setInterval(unwrapAll, 2000); | ||
}); |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ let fb_wrap = 'https://facebook.com/l.php?u=' + destination; | |
let fb_xss = 'https://facebook.com/l.php?u=javascript://bad.site/%250Aalert(1)'; | ||
let g_wrap = 'https://www.google.com/url?q=' + destination; | ||
let g_ping = '/url?url=' + destination; | ||
let tumblr_wrap = 'https://t.umblr.com/redirect?z=' + destination; | ||
|
||
function makeLink(href) { | ||
let element = document.createElement('a'); | ||
|
@@ -164,4 +165,38 @@ QUnit.test('google search de-instrumentation', (assert) => { | |
fixture.appendChild(util_script); | ||
}); | ||
|
||
QUnit.test('tumblr link unwrapping', (assert) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't need a unit test for this PR, especially if we reuse |
||
const NUM_CHECKS = 2, | ||
done = assert.async(); | ||
assert.expect(NUM_CHECKS); | ||
|
||
let fixture = document.getElementById('qunit-fixture'); | ||
let tumblr_link = makeLink(tumblr_wrap); | ||
|
||
// create first-party utility script | ||
let util_script = document.createElement('script'); | ||
util_script.src = '../js/firstparties/lib/utils.js'; | ||
|
||
// create the content script | ||
let tumblr_script = document.createElement('script'); | ||
tumblr_script.src = '../js/firstparties/tumblr.js'; | ||
tumblr_script.onload = function() { | ||
assert.equal(tumblr_link.href, destination, 'unwrapped tumblr link'); | ||
assert.ok(tumblr_link.rel.includes('noreferrer'), | ||
'added noreferrer to tumblr link'); | ||
|
||
unstub(); | ||
done(); | ||
}; | ||
|
||
// after the utility script has finished loading, add the content script | ||
util_script.onload = function() { | ||
fixture.append(tumblr_script); | ||
}; | ||
|
||
stub([tumblr_link], '/url?'); | ||
fixture.appendChild(tumblr_link); | ||
fixture.appendChild(util_script); | ||
}); | ||
|
||
}()); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is almost identical to https://github.com/EFForg/privacybadger/blob/master/src/js/firstparties/google-static.js. What if we reuse
google-static.js
, conditionally setting the DOM selector variable (based ondocument.domain
maybe)?