This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add upgrade-insecure-requests to responseHeaders in HTTP Nowhere Mode #14600
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0fa804f
Add upgrade-insecure-requests to responseHeaders in HTTP Nowhere Mode…
0d1f114
When extension is disabled, do nothing
1e06bf1
If CSP already existed, modify it insteads
e4b17e8
Exclude .onion requests from being upgraded
9541530
Return responseHeaders only if it is modified
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 |
---|---|---|
|
@@ -497,11 +497,46 @@ function onErrorOccurred(details) { | |
} | ||
} | ||
|
||
/** | ||
* handle webrequest.onHeadersReceived, insert upgrade-insecure-requests directive | ||
* @param details details for the chrome.webRequest (see chrome doc) | ||
*/ | ||
function onHeadersReceived(details) { | ||
if (isExtensionEnabled && httpNowhereOn) { | ||
// Do not upgrade the .onion requests in HTTP Nowhere Mode, | ||
// See https://github.com/EFForg/https-everywhere/pull/14600#discussion_r168072480 | ||
const uri = new URL(details.url); | ||
if (uri.hostname.slice(-6) == '.onion') { | ||
return {responseHeaders: details.responseHeaders}; | ||
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. return {}; |
||
} | ||
|
||
for (const idx in details.responseHeaders) { | ||
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. Don't use a |
||
if (details.responseHeaders[idx].name.match(/Content-Security-Policy/i)) { | ||
// Existing CSP headers found | ||
const value = details.responseHeaders[idx].value; | ||
|
||
// Prepend if no upgrade-insecure-requests directive exists | ||
if (!value.match(/upgrade-insecure-requests/i)) { | ||
details.responseHeaders[idx].value = "upgrade-insecure-requests; " + value; | ||
} | ||
return {responseHeaders: details.responseHeaders}; | ||
} | ||
} | ||
|
||
// CSP headers not found | ||
const upgradeInsecureRequests = { | ||
name: 'Content-Security-Policy', | ||
value: 'upgrade-insecure-requests' | ||
} | ||
details.responseHeaders.push(upgradeInsecureRequests); | ||
} | ||
return {responseHeaders: details.responseHeaders}; | ||
} | ||
|
||
// Registers the handler for requests | ||
// See: https://github.com/EFForg/https-everywhere/issues/10039 | ||
chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["*://*/*"]}, ["blocking"]); | ||
|
||
|
||
// Try to catch redirect loops on URLs we've redirected to HTTPS. | ||
chrome.webRequest.onBeforeRedirect.addListener(onBeforeRedirect, {urls: ["https://*/*"]}); | ||
|
||
|
@@ -511,9 +546,13 @@ chrome.webRequest.onCompleted.addListener(onCompleted, {urls: ["*://*/*"]}); | |
// Cleanup redirectCounter if neccessary | ||
chrome.webRequest.onErrorOccurred.addListener(onErrorOccurred, {urls: ["*://*/*"]}) | ||
|
||
// Insert upgrade-insecure-requests directive in httpNowhere mode | ||
chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["https://*/*"]}, ["blocking", "responseHeaders"]); | ||
|
||
// Listen for cookies set/updated and secure them if applicable. This function is async/nonblocking. | ||
chrome.cookies.onChanged.addListener(onCookieChanged); | ||
|
||
|
||
/** | ||
* disable switch Planner | ||
* @param tabId the Tab to disable for | ||
|
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.
There may be a wild edge case here. In
https-everywhere/chromium/background.js
Lines 247 to 253 in 2808747
.onion
URLs that do not have HTTPS in HTTP Nowhere mode. If a.onion
URL serves only one page in HTTPS, and the rest are over HTTP, landing on that page with this logic will cause the client to make unreachable upgraded requests over HTTPS.As I said, it's a pretty far-fetched edge case (why would a
.onion
site have a TLS configuration like that?) but it is possible, and probably worth accounting for.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.
I agree. Since
.onion
requests are encrypted anyway, IMHO we shall exclude them from the HTTPS upgrades, see e4b17e8There 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.
I think requests to non-
.onion
websites should still be upgraded if they were made from.onion
website.