Implement Trusted Type support for setAttribute/setAttributeNS
Categories
(Core :: DOM: Security, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox135 | --- | fixed |
People
(Reporter: fredw, Assigned: fredw)
References
(Blocks 2 open bugs)
Details
(Whiteboard: [domsecurity-backlog], [wptsync upstream])
Attachments
(5 files)
See attached testcase.
IIUC this corresponds to this PR to the DOM spec for setAttribute/setAttributeNS as well as the following sections from the trusted type spec.
https://w3c.github.io/trusted-types/dist/spec/#validate-attribute-mutation
https://w3c.github.io/trusted-types/dist/spec/#get-trusted-type-data-for-attribute
This is also at least making the following tests fail:
trusted-types/trusted-types-event-handlers.html (see testing/web-platform/meta/trusted-types/trusted-types-event-handlers.html.ini)
trusted-types/TrustedTypePolicyFactory-metadata.tentative.html (failure shows up after implementing getAttributeType in bug 1917783)
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 2•1 year ago
|
||
Updating title, event handler content attribute are only one case.
In general, setAttribute/setAttributeNS should handle all attributes mentioned on https://w3c.github.io/trusted-types/dist/spec/#abstract-opdef-get-trusted-type-data-for-attribute
Similar logic is implemented in TrustedTypePolicyFactory::GetAttributeType and we should make sure to share code as much as possible.
| Assignee | ||
Comment 3•1 year ago
|
||
This patch introduces TrustedTypeUtils::GetTrustedTypeDataForAttribute
to implement the corresponding algorithm from the spec:
https://w3c.github.io/trusted-types/dist/spec/#get-trusted-type-data-for-attribute
It is currently only used by TrustedTypePolicyFactory::GetAttributeType
but "Get Trusted Types-compliant attribute value" will use it to when
we implement trusted types for setAttribute/setAttributeNS.
https://w3c.github.io/trusted-types/dist/spec/#validate-attribute-mutation
| Assignee | ||
Comment 4•1 year ago
|
||
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Comment 5•1 year ago
|
||
- Use cleanup functions to guarantee the state of the DOM tree before
each test. - Make more explicit why the length of the div's attribute list is
expected to be 2. - Add 2 tests for https://g-issues.chromium.org/issues/333739948
using setAttributeNS instead of setAttribute.
Updated•1 year ago
|
| Assignee | ||
Comment 6•1 year ago
•
|
||
Attached is a basic performance test for profiling purpose:
- It sets attribute via setAttribute and setAttributeNS.
- These calls perform attaching a new attribute and then modifying its value.
- It tries attributes for which GetTrustedTypeDataForAttribute returns false (title) and true (onclick).
- It can test DOM mutation in either window.document or a "data" document.
| Assignee | ||
Comment 7•1 year ago
|
||
These are the profiling results for attachment 9437631 [details] with 0.01ms sampling interval:
- dom.security.trusted_types disabled: https://share.firefox.dev/4eAhAE2
- dom.security.trusted_types enabled: https://share.firefox.dev/48QGsX5
- dom.security.trusted_types enabled, data document: https://share.firefox.dev/48NCpL4
- dom.security.trusted_types enabled, data document, testcase tweaked to only set the
titleattribute: https://share.firefox.dev/4fse5AN
I believe things look as expected:
-
The call to the "string" version of
Element::SetAttributefrom the "trusted type" version does not show up on the flame graph, thanks to thensMutationGuard. -
For the two first profiles, the call to
GetTrustedTypesCompliantAttributeValuedoes not show up either when filtering forSetAttribute. When filtering forGetTrustedTypesCompliantAttributeValue, we see that it exits early as expected ; we get no results when filtering forGetTrustedTypeDataForAttributeorGetTrustedTypesCompliantString. -
For the third profile, the call to
GetTrustedTypesCompliantAttributeValueshows up on the flame graph when filtering forSetAttribute. Filtering forGetTrustedTypesCompliantAttributeValue, it is essentially spending time inGetTrustedTypeDataForAttribute(IsEventAttributeNamedoing a map lookup) andGetTrustedTypesCompliantString(retrieving the global window object). We get no results when filtering forGetScporDoesSinkTypeRequireTrustedTypes, as previously tested for innerHTML. -
For the fourth profile, the call to
GetTrustedTypesCompliantAttributeValuedoes not show up either when filtering forSetAttribute. When filtering forGetTrustedTypesCompliantAttributeValue, we see that it exits early after theGetTrustedTypeDataForAttributecall (IsEventAttributeNameexits early without map lookup) ; we get no results when filtering forGetTrustedTypesCompliantString.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 8•1 year ago
|
||
Patch set at https://lando.services.mozilla.com/D227943 have been updated to use c++ templates and address review feedback.
New try job is available at : https://treeherder.mozilla.org/jobs?repo=try&revision=a2df508e2bd1f0c7c01f72dbce8fd9eb00d47df1
try perf submitted here: https://perf.compare/compare-results?baseRev=e9a124617383f6f84e987c5e91bbcab5b4033c83&newRev=91dc606f59b35aeda8987ed705a92c8d7ffd8f0e&baseRepo=try&newRepo=try&framework=13
| Assignee | ||
Comment 9•1 year ago
|
||
So https://perf.compare/subtests-compare-results?baseRev=e9a124617383f6f84e987c5e91bbcab5b4033c83&baseRepo=try&newRev=91dc606f59b35aeda8987ed705a92c8d7ffd8f0e&newRepo=try&framework=13&baseParentSignature=5131097&newParentSignature=5131097 does not report any regression.
Looking over each subtest, I guess the only significant difference is the 11% for Editor-TipTap/Highlight/Async, which seems due to 3 slow runs: https://treeherder.mozilla.org/perfherder/graphs?highlightedRevisions=e9a124617383&highlightedRevisions=91dc606f59b3&series=try%2C50f3328343643f6c9f3668f4c30ae2baf64165c5%2C1%2C13&timerange=86400
| Assignee | ||
Comment 10•1 year ago
|
||
@smaug: I'm setting the needinfo flag, so you can take a look whenever you have time:
-
Review the stack at https://lando.services.mozilla.com/D227943 ; they are all approved but would be good to take a look now that things moved to C++ templates.
-
Check profiling results (comment 7)
I plan to land the patches one bug at a time, but won't do it until I get your feedback on these points.
Comment 11•1 year ago
|
||
That is showing only "important changes".
(need to still use the older perfherder to get links to share)
So I think sp3 looks good.
Comment 7 shows that you have a11y enabled? That slows down things quite a bit.
But the setAttribute method itself looks reasonable. Thanks for testing.
| Assignee | ||
Comment 12•1 year ago
|
||
(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #11)
Comment 7 shows that you have a11y enabled? That slows down things quite a bit.
Thanks for checking. Mmh, I'm not sure what's happening with these mozilla::a11y::EventQueue events, I don't think I have a11y enabled.
Comment 13•1 year ago
|
||
about:support should tell if a11y is enabled.
(but that is unrelated to this bug, though I guess the new code might show up in the profiles in a bit different ways if a11y wasn't enabled)
| Assignee | ||
Comment 14•1 year ago
|
||
Yes, it seems to be enabled. Setting accessibility.force_disabled=1 works around that, although I'm not sure this is supposed to be necessary. anyway, as you said that's unrelated to that bug.
Comment 15•1 year ago
|
||
Comment 17•1 year ago
|
||
Backed out for causing multiple failures.
- Push with failures - build bustages
- Failure Log
- Failure line: /builds/worker/checkouts/gecko/dom/security/trusted-types/TrustedTypeUtils.cpp:50:1: error: control reaches end of non-void function [-Werror=return-type]
- Push with failures - wpt failures
- Failure Log
- Failure line: TEST-UNEXPECTED-PASS | /trusted-types/trusted-types-event-handlers.html | Event handler div.ontouchstart should be blocked. - expected FAIL
| Assignee | ||
Comment 19•1 year ago
|
||
(In reply to Serban Stanca [:SerbanS] from comment #17)
It seems some platforms believe there is reachable code after the switch() statements, and Android passes more tests.
Comment 20•1 year ago
|
||
Comment 22•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/d0f1354e4993
https://hg.mozilla.org/mozilla-central/rev/094b1d5348ab
https://hg.mozilla.org/mozilla-central/rev/eb723beab1df
Description
•