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

re-add the ability to allow/block individual scripts in Shields (webui part) #17221

Merged
merged 6 commits into from
Mar 10, 2023

Conversation

spylogsster
Copy link
Contributor

@spylogsster spylogsster commented Feb 15, 2023

Resolves brave/brave-browser#28510

block.mp4

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Go to cnn.com and block/allow scripts in Shield panel

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Base automatically changed from brave-24593 to master February 20, 2023 10:21
@spylogsster spylogsster force-pushed the brave-24593-webui branch 3 times, most recently from 1c213e4 to 03127ab Compare February 20, 2023 10:49
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@spylogsster spylogsster marked this pull request as draft March 9, 2023 07:46
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

<div className={urlTextClass} onClick={handleTextClick}>
{props.path ? props.path : props.host}
</div>
{props.onPermissionButtonClick && (
Copy link
Contributor

Choose a reason for hiding this comment

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

If onPermissionButtonClick is a required prop, why are we checking if it exists here? If the permission button is conditionally rendering, it would make sense to allow null/undefined values for the prop, which should be consistent throughout the call stack.

Copy link
Contributor Author

@spylogsster spylogsster Mar 9, 2023

Choose a reason for hiding this comment

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

it can be undefined as suggested by @fallaciousreasoning above #17221 (comment)

export type PermissionButtonHandler =
  ((name: string) => void) | undefined

false was not compiled, undefined works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the handler was suggested in #17221 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed type of onPermissionButtonClick and made parameter optional

Copy link
Contributor

@nullhook nullhook left a comment

Choose a reason for hiding this comment

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

Looks good!

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

Thanks for that @spylogsster!

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@spylogsster spylogsster merged commit 825c012 into master Mar 10, 2023
@spylogsster spylogsster deleted the brave-24593-webui branch March 10, 2023 08:15
@github-actions github-actions bot added this to the 1.51.x - Nightly milestone Mar 10, 2023
@@ -78,6 +78,7 @@ class BraveShieldsDataController
void SetIsNoScriptEnabled(bool is_enabled);
void SetIsHTTPSEverywhereEnabled(bool is_enabled);
void AllowScriptsOnce(const std::vector<std::string>& origins);
void BlockAllowedScripts(const std::vector<std::string>& origins);
Copy link
Collaborator

Choose a reason for hiding this comment

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

block allowed scripts? Can you please add a comment explaining what it does because it makes no sense to block an allowed script.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should probably be BlockScriptsOnce to match AllowScriptsOnce?

@bridiver
Copy link
Collaborator

bridiver commented Mar 13, 2023

I don't see any tests to verify that this actually blocks/allows the individual scripts on the page and I'm not really sure how it can work correctly given that

bool BraveContentSettingsAgentImpl::IsScriptTemporilyAllowed(
    const GURL& script_url) {
  // Check if scripts from this origin are temporily allowed or not.
  // Also matches the full script URL to support data URL cases which we use
  // the full URL to allow it.
  bool allow = base::Contains(temporarily_allowed_scripts_,
                              url::Origin::Create(script_url).Serialize()) ||
               base::Contains(temporarily_allowed_scripts_, script_url.spec());

hasn't changed. The test here https://github.com/brave/brave-core/pull/17152/files#diff-7274b75afeaaeb25be8467441f13ad371269f1ba1c637e3fee2a1714f80c8003R201 is not sufficient because you need two different scripts with the same origin to verify that you are blocking by the full script url and not just the origin.

If I'm missing something here and this does work then at the very least the comment needs to be changed, but I'm pretty sure it won't work correctly with more than one script from the same domain

bool is_origin = origin.Serialize() == script;
base::EraseIf(allowed_scripts_, [is_origin, script,
origin](const std::string& value) {
// scripts array may have both origins or full scripts paths.
Copy link
Collaborator

Choose a reason for hiding this comment

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

SetAllowScriptsFromOriginsOnce only matches based on origin so having a full script url in this list seems confusing at best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-add the ability to allow/block individual scripts in Shields (webui part)
7 participants