[PSST] Show infobar when the feature availability is detected for the website#34174
[PSST] Show infobar when the feature availability is detected for the website#34174vadimstruts wants to merge 30 commits intomasterfrom
Conversation
463f997 to
96efa72
Compare
📋 Code Owners Summary14 file(s) changed, 2 with assigned owners 2 team(s) affected: Owners and Their Files
|
|
A Storybook has been deployed to preview UI for the latest push |
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
|
Chromium major version is behind target branch (145.0.7632.120 vs 146.0.7680.32). Please rebase. |
#34174 (comment) #34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) #34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) #34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) #34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
#34174 (comment) Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
…ct to the next one Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
fallaciousreasoning
left a comment
There was a problem hiding this comment.
going to defer to @boocmp on the review here as I'm not too familiar with this feature
components/psst/browser/content/psst_tab_web_contents_observer.h
Outdated
Show resolved
Hide resolved
components/psst/browser/content/psst_tab_web_contents_observer.h
Outdated
Show resolved
Hide resolved
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: Vadym Struts <[email protected]>
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
| script_injector_remote->RequestAsyncExecuteScript( | ||
| world_id, base::UTF8ToUTF16(std::string(script)), | ||
| blink::mojom::UserActivationOption::kActivate, | ||
| blink::mojom::PromiseResultOption::kAwait, std::move(cb)); |
There was a problem hiding this comment.
reported by reviewdog 🐶
[opengrep] RequestAsyncExecuteScript usages should be vet by the security-team.
References:
- https://github.com/brave/brave-browser/wiki/Security-reviews (point 12)
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/brave-execute-script.yaml
Cc @stoletheminerals @diracdeltas @bridiver
There was a problem hiding this comment.
how are you planning to distribute these scripts (component updater)? will the initial set of scripts and updates be security audited?
note ISOLATED_WORLD_ID_BRAVE_INTERNAL is reused for a bunch of stuff like brave ads, publishers, speedreader, etc; so if one of these scripts is compromised, all the others can be prototype-polluted. therefore if these scripts deal with untrusted input, it might make sense to use a separate world id for them. see https://bravesoftware.slack.com/archives/C7VLGSR55/p1673046335116019 for info.
There was a problem hiding this comment.
how are you planning to distribute these scripts
It will be distributed like other CRX components, so the component updater
will receive new versions of the scripts in the standard way.
will the initial set of scripts and updates be security audited?
I think it will be required once we are ready to release the initial version,
at least for the first website.
it might make sense to use a separate world id for them
It make sense
There was a problem hiding this comment.
@diracdeltas we'd discussed having a separate world ID for PSST in this security review: https://github.com/brave/reviews/issues/2020#issuecomment-3210147843
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: Vadym Struts <[email protected]>
mkarolin
left a comment
There was a problem hiding this comment.
strings, chromium_src ++
components/psst/browser/content/psst_tab_web_contents_observer.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: Vadym Struts <[email protected]>
|
Warning You have got a presubmit warning. Please address it if possible. |
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
|
[puLL-Merge] - brave/brave-core@34174 DescriptionThis PR evolves the PSST (Privacy Settings Suggestions Tool) feature by adding a UI layer consisting of an infobar notification and a presenter pattern. The main changes include:
Possible Issues
Security Hotspots
ChangesChanges
sequenceDiagram
participant User
participant WebContents
participant Observer as PsstTabWebContentsObserver
participant Registry as PsstRuleRegistry
participant UiDelegate as PsstUiDelegateImpl
participant Presenter as UiDesktopPresenter
participant InfoBar as PsstInfoBarDelegate
WebContents->>Observer: NavigationEntryCommitted()
Observer->>Observer: SetUserData(kShouldProcessKey)
WebContents->>Observer: DocumentOnLoadCompleted()
Observer->>Registry: CheckIfMatch(url)
Registry-->>Observer: MatchedRule
Observer->>WebContents: inject_script_callback_(user_script)
WebContents-->>Observer: OnUserScriptResult(script_result)
Observer->>UiDelegate: GetPsstWebsiteSettings(origin, user_id)
UiDelegate-->>Observer: std::nullopt (first visit)
Observer->>UiDelegate: Show(origin, settings, site_name, tasks, callback)
UiDelegate->>UiDelegate: Check consent_status
UiDelegate->>Presenter: ShowIcon()
UiDelegate->>Presenter: ShowInfoBar(callback)
Presenter->>InfoBar: Create(infobar_manager, callback)
User->>InfoBar: Accept
InfoBar->>Presenter: OnInfobarAccepted(true)
Presenter->>UiDelegate: OnUserAcceptedInfobar(origin, true)
UiDelegate->>Observer: ConsentCallback(disabled_checks)
Observer->>Observer: PrepareParametersForPolicyExecution()
Observer->>WebContents: inject_async_script_callback_(policy_script)
WebContents-->>Observer: OnPolicyScriptResult(result)
Observer->>UiDelegate: UpdateTasks(progress, tasks, status)
Observer->>WebContents: LoadURL(next_url)
|
| psst_settings->user_id = *user_id; | ||
| } | ||
|
|
||
| auto origin = url::Origin::Create(web_contents()->GetLastCommittedURL()); |
There was a problem hiding this comment.
I think this is generally supposed to use url_formatter::FormatOriginForSecurityDisplay, but also what happens if the webcontents has navigated by the time the callback runs? Does navigation clear it? Is there a test for that? This looks like a potential security spoofing issue to me.
There was a problem hiding this comment.
There is a check for ShouldInsertScriptForPage at func's beginning, it checks for the navigation entry id, this id is updated in the DocumentOnLoadCompletedInPrimaryMainFrame. There are several tests with navigations, @vadimstruts could you point to the one which checks the mentioned behavior?
There was a problem hiding this comment.
As for
what happens if the webcontents has navigated by the time the callback runs
When a user navigates to any website for the first time (in NavigationEntryCommitted), we check the following conditions:
- The main frame navigated to a different page
- The entry's URL has an
httporhttpsscheme - The entry is not restored
- PSST is enabled in preferences
If all conditions are met, we save the current entry ID to user data and use ShouldInsertScriptForPage to validate it at the beginning of every relevant function.
Navigations Related Unittests:
There was a problem hiding this comment.
As for
I think this is generally supposed to use
url_formatter::FormatOriginForSecurityDisplay
In the current PR, we use the origin solely to save and retrieve website-related settings data, i.e. it is not visible to the user. Even in the follow-up PR (coming soon), when we add the consent dialog to display the feature status, we will only show the user information from the loaded CRX component.
| return; | ||
| } | ||
|
|
||
| const auto* site_name = params.FindString(kUserScriptResultSiteNamePropName); |
There was a problem hiding this comment.
why are we getting the site_name from JS? Is there a description somewhere of what these properties are and how they are determined? We may not want to trust this value if it can be potentially spoofed by the page. Since we're not running this before any page code, the page can spoof just about anything by messing with prototypes
There was a problem hiding this comment.
PSST executes scripts in the ISOLATED_WORLD_ID_BRAVE_INTERNAL, page can't spoof this
There was a problem hiding this comment.
The site name is part of the information retrieved from user.js, which is managed as a CRX component.
Here is example of user.js code:
https://github.com/brave-experiments/psst-component/blob/main/scripts/twitter/user.js#L38
This means that we will prepare the content of the CRX component, which contains the user.js, policy.js and the config: https://github.com/brave-experiments/psst-component/blob/main/psst.json#L3 for each website we want to support.
Both scripts, as @boocmp said, will be executed in the ISOLATED_WORLD_ID_BRAVE_INTERNAL
There was a problem hiding this comment.
ah right, forgot it was an isolated world, but still curious what we're returning here for site_name that we need js for?
There was a problem hiding this comment.
it would really be helpful is there were more comments here or documentation about what is actually happening in these scripts and what all these values are
Resolves brave/brave-browser#53452
Added display of the infobar when PSST feature availability is detected for the website.
When the user clicks the Review button on the infobar, we plan to show a WebUI modal dialog, which will be added in follow up.
Here is screenshot of the infobar:
1