-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add upgrade-insecure-requests to responseHeaders in HTTP Nowhere Mode #14600
Conversation
Built and tested with http://www.gsu.edu/about/. Good job! 👍 |
@cschanaj If Content-Security-Policy header already exists, you should modify it instead of adding a new one. |
@cschanaj I've created a PR in your repo. Check it out. |
@epicminecrafting is there any new feature in the code you proposed? since the code is relatively short, I am not going to bother with the coding style here. |
@cschanaj Just minor fixes, like appending instead of prepending and simpler and faster case-ignoring comparision. |
@cschanaj I can review as-is or wait for you to merge @epicminecrafting's changes. Please advise. |
@Hainish Please review this as-is. thanks! |
* @param details details for the chrome.webRequest (see chrome doc) | ||
*/ | ||
function onHeadersReceived(details) { | ||
if (isExtensionEnabled && httpNowhereOn) { |
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
const shouldCancel = httpNowhereOn && | |
uri.protocol === 'http:' && | |
uri.hostname.slice(-6) !== '.onion' && | |
uri.hostname !== 'localhost' && | |
!/^127(\.[0-9]{1,3}){3}$/.test(canonical_host) && | |
!/^0\.0\.0\.0$/.test(canonical_host) && | |
uri.hostname !== '[::1]'; |
.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 e4b17e8
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 think requests to non-.onion
websites should still be upgraded if they were made from .onion
website.
chromium/background.js
Outdated
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
return {};
chromium/background.js
Outdated
return {responseHeaders: details.responseHeaders}; | ||
} | ||
|
||
for (const idx in details.responseHeaders) { |
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.
Don't use a for
loop, use find
function.
As per the Chrome's docs in https://developer.chrome.com/extensions/webRequest#type-HttpHeaders
@epicminecrafting fixed in 9541530; as for |
@cschanaj There is, declarative programming over imperative one. |
Thank you! |
cc @Hainish @gloomy-ghost It would be really great to see this in the next release.
TEST CASES
upgrade-insecure-requests
directiveupgrade-insecure-requests
directiveFollow up: Should we modify the CORS headers as well??
Close #8506 Close cschanaj/https-everywhere/pull/13