Skip to content

[Desktop] Avoid relying on innerHTML for Brave Rewards & Welcome pages #11642

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

Closed
mariospr opened this issue Sep 9, 2020 · 7 comments · Fixed by brave/brave-core#6669
Closed

Comments

@mariospr
Copy link
Contributor

mariospr commented Sep 9, 2020

Description

For Chromium 87, we needed to push a patch named "Disable Trusted Types mitigation on Brave's Welcome & Rewards pages" that disables the Content Security Policy for Trusted Types in Brave's Welcome and Rewards WebUI pages, since they rely on the ability to assign untrusted text to the innerHTML element to deal with translations and error messages (you can search for dangerouslySetInnerHTML in *.tsx files to find where exactly this is a problem).

This is consistent with what upstream Chromium does for pages that don't support Trusted Types yet (see CL 2234238), but it would be good if Brave's WebUI pages could eventually migrate from this model, which would need some refactor of the current JS code, which heavily relies on innerHTML for translations.

Chromium change:

Steps to Reproduce

  1. Build Cr87-based Brave with the patch mentioned in the description reverted
  2. Load Brave Rewards main page (brave://rewards)

Actual result:

The page doesn't load and there's an error on the console saying "This document requires 'TrustedHTML' assignment."

Expected result:

The page should work fine, no errors on the console.

Reproduces how often:

Always, assuming the patch mentioned in the description is reverted

Brave version (brave://version info)

Brave 1.15.37 or newer (Chromium: 87.0.4250.0 (Developer Build) (64-bit)), but only with the patch reverted.

QA test steps

see test plan in brave/brave-core#6669

@diracdeltas
Copy link
Member

good call, we shouldn't be using innerHTML anyway. (it's mentioned in our security review guidelines)

@diracdeltas diracdeltas self-assigned this Sep 9, 2020
@srirambv srirambv changed the title Avoid relying on innerHTML for Brave Rewards & Welcome pages [Desktop] Avoid relying on innerHTML for Brave Rewards & Welcome pages Sep 10, 2020
@diracdeltas diracdeltas added the priority/P3 The next thing for us to work on. It'll ride the trains. label Sep 10, 2020
@diracdeltas
Copy link
Member

@mariospr how do i revert this patch for a build? sorry i've not had to do this before.

@mariospr
Copy link
Contributor Author

@mariospr how do i revert this patch for a build? sorry i've not had to do this before.

Apologies, I think I might have poorly explained the problem in the description 🤔

There is no patch to revert on any current build, nor even on a branch right now... the problem only affected the WIP branch cr87 until we figured out the patch to solve the issue, which has been applied in brave/brave-core@37848a5f. This was not a problem before (neither on the current stable cr85-based version of Brave, nor on the incoming cr86-based one), so the only way you could experience this problem is by building the cr87 branch from sources with the path brave/brave-core@37848a5f reverted on top.

So, when I said that the problem reproduces "always for Brave 1.15.37 or newer (Chromium: 87.0.4250.0), but only with the patch reverted", it was just a way for me to show where the problem was before it got worked around for the incoming cr87-based release, not that the problem is still reproducible in there. But, as said, this is a workaround and the true fix would be to avoid relying on innerHTML, which is what this issue is actually for.

Hope that this clarifies things, but please feel free to ask more questions if not! 🙂

@zenparsing
Copy link

For localization of strings that may contain markup (such as links) when displayed, we should use the pattern described here.

@diracdeltas
Copy link
Member

@mariospr ah ok, thanks for clarifying.

@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Sep 29, 2020

Verification passed on


Brave | 1.16.43 Chromium: 86.0.4240.55 (Official Build) nightly (64-bit)
-- | --
Revision | a6d625ef6f7fe8ea0675f1cf759155a05ee1be40-refs/branch-heads/4240@{#953}
OS | Windows 10 OS Version 1903 (Build 18362.1016)



Verification completed using

Brave	1.16.57 Chromium: 86.0.4240.75 (Official Build) dev (x86_64)
Revision	c69c33933bfc72a159aceb4aeca939eb0087416c-refs/branch-heads/4240@{#1149}
OS	macOS Version 10.14.6 (Build 18G3020)

Verified test plan from brave/brave-core#6669

16 word

  • Confirmed min 25 BAT balance required for wallet verification

25 BAT min

  • Confirmed BAT value displayed on "Reset" tab

reset warning

  • Confirmed Uphold modal is displayed

Uphold

Encountered #11908 when attempting to confirm unsupported region message.


Verification passed on

Brave 1.16.55 Chromium: 86.0.4240.72 (Official Build) dev (64-bit)
Revision 581582174c512f44f44fd1aea340471f54b2365f-refs/branch-heads/4240@{#1134}
OS Ubuntu 18.04 LTS

deeppandya pushed a commit to brave/brave-core that referenced this issue Oct 7, 2020
@srirambv srirambv removed the OS/Android Fixes related to Android browser functionality label Oct 19, 2020
@srirambv
Copy link
Contributor

Removed OS/Android label after discussing with @NejcZdovc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants