Closed Bug 2070804 Opened 2 months ago Closed 22 days ago

measure Trusted Types usage

Categories

(Core :: DOM: Security, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
161 Branch
Tracking Status
firefox161 --- fixed

People

(Reporter: freddy, Assigned: freddy)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 3 external files, 1 obsolete file)

Bug 2070801 evaluates Trusted Types in the CSP policy.
It would be great if we had use counters / probes for the Web APIs

  • TT policies created
  • TT policies invoked (createHTML, et al) manually
  • ....invoked implicitly by a "default" policy
Assignee: nobody → fbraun
Status: NEW → ASSIGNED
Attachment #9649643 - Attachment is obsolete: true

Changing the approach a bit. We want to measure trusted-types (TT) with a specific focus on what pages on the web might be "ready to adopt" it, given a set of criteria:

  • Does the page use Javascript at all?
  • Does the page us innerHTML/insertAdjacentHTML/outerHTML: yes/no
  • Does the page use document.write/document.writeln: yes/no
  • Does the CSP use Trusted types: yes/no/reporting
  • Does the code instantiate a TT policy object: yes/no
  • Does the code call into the TT policy to create trusted types: yes/no
  • Include library that can easily support TT: yes/no (React, Preact, Angular, Lit, maybe HTMX)

This adds a Glean labeled_counter whose label encodes the full combination of readiness signals for that document:

htmlsink-{none,trusted,string}_writesink-{none,trusted,string}_ttcsp-{none,report,enforce}_strictcsp-{none,report,enforce}_created-{0,1}_used-{0,1}_lib-{0,1}_js-{0,1}

Recording depends on the pref
dom.security.trusted_types.readiness_telemetry.enabled

Expose dom.security.trusted_types.readiness_telemetry.enabled through
a Nimbus setPref feature so the measurement can be sampled

Set the HasTTLibrary signal, reported as the lib dimension of
security.trusted_types_readiness, when a page uses one of React, Angular,
Preact, Lit or htmx.

Detections:

  • Lit: TrustedTypePolicyFactory::CreatePolicy matches the "lit-html" policy name, which Lit always creates when it loads. It is checked before the CSP check, so a blocked attempt still counts.
  • React: React DOM looks up REACT_DEVTOOLS_GLOBAL_HOOK when it loads. nsGlobalWindowInner::MayResolve and DoResolve recognize that id, from a new XPCJSContext string id, and record the lookup without resolving it, ignoring Xray lookups. Defining the global goes through the resolve hook too, so at pagehide the lookup only counts if the hook still does not exist. When it does exist, the pagehide check counts it if the DevTools hook's renderers Map is non-empty, or if the page defined the hook itself, typically to disable DevTools. A hook behind an accessor, as the DevTools extension may install it, is not read and does not count.
  • htmx: an htmx global property.
  • Angular: an ng-version attribute anywhere in the document.
  • Preact: the root vnode Preact's render() stores in its container's k expando, validated by its own undefined constructor and numeric v, at pagehide.

browser_trusted_types_libraries.js checks each detection against a page that
only reproduces its symptom, and that an empty DevTools hook or an unrelated
__k expando are not detected.

Attachment #9659264 - Attachment description: WIP: Bug 2070804 - Detect libraries that ease Trusted Types adoption for the readiness telemetry r?tschuster → Bug 2070804 - Detect libraries that ease Trusted Types adoption for the readiness telemetry r?tschuster
Attachment #9651901 - Attachment description: WIP: Bug 2070804 - Add a Nimbus feature gating Trusted Types readiness telemetry r?#nimbus-reviewers → Bug 2070804 - Add a Nimbus feature gating Trusted Types readiness telemetry r?#nimbus-reviewers
Attachment #9651900 - Attachment description: WIP: Bug 2070804 - Add per-document Trusted Types readiness telemetry r?tschuster → Bug 2070804 - Add per-document Trusted Types readiness telemetry r?tschuster
Attached file data-review.txt —

First pass at a data review

Attachment #9667369 - Flags: data-review?(chutten)

Comment on attachment 9667369 [details]
data-review.txt

Actually, starting May 7, 2024, all data collections in projects reviewed in Phabricator also perform data review in Phabricator: https://wiki.mozilla.org/Data_Collection#Firefox_Desktop.2C_Firefox_and_Focus_for_Android.2C_Gecko_.28from_May_7.2C_2024.29

In short, following what the Herald message says, code authors and code reviewers together determine what level of review is needed for new or expanded data collections. You might never need to fill out a data review request form again! (For instrumentation in projects reviewed in Phabricator, anyway)

Attachment #9667369 - Flags: data-review?(chutten)
Status: ASSIGNED → RESOLVED
Closed: 22 days ago
Resolution: --- → FIXED
Target Milestone: --- → 161 Branch
Depends on: 2089997
QA Whiteboard: [qa-triage-done-c162/b161]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: