Skip to content
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

Implement per-origin noscript #97

Merged
merged 3 commits into from
May 23, 2018
Merged

Implement per-origin noscript #97

merged 3 commits into from
May 23, 2018

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented May 2, 2018

Fix brave/brave-browser#6
Support per-tab per-origin noScript settings which will be cleared when navigating away.
See also: brave/brave-extension/pull/21

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.

Test Plan:

An automated browser test is added for this feature.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions

@yrliou yrliou self-assigned this May 3, 2018
@yrliou yrliou force-pushed the noscript branch 2 times, most recently from eee42b2 to 300dda7 Compare May 8, 2018 20:43
@yrliou yrliou changed the title [WIP] Implement per-origin noscript Implement per-origin noscript May 8, 2018
@yrliou
Copy link
Member Author

yrliou commented May 8, 2018

Built on Mac, will make sure other platforms built before merging.

@yrliou yrliou requested a review from bbondy May 8, 2018 21:21
@yrliou
Copy link
Member Author

yrliou commented May 8, 2018

Please leave this PR for me to merge since I would like to include extension DEPS update commit in this PR when everything is reviewed and ready to merged.

Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can ship initially with the UI as is but ideally we'll one day modify this:
screen shot 2018-05-11 at 10 30 32 am

Please try to customize the "JavaScript was blocked on this page" message. To indicate they should check the Brave shields panel. But since this string is in chrome/app/generated_resources.grd and we don't override it yet, we should override that as a separate PR and do that at that point. Posting a task for this would be fine for now.


While testing I somehow had an extension show up, which makes me think we blocked some extension we shouldn't have. I don't have any extra extensions installed, but it looks like it's from chrome/browser/resources/media_router.

screen shot 2018-05-11 at 10 22 10 am

@@ -25,14 +26,55 @@ BraveContentSettingsObserver::BraveContentSettingsObserver(
BraveContentSettingsObserver::~BraveContentSettingsObserver() {
}

void BraveContentSettingsObserver::DidFinishLoad() {
temporarily_allowed_scripts_.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this clear here will cause a bad experience for NoScript users because a lot of resource loads for an origin happen after the onload. On browser-laptop in frame.js we clear it when the component is unmounted (tab is closed) or when the user navigates to a different origin.
I think we could instead clear it when there's a different origin than was set in allow once in WillCommitProvisionalLoad or something like that.
You can try it out on my website to see how it doesn't really work well. It probably works for some test sites just fine though.
We don't have to be consistent completely with how browser-laptop works but just more usable.

temporarily_allowed_scripts_.clear();
}

bool BraveContentSettingsObserver::OnMessageReceived(const IPC::Message& message) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting an alternate way to do this might be to create temporary content settings that we later clear. But I'm ok with the current method you used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that actually doesn't work because it will affect other loads that might be happening in the background

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even this had to be tweaked slightly from the original to avoid any race conditoins

<html><head><title>load js from origins</title></head>
<body>
<script src="/cross-site/a.com/create_iframe.js"></script>
<script src="/cross-site/b.com/create_iframe.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these paths are wrong which I think would make the tests fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed, comments about how this works are added into html file.


// Send IPC msg to update the list in this tab's content settings observers
contents->SendToAllFrames(
new BraveFrameMsg_AllowScriptsOnce(MSG_ROUTING_NONE, params->origins));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted there is an issue here that frames which might be created after this will not get this list.
Probably could be solved by saving the list (which is specific to one webcontent) in the browser process (maybe in BraveWebContentsObserver or BraveTabSpecificContentSetting) and send the list in RenderFrameCreated to those subsequent frames that are created later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed by 00cfdb3


void BraveContentSettingsObserver::OnAllowScriptsOnce(
const std::vector<std::string>& origins) {
temporarily_allowed_scripts_.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need an extra setting here or can we just set the existing cached_script_permissions_? cached_script_permissions_ gets cleared on navigation

@yrliou yrliou force-pushed the noscript branch 9 times, most recently from 6284061 to 9283244 Compare May 19, 2018 05:22
@yrliou
Copy link
Member Author

yrliou commented May 19, 2018

@bbondy, @bridiver PR is updated, please take a look again when you're available, thanks!
Main change here is to maintain a set in BraveShieldsWebContentsObserver which will be propagated to render frames in ReadyToCommitNavigation, and the set would be cleared when navigating away.
In renderer side, origins passed from browser process will first be preloaded into preloaded_temporarily_allowed_scripts_.
Then it will be loaded into temporarily_allowed_scripts_ in DidCommitProvisionalLoad.
The reason of adding a preloaded var is to avoid wrongly apply the no-script setting which is meant for the navigation that's going to be committed to things in the current page load.

bbondy
bbondy previously approved these changes May 22, 2018
Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yrliou yrliou merged commit c91d571 into master May 23, 2018
@yrliou yrliou deleted the noscript branch May 30, 2018 20:09
NejcZdovc pushed a commit that referenced this pull request Dec 10, 2018
Autocontribute monthly values other than defaults are now added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants