From 7aa211dd304c18fda57df8754c747fb694c0b33c Mon Sep 17 00:00:00 2001 From: koto Date: Wed, 21 Aug 2019 09:35:23 -0700 Subject: [PATCH] Make Closure Trusted Types integration not require TrustedURL values, as they will soon be removed from the Trusted Types API - https://github.com/WICG/trusted-types/pull/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 --- closure/goog/base.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/closure/goog/base.js b/closure/goog/base.js index 033ddfd457..cc1511eb57 100644 --- a/closure/goog/base.js +++ b/closure/goog/base.js @@ -4168,6 +4168,21 @@ goog.createTrustedTypesPolicy = function(name) { } catch (e) { goog.logToConsole_(e.message); } + + // TrustedTypes API will deprecate TrustedURLs in Chrome 78. To prepare for + // that, and make the Closure code emulate the post-deprecation behavior + // of the API, we attempt to create a default policy that blesses any value + // to TrustedURL. This is a best-effort attempt. If that does not succeed, + // the application fails close - TrustedURL values will simply be required + // at all relevant sinks. + if (typeof TrustedURL !== 'undefined' && TrustedTypes.getPolicyNames && + TrustedTypes.getPolicyNames().indexOf('default') === -1) { + try { + TrustedTypes.createPolicy('default', {createURL: goog.identity_}, true); + } catch (e) { + goog.logToConsole_(e.message); + } + } return policy; };