Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 7aa211d

Browse files
kotonreid260
authored andcommitted
Make Closure Trusted Types integration not require TrustedURL values, as they will soon be removed from the Trusted Types API - w3c/trusted-types#204.
goog.createTrustedTypesPolicy will attempt to create a default policy allowing any value to be converted to TrustedURL. RELNOTES: Trusted Types integrations will allow any value to be a TrustedURL via defensively creating a 'default' policy (to prepare for TrustedURL deprecation) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=264626714
1 parent 2f43b5f commit 7aa211d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

closure/goog/base.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,21 @@ goog.createTrustedTypesPolicy = function(name) {
41684168
} catch (e) {
41694169
goog.logToConsole_(e.message);
41704170
}
4171+
4172+
// TrustedTypes API will deprecate TrustedURLs in Chrome 78. To prepare for
4173+
// that, and make the Closure code emulate the post-deprecation behavior
4174+
// of the API, we attempt to create a default policy that blesses any value
4175+
// to TrustedURL. This is a best-effort attempt. If that does not succeed,
4176+
// the application fails close - TrustedURL values will simply be required
4177+
// at all relevant sinks.
4178+
if (typeof TrustedURL !== 'undefined' && TrustedTypes.getPolicyNames &&
4179+
TrustedTypes.getPolicyNames().indexOf('default') === -1) {
4180+
try {
4181+
TrustedTypes.createPolicy('default', {createURL: goog.identity_}, true);
4182+
} catch (e) {
4183+
goog.logToConsole_(e.message);
4184+
}
4185+
}
41714186
return policy;
41724187
};
41734188

0 commit comments

Comments
 (0)