Commit 7c4c1500 authored by Mike West's avatar Mike West Committed by Commit Bot

Make Trusted Types ununforgeable.

Context: https://github.com/w3c/webappsec-trusted-types/issues/257

Bug: 1058400
Change-Id: Ie91e8ad7e8eff814e3aaa1d940ca0bc1d6c2f09e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089705Reviewed-by: default avatarYifan Luo <lyf@chromium.org>
Commit-Queue: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748022}
parent 4e6e084b
...@@ -209,7 +209,7 @@ ...@@ -209,7 +209,7 @@
[DisableInNewIDLCompiler] attribute DOMMatrixConstructor WebKitCSSMatrix; [DisableInNewIDLCompiler] attribute DOMMatrixConstructor WebKitCSSMatrix;
// TrustedTypes API: http://github.com/wicg/trusted-types // TrustedTypes API: http://github.com/wicg/trusted-types
[RuntimeEnabled=TrustedDOMTypes, Unforgeable] readonly attribute TrustedTypePolicyFactory trustedTypes; [RuntimeEnabled=TrustedDOMTypes] readonly attribute TrustedTypePolicyFactory trustedTypes;
}; };
Window includes GlobalEventHandlers; Window includes GlobalEventHandlers;
......
...@@ -10,8 +10,8 @@ typedef (DOMString or TrustedHTML or TrustedScript or TrustedScriptURL) TrustedS ...@@ -10,8 +10,8 @@ typedef (DOMString or TrustedHTML or TrustedScript or TrustedScriptURL) TrustedS
Exposed=Window, Exposed=Window,
RuntimeEnabled=TrustedDOMTypes RuntimeEnabled=TrustedDOMTypes
] interface TrustedTypePolicy { ] interface TrustedTypePolicy {
[Unforgeable] readonly attribute DOMString name; readonly attribute DOMString name;
[CallWith=ScriptState, RaisesException, Unforgeable] TrustedHTML createHTML(DOMString input, any... args); [CallWith=ScriptState, RaisesException] TrustedHTML createHTML(DOMString input, any... args);
[CallWith=ScriptState, RaisesException, Unforgeable] TrustedScript createScript(DOMString input, any... args); [CallWith=ScriptState, RaisesException] TrustedScript createScript(DOMString input, any... args);
[CallWith=ScriptState, RaisesException, Unforgeable] TrustedScriptURL createScriptURL(DOMString input, any... args); [CallWith=ScriptState, RaisesException] TrustedScriptURL createScriptURL(DOMString input, any... args);
}; };
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
Exposed=(Window, Worker), Exposed=(Window, Worker),
RuntimeEnabled=TrustedDOMTypes RuntimeEnabled=TrustedDOMTypes
] interface TrustedTypePolicyFactory { ] interface TrustedTypePolicyFactory {
[RaisesException, Unforgeable] TrustedTypePolicy createPolicy(DOMString policyName, TrustedTypePolicyOptions policyOptions); [RaisesException] TrustedTypePolicy createPolicy(DOMString policyName, TrustedTypePolicyOptions policyOptions);
[Unforgeable] readonly attribute TrustedTypePolicy defaultPolicy; readonly attribute TrustedTypePolicy defaultPolicy;
// All the policy object names that have been created // All the policy object names that have been created
[CallWith=ScriptState, Unforgeable] boolean isHTML(any checkedObject); [CallWith=ScriptState] boolean isHTML(any checkedObject);
[CallWith=ScriptState, Unforgeable] boolean isScript(any checkedObject); [CallWith=ScriptState] boolean isScript(any checkedObject);
[CallWith=ScriptState, Unforgeable] boolean isScriptURL(any checkedObject); [CallWith=ScriptState] boolean isScriptURL(any checkedObject);
[Unforgeable] readonly attribute TrustedHTML emptyHTML; readonly attribute TrustedHTML emptyHTML;
[Unforgeable] readonly attribute TrustedScript emptyScript; readonly attribute TrustedScript emptyScript;
// Trusted Types metadata, following the proposal in: // Trusted Types metadata, following the proposal in:
// https://github.com/WICG/trusted-types/pull/149/commits/ecd9ab0b6993674951bfc7b44a04530fce7468a7 // https://github.com/WICG/trusted-types/pull/149/commits/ecd9ab0b6993674951bfc7b44a04530fce7468a7
......
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
readonly attribute FontFaceSet fonts; readonly attribute FontFaceSet fonts;
// TrustedTypes API: http://github.com/wicg/trusted-types // TrustedTypes API: http://github.com/wicg/trusted-types
[RuntimeEnabled=TrustedDOMTypes, Unforgeable] readonly attribute TrustedTypePolicyFactory trustedTypes; [RuntimeEnabled=TrustedDOMTypes] readonly attribute TrustedTypePolicyFactory trustedTypes;
}; };
WorkerGlobalScope includes WindowOrWorkerGlobalScope; WorkerGlobalScope includes WindowOrWorkerGlobalScope;
......
...@@ -4,33 +4,43 @@ typedef (DOMString or TrustedHTML) HTMLString; ...@@ -4,33 +4,43 @@ typedef (DOMString or TrustedHTML) HTMLString;
typedef (DOMString or TrustedScript) ScriptString; typedef (DOMString or TrustedScript) ScriptString;
typedef (DOMString or TrustedScriptURL) ScriptURLString; typedef (DOMString or TrustedScriptURL) ScriptURLString;
[Exposed=(Window, Worker)] [
interface TrustedHTML { Exposed=(Window, Worker),
SecureContext
] interface TrustedHTML {
stringifier; stringifier;
}; };
[Exposed=(Window, Worker)] [
interface TrustedScript { Exposed=(Window, Worker),
SecureContext
] interface TrustedScript {
stringifier; stringifier;
}; };
[Exposed=(Window, Worker)] [
interface TrustedScriptURL { Exposed=(Window, Worker),
SecureContext
] interface TrustedScriptURL {
stringifier; stringifier;
}; };
[Exposed=(Window, Worker)] [
interface TrustedTypePolicyFactory { Exposed=(Window, Worker),
[Unforgeable] TrustedTypePolicy createPolicy(DOMString policyName, TrustedTypePolicyOptions policyOptions); SecureContext
] interface TrustedTypePolicyFactory {
TrustedTypePolicy createPolicy(DOMString policyName, TrustedTypePolicyOptions policyOptions);
// All the policy object names that have been created // All the policy object names that have been created
}; };
[Exposed=(Window, Worker)] [
interface TrustedTypePolicy { Exposed=(Window, Worker),
[Unforgeable] readonly attribute DOMString name; SecureContext
[Unforgeable] TrustedHTML createHTML(DOMString input); ] interface TrustedTypePolicy {
[Unforgeable] TrustedScript createScript(DOMString input); readonly attribute DOMString name;
[Unforgeable] TrustedScriptURL createScriptURL(DOMString input); TrustedHTML createHTML(DOMString input);
TrustedScript createScript(DOMString input);
TrustedScriptURL createScriptURL(DOMString input);
}; };
dictionary TrustedTypePolicyOptions { dictionary TrustedTypePolicyOptions {
......
...@@ -82,40 +82,4 @@ ...@@ -82,40 +82,4 @@
assert_false(trustedTypes.isScriptURL('test')); assert_false(trustedTypes.isScriptURL('test'));
assert_false(trustedTypes.isScriptURL({})); assert_false(trustedTypes.isScriptURL({}));
}, 'TrustedTypePolicyFactory.isXXX should accept anything without throwing.'); }, 'TrustedTypePolicyFactory.isXXX should accept anything without throwing.');
// Redefinition tests, assign to property.
// (Assignments will through in the polyfill (because the objects are frozen)
// but will be silently dropped in the native implementation (because that's
// what [Unforgeable] does. Hence, the tests use try {..} catch {} to cover
// both situationsm rather than expect_throws(...).)
test(t => {
try { trustedTypes.isHTML = () => 'fake'; } catch { }
assert_false(trustedTypes.isHTML({}));
}, 'TrustedTypePolicyFactory.IsHTML cannot be redefined.');
test(t => {
try { trustedTypes.isScript = () => 'fake'; } catch { }
assert_false(trustedTypes.isScript({}));
}, 'TrustedTypePolicyFactory.isScript cannot be redefined.');
test(t => {
try { trustedTypes.isScriptURL = () => 'fake'; } catch { }
assert_false(trustedTypes.isScriptURL({}));
}, 'TrustedTypePolicyFactory.isScriptURL cannot be redefined.');
// Redefinition tests, via Object.defineProperty.
test(t => {
try { Object.defineProperty(trustedTypes, 'isHTML', () => 'fake'); } catch { }
assert_false(trustedTypes.isHTML({}));
}, 'TrustedTypePolicyFactory.IsHTML cannot be redefined via defineProperty.');
test(t => {
try { Object.defineProperty(trustedTypes, 'isScript', () => 'fake'); } catch { }
assert_false(trustedTypes.isScript({}));
}, 'TrustedTypePolicyFactory.isScript cannot be redefined via definePropert.');
test(t => {
try { Object.defineProperty(trustedTypes, 'isScriptURL', () => 'fake'); } catch { }
assert_false(trustedTypes.isScriptURL({}));
}, 'TrustedTypePolicyFactory.isScriptURL cannot be redefined via definePropert.');
</script> </script>
...@@ -1426,10 +1426,17 @@ interface TransformStream ...@@ -1426,10 +1426,17 @@ interface TransformStream
method constructor method constructor
interface TrustedTypePolicyFactory interface TrustedTypePolicyFactory
attribute @@toStringTag attribute @@toStringTag
getter defaultPolicy
getter emptyHTML
getter emptyScript
method constructor method constructor
method createPolicy
method getAttributeType method getAttributeType
method getPropertyType method getPropertyType
method getTypeMapping method getTypeMapping
method isHTML
method isScript
method isScriptURL
interface URL interface URL
attribute @@toStringTag attribute @@toStringTag
getter hash getter hash
...@@ -3702,6 +3709,7 @@ interface WorkerGlobalScope : EventTarget ...@@ -3702,6 +3709,7 @@ interface WorkerGlobalScope : EventTarget
getter origin getter origin
getter performance getter performance
getter self getter self
getter trustedTypes
method atob method atob
method btoa method btoa
method clearInterval method clearInterval
...@@ -3802,7 +3810,6 @@ interface WritableStreamDefaultWriter ...@@ -3802,7 +3810,6 @@ interface WritableStreamDefaultWriter
getter onsync getter onsync
getter registration getter registration
getter serviceWorker getter serviceWorker
getter trustedTypes
method gc method gc
method skipWaiting method skipWaiting
setter cookieStore setter cookieStore
......
...@@ -1357,10 +1357,17 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -1357,10 +1357,17 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method constructor [Worker] method constructor
[Worker] interface TrustedTypePolicyFactory [Worker] interface TrustedTypePolicyFactory
[Worker] attribute @@toStringTag [Worker] attribute @@toStringTag
[Worker] getter defaultPolicy
[Worker] getter emptyHTML
[Worker] getter emptyScript
[Worker] method constructor [Worker] method constructor
[Worker] method createPolicy
[Worker] method getAttributeType [Worker] method getAttributeType
[Worker] method getPropertyType [Worker] method getPropertyType
[Worker] method getTypeMapping [Worker] method getTypeMapping
[Worker] method isHTML
[Worker] method isScript
[Worker] method isScriptURL
[Worker] interface URL [Worker] interface URL
[Worker] static method createObjectURL [Worker] static method createObjectURL
[Worker] static method revokeObjectURL [Worker] static method revokeObjectURL
...@@ -3752,6 +3759,7 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3752,6 +3759,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter origin [Worker] getter origin
[Worker] getter performance [Worker] getter performance
[Worker] getter self [Worker] getter self
[Worker] getter trustedTypes
[Worker] method atob [Worker] method atob
[Worker] method btoa [Worker] method btoa
[Worker] method clearInterval [Worker] method clearInterval
...@@ -3880,7 +3888,6 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3880,7 +3888,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter name [Worker] getter name
[Worker] getter onmessage [Worker] getter onmessage
[Worker] getter onmessageerror [Worker] getter onmessageerror
[Worker] getter trustedTypes
[Worker] method cancelAnimationFrame [Worker] method cancelAnimationFrame
[Worker] method close [Worker] method close
[Worker] method gc [Worker] method gc
......
...@@ -8436,13 +8436,24 @@ interface TrustedScriptURL ...@@ -8436,13 +8436,24 @@ interface TrustedScriptURL
method toString method toString
interface TrustedTypePolicy interface TrustedTypePolicy
attribute @@toStringTag attribute @@toStringTag
getter name
method constructor method constructor
method createHTML
method createScript
method createScriptURL
interface TrustedTypePolicyFactory interface TrustedTypePolicyFactory
attribute @@toStringTag attribute @@toStringTag
getter defaultPolicy
getter emptyHTML
getter emptyScript
method constructor method constructor
method createPolicy
method getAttributeType method getAttributeType
method getPropertyType method getPropertyType
method getTypeMapping method getTypeMapping
method isHTML
method isScript
method isScriptURL
interface UIEvent : Event interface UIEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter detail getter detail
......
...@@ -1303,10 +1303,17 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -1303,10 +1303,17 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method constructor [Worker] method constructor
[Worker] interface TrustedTypePolicyFactory [Worker] interface TrustedTypePolicyFactory
[Worker] attribute @@toStringTag [Worker] attribute @@toStringTag
[Worker] getter defaultPolicy
[Worker] getter emptyHTML
[Worker] getter emptyScript
[Worker] method constructor [Worker] method constructor
[Worker] method createPolicy
[Worker] method getAttributeType [Worker] method getAttributeType
[Worker] method getPropertyType [Worker] method getPropertyType
[Worker] method getTypeMapping [Worker] method getTypeMapping
[Worker] method isHTML
[Worker] method isScript
[Worker] method isScriptURL
[Worker] interface URL [Worker] interface URL
[Worker] static method createObjectURL [Worker] static method createObjectURL
[Worker] static method revokeObjectURL [Worker] static method revokeObjectURL
...@@ -3574,6 +3581,7 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3574,6 +3581,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter origin [Worker] getter origin
[Worker] getter performance [Worker] getter performance
[Worker] getter self [Worker] getter self
[Worker] getter trustedTypes
[Worker] method atob [Worker] method atob
[Worker] method btoa [Worker] method btoa
[Worker] method clearInterval [Worker] method clearInterval
...@@ -3701,7 +3709,6 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3701,7 +3709,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] attribute internals [Worker] attribute internals
[Worker] getter name [Worker] getter name
[Worker] getter onconnect [Worker] getter onconnect
[Worker] getter trustedTypes
[Worker] method close [Worker] method close
[Worker] method gc [Worker] method gc
[Worker] method webkitRequestFileSystem [Worker] method webkitRequestFileSystem
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment