Skip to content

Sanitizing inner html text to be TrustedTypes complaint on adblock page - Uplift to 1.49.x #17066

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

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SHIELDS_DOWN" desc="Label for shields status down site settings.">
Shields Down
</message>
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_TITLE" desc="The title for Brave shields section in settings">
Shields
</message>
Expand Down Expand Up @@ -298,10 +298,6 @@
<message name="IDS_BRAVE_ADBLOCK_CONTENT_FILTER_LABEL_DESCRIPTION" desc="Long description describing what Content Filtering does">
Enable custom filters that block regional and language-specific trackers and Annoyances.
</message>
<message name="IDS_BRAVE_ADBLOCK_CONTENT_FILTERING_DESC" desc="Long description describing what Content Filtering does">
Enable custom filters that block regional and language-specific trackers and
<ph name="BEGIN_LINK">&lt;a target="_blank" href="$1"&gt;</ph>Annoyances<ph name="END_LINK">&lt;/a&gt;</ph>.
</message>
<message name="IDS_BRAVE_ADBLOCK_ADD_CUSTOM_FILTERS_LISTS_LABEL" desc="Label for custom filters lists section">
Add custom filter lists
</message>
Expand Down Expand Up @@ -835,7 +831,7 @@
</message>
<message name="IDS_SETTINGS_TOR_SNOWFLAKE_INSTALL_FAILED" desc="">
The Snowflake extension necessary for this functionality could not be downloaded. Please check your Internet connection and try again.
</message>
</message>
<message name="IDS_SETTINGS_TOR_SELECT_BUILT_IN_RADIO" desc="">
Select a built-in bridge
</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,30 @@
>
[[item.subscription_url]]
</span>
<span inner-h-t-m-l="[[getStatus_(
item.last_update_attempt,
item.last_successful_update_attempt,
item.last_updated_pretty_text)]]"></span>
<!--
/* "Last updated" column can have four distinct states:
* No update ever attempted: fine to show blank
* Update attempted and failed, and never succeeded previously: show
* "Download failure"
* Update attempted and failed, but succeeded previously: show
* "Download failure since + last updated time"
* Update attempted and succeeded: show the last updated time
*/
-->
<span>
<template is="dom-if" if="[[isEqual_(item.last_update_attempt, 0)]]">
<span>—</span>
</template>
<template is="dom-if" if="[[isEqual_(item.last_successful_update_attempt, 0)]]">
<mark>[[i18n('adblockSubscribeUrlDownloadFailed')]]</mark>
</template>
<template is="dom-if" if="[[isFailedUpdate_(item)]]">
<span>[[item.last_updated_pretty_text]] <mark>[[i18n('adblockSubscribeUrlUpdateFailed')]]</mark></span>
</template>
<template is="dom-if" if="[[isLastAttemptFailed_(item)]]">
<span>[[item.last_updated_pretty_text]]</span>
</template>
</span>
<adblock-subscribe-dropdown
on-update-subscription="handleUpdateSubscription_"
on-view-subscription="handleViewSubscription_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,16 @@ class AdBlockSubpage extends AdBlockSubpageBase {
return this.i18nAdvanced(id, { substitutions: [ link ]})
}

getStatus_(last_update_attempt, last_successful_update_attempt, last_updated_pretty_text) {
/* "Last updated" column can have four distinct states:
* No update ever attempted: fine to show blank
* Update attempted and failed, and never succeeded previously: show
* "Download failure"
* Update attempted and failed, but succeeded previously: show
* "Download failure since + last updated time"
* Update attempted and succeeded: show the last updated time
*/

if (last_update_attempt === 0) {
return '—'
} else if (last_successful_update_attempt === 0) {
return `<mark>${this.i18n('adblockSubscribeUrlDownloadFailed')}<mark>`
} else if (last_successful_update_attempt !== last_update_attempt) {
return `${last_updated_pretty_text} <mark>${this.i18n('adblockSubscribeUrlUpdateFailed')}</mark>`
} else {
return last_updated_pretty_text
}
isEqual_(lhs, rhs) {
return lhs === rhs
}

isFailedUpdate_(item) {
return item.last_successful_update_attempt !== 0 && item.last_successful_update_attempt !== item.last_update_attempt
}

isLastAttemptFailed_(item) {
return item.last_successful_update_attempt !== 0 && item.last_successful_update_attempt === item.last_update_attempt
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"walletNetworkReset", IDS_BRAVE_WALLET_NETWORK_RESET},
{"walletNetworkSetAsActive", IDS_BRAVE_WALLET_NETWORK_SET_AS_ACTIVE},
{"adblockContentFilteringLabel", IDS_BRAVE_ADBLOCK_CONTENT_FILTERING_LABEL},
{"adblockContentFilteringDesc", IDS_BRAVE_ADBLOCK_CONTENT_FILTERING_DESC},
{"adblockAddCustomFiltersListsLabel",
IDS_BRAVE_ADBLOCK_ADD_CUSTOM_FILTERS_LISTS_LABEL},
{"adblockContentFilterLabelDesc",
Expand Down