@capagents/forgeqe 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/HOW_TO_USE.md +435 -78
  2. package/README.md +21 -6
  3. package/THIRD_PARTY_NOTICES.md +210 -1
  4. package/dist/docs-site/CREDITS.md +6 -0
  5. package/dist/docs-site/architecture-map/index.html +1 -1
  6. package/dist/docs-site/docs/app-theme.css +100 -8
  7. package/dist/docs-site/docs/architecture/index.html +210 -214
  8. package/dist/docs-site/docs/area-api/index.html +350 -0
  9. package/dist/docs-site/docs/area-automated-tests/index.html +967 -0
  10. package/dist/docs-site/docs/area-browser/index.html +430 -0
  11. package/dist/docs-site/docs/area-data/index.html +605 -0
  12. package/dist/docs-site/docs/area-desktop/index.html +755 -0
  13. package/dist/docs-site/docs/area-mobile/index.html +631 -0
  14. package/dist/docs-site/docs/area-operations/index.html +1069 -0
  15. package/dist/docs-site/docs/area-pull-requests/index.html +208 -0
  16. package/dist/docs-site/docs/area-quality/index.html +365 -0
  17. package/dist/docs-site/docs/area-release/index.html +320 -0
  18. package/dist/docs-site/docs/area-setup/index.html +1192 -0
  19. package/dist/docs-site/docs/area-systems/index.html +207 -0
  20. package/dist/docs-site/docs/area-test-cases/index.html +694 -0
  21. package/dist/docs-site/docs/containers/index.html +97 -104
  22. package/dist/docs-site/docs/cost-architecture/index.html +108 -112
  23. package/dist/docs-site/docs/custom-agents-first-run/index.html +19 -23
  24. package/dist/docs-site/docs/desktop/index.html +172 -162
  25. package/dist/docs-site/docs/desktop-ci/index.html +26 -33
  26. package/dist/docs-site/docs/evidence/index.html +253 -257
  27. package/dist/docs-site/docs/feature-test-prompts/index.html +66 -70
  28. package/dist/docs-site/docs/get-started/index.html +495 -0
  29. package/dist/docs-site/docs/graphify/index.html +42 -46
  30. package/dist/docs-site/docs/guardrails/index.html +17 -21
  31. package/dist/docs-site/docs/index.html +17 -6729
  32. package/dist/docs-site/docs/mobile/index.html +155 -162
  33. package/dist/docs-site/docs/model-routing/index.html +44 -51
  34. package/dist/docs-site/docs/overview/index.html +176 -0
  35. package/dist/docs-site/docs/product-graph/index.html +52 -55
  36. package/dist/docs-site/docs/product-knowledge/index.html +11 -15
  37. package/dist/docs-site/docs/product-views/index.html +53 -57
  38. package/dist/docs-site/docs/reference/index.html +379 -0
  39. package/dist/docs-site/docs/search.js +1 -1
  40. package/dist/docs-site/docs/using/index.html +480 -0
  41. package/dist/docs-site/docs/web-app/index.html +147 -93
  42. package/dist/docs-site/security/index.html +930 -0
  43. package/dist/docs-site/security/security-theme.css +161 -0
  44. package/dist/docs-site/security/security.js +1465 -0
  45. package/dist/docs-site/vendor/react-18.3.1.production.min.js +31 -0
  46. package/dist/docs-site/vendor/react-dom-18.3.1.production.min.js +267 -0
  47. package/dist/docs-site/vendor/reactflow-11.11.4.umd.js +10 -0
  48. package/dist/forgeqe.js +1902 -1895
  49. package/dist/web/THIRD_PARTY_NOTICES.md +0 -136
  50. package/dist/web/assets/Agent-CPhmZdFX.js +8 -0
  51. package/dist/web/assets/AgentWork-BXdN9xgi.js +2 -0
  52. package/dist/web/assets/ApiTests-Do3xLjfB.js +10 -0
  53. package/dist/web/assets/Browse-WVkJT6Bs.js +2 -0
  54. package/dist/web/assets/Chat-CDc9UcQX.js +3 -0
  55. package/dist/web/assets/CommandPalette-BAZm62lV.js +1 -0
  56. package/dist/web/assets/Compare-Br6n9T9L.js +1 -0
  57. package/dist/web/assets/Cost-BBUyBu3Y.js +1 -0
  58. package/dist/web/assets/Data-Ch2DPEWp.js +6 -0
  59. package/dist/web/assets/Desktop-Qzoq-cQv.js +1 -0
  60. package/dist/web/assets/DesktopReview-CF_jQYAM.js +1 -0
  61. package/dist/web/assets/Evidence-C72Lj5_Q.js +1 -0
  62. package/dist/web/assets/Explore-ObkEpUyS.js +2 -0
  63. package/dist/web/assets/Features-CQzNo_WP.js +1 -0
  64. package/dist/web/assets/Flags-0-RniPJm.js +2 -0
  65. package/dist/web/assets/Flaky-BPJvNLCA.js +1 -0
  66. package/dist/web/assets/Impact-CfccsL_k.js +3 -0
  67. package/dist/web/assets/Jobs-T6m4zhDy.js +5 -0
  68. package/dist/web/assets/KindPage-BDUvWe2p.js +6 -0
  69. package/dist/web/assets/Migration-Dqeh4x5u.js +2 -0
  70. package/dist/web/assets/PageAgent-DNjzIgeY.js +1 -0
  71. package/dist/web/assets/Product-nYV_scOV.js +7 -0
  72. package/dist/web/assets/Production-CGSbEWVa.js +1 -0
  73. package/dist/web/assets/Quality-BIypojZm.js +1 -0
  74. package/dist/web/assets/Readiness-BlRjwJRg.js +1 -0
  75. package/dist/web/assets/Record-v2KLI-_Z.js +1 -0
  76. package/dist/web/assets/Regression-B-jSt4Jz.js +5 -0
  77. package/dist/web/assets/RelationGraph-8J98lOVG.js +1 -0
  78. package/dist/web/assets/Reports-GI4u6SyW.js +2 -0
  79. package/dist/web/assets/Response-mhBThq2b.js +9 -0
  80. package/dist/web/assets/Responsive-DXu7Ra7K.js +3 -0
  81. package/dist/web/assets/RunDiff-D0SHDNp0.js +1 -0
  82. package/dist/web/assets/Runs-C1Gjdi9M.js +2 -0
  83. package/dist/web/assets/Settings-BGGeuvyF.js +21 -0
  84. package/dist/web/assets/Steps-D-YG0eJy.js +2 -0
  85. package/dist/web/assets/TestCases-DC4w77eQ.js +1 -0
  86. package/dist/web/assets/TestData-CvKWRVVV.js +2 -0
  87. package/dist/web/assets/TestDebt-D8YzN29_.js +1 -0
  88. package/dist/web/assets/TestManagement-C5cDCqrD.js +1 -0
  89. package/dist/web/assets/Tosca-BGUv3RiJ.js +3 -0
  90. package/dist/web/assets/WhatsNew-B_Gyuv8O.js +1 -0
  91. package/dist/web/assets/agents-C0Jg2pN8.js +1 -0
  92. package/dist/web/assets/coverage-BMP6ELFJ.js +5 -0
  93. package/dist/web/assets/dataParts-DbeCj9ga.js +3 -0
  94. package/dist/web/assets/diff-BStuTmsN.js +2 -0
  95. package/dist/web/assets/families-BBFFrUlo.js +1 -0
  96. package/dist/web/assets/filters-CnAMr286.js +1 -0
  97. package/dist/web/assets/fold-D_O_VZui.js +1 -0
  98. package/dist/web/assets/head-CRo48rPt.js +1 -0
  99. package/dist/web/assets/highlight-BcFZIf59.js +4 -0
  100. package/dist/web/assets/index-B3JsM7tv.js +64 -0
  101. package/dist/web/assets/index-CafApcbZ.css +2 -0
  102. package/dist/web/assets/input-CtzK50ZF.js +1 -0
  103. package/dist/web/assets/jsx-runtime-LKYXHABd.js +1 -0
  104. package/dist/web/assets/line-icons-rdF8DYDJ.js +1 -0
  105. package/dist/web/assets/logos-D4oVWzqa.js +1 -0
  106. package/dist/web/assets/palette-DAaGSao7.js +1 -0
  107. package/dist/web/assets/paletteCommands-Co-RlQ8q.js +1 -0
  108. package/dist/web/assets/parts-D357Wolo.js +1 -0
  109. package/dist/web/assets/productParts-B8oHRCJF.js +1 -0
  110. package/dist/web/assets/qualityParts-BLkmIfDY.js +1 -0
  111. package/dist/web/assets/recordTest-Cez2sDJO.js +1 -0
  112. package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  113. package/dist/web/assets/route-BloYJWgw.js +1 -0
  114. package/dist/web/index.html +12 -6
  115. package/docs/ARCHITECTURE.md +1 -1
  116. package/docs/BASAL.md +1 -1
  117. package/docs/DESKTOP.md +20 -1
  118. package/docs/EVIDENCE.md +1 -1
  119. package/docs/MOBILE.md +4 -4
  120. package/docs/PRODUCT_KNOWLEDGE.md +2 -0
  121. package/docs/WEB_APP.md +114 -51
  122. package/docs/user-guide.html +404 -81
  123. package/forgeqe.example.yaml +3 -3
  124. package/package.json +1 -1
  125. package/prompts/page-differs.md +1 -1
  126. package/prompts/requests-rule.md +1 -1
  127. package/prompts/test-reviewer.md +1 -1
  128. package/prompts/test-rules.md +3 -4
  129. package/skills/web-guidance/LICENSE +202 -0
  130. package/skills/web-guidance/SKILL.md +76 -0
  131. package/skills/web-guidance/UPSTREAM +67 -0
  132. package/skills/web-guidance/references/accessibility/accessibility.md +585 -0
  133. package/skills/web-guidance/references/accessibility/accessible-error-announcement.md +302 -0
  134. package/skills/web-guidance/references/accessibility/accessible-generated-content.md +41 -0
  135. package/skills/web-guidance/references/accessibility/respect-os-text-scale.md +127 -0
  136. package/skills/web-guidance/references/css/responsive-design.md +16 -0
  137. package/skills/web-guidance/references/forms/autofill-address-form.md +86 -0
  138. package/skills/web-guidance/references/forms/autofill-payment-form.md +142 -0
  139. package/skills/web-guidance/references/forms/autofill-sign-in-form.md +145 -0
  140. package/skills/web-guidance/references/forms/autofill-sign-up-form.md +155 -0
  141. package/skills/web-guidance/references/forms/forms.md +415 -0
  142. package/skills/web-guidance/references/forms/ime-safe-enter-submit.md +115 -0
  143. package/skills/web-guidance/references/forms/required-field-feedback.md +317 -0
  144. package/skills/web-guidance/references/forms/select-menu-interaction.md +310 -0
  145. package/skills/web-guidance/references/forms/slider.md +184 -0
  146. package/skills/web-guidance/references/forms/sms-otp-form.md +208 -0
  147. package/skills/web-guidance/references/forms/switch.md +60 -0
  148. package/skills/web-guidance/references/forms/validate-input-after-interaction.md +406 -0
  149. package/skills/web-guidance/references/performance/break-up-long-tasks.md +64 -0
  150. package/skills/web-guidance/references/performance/identify-heavy-scripts.md +69 -0
  151. package/skills/web-guidance/references/performance/identify-inp-causes.md +105 -0
  152. package/skills/web-guidance/references/performance/interaction-paint-timing.md +200 -0
  153. package/skills/web-guidance/references/performance/optimize-image-priority.md +73 -0
  154. package/skills/web-guidance/references/performance/performance.md +384 -0
  155. package/skills/web-guidance/references/privacy/privacy.md +247 -0
  156. package/skills/web-guidance/references/security/passkey-authentication.md +218 -0
  157. package/skills/web-guidance/references/security/passkey-management.md +310 -0
  158. package/skills/web-guidance/references/security/passkey-reauthentication.md +142 -0
  159. package/skills/web-guidance/references/security/passkey-registration.md +186 -0
  160. package/skills/web-guidance/references/security/passkeys.md +39 -0
  161. package/skills/web-guidance/references/security/sanitize-untrusted-html.md +105 -0
  162. package/skills/web-guidance/references/security/secure-external-subresources.md +202 -0
  163. package/skills/web-guidance/references/security/security.md +390 -0
  164. package/skills/web-guidance/references/security/trusted-types.md +141 -0
  165. package/skills/web-guidance/references/security/validate-origins.md +197 -0
  166. package/skills/web-guidance/references/security/verify-email-ownership.md +235 -0
  167. package/skills/web-guidance/references/ui-atoms/position-aware-tooltips.md +173 -0
  168. package/skills/web-guidance/references/ui-atoms/responsive-table.md +122 -0
  169. package/skills/web-guidance/references/ui-atoms/viewport-aware-dropdowns.md +178 -0
  170. package/skills/web-guidance/references/ui-behaviors/drag-and-drop.md +108 -0
  171. package/skills/web-guidance/references/ui-behaviors/light-dismiss-a-dialog.md +89 -0
  172. package/skills/web-guidance/references/ui-behaviors/motion.md +97 -0
  173. package/skills/web-guidance/references/ui-behaviors/platform-controls-dismiss-dialog.md +40 -0
  174. package/skills/web-guidance/references/ui-behaviors/prevent-page-scroll-under-modal-dialog.md +59 -0
  175. package/skills/web-guidance/references/ui-behaviors/search-hidden-content.md +141 -0
  176. package/skills/web-guidance/references/ui-behaviors/sortable-table.md +140 -0
  177. package/skills/web-guidance/references/ui-components/accordion.md +343 -0
  178. package/skills/web-guidance/references/ui-components/breadcrumbs.md +168 -0
  179. package/skills/web-guidance/references/ui-components/carousel.md +206 -0
  180. package/skills/web-guidance/references/ui-components/checkbox.md +144 -0
  181. package/skills/web-guidance/references/ui-components/dialog.md +218 -0
  182. package/skills/web-guidance/references/ui-components/hovercard.md +391 -0
  183. package/skills/web-guidance/references/ui-components/menu.md +415 -0
  184. package/skills/web-guidance/references/ui-components/navbar.md +281 -0
  185. package/skills/web-guidance/references/ui-components/navigation-drawer.md +429 -0
  186. package/skills/web-guidance/references/ui-components/persistent-toast-notifications.md +185 -0
  187. package/skills/web-guidance/references/ui-components/progress.md +181 -0
  188. package/skills/web-guidance/references/ui-components/spinner.md +179 -0
  189. package/skills/web-guidance/references/ui-components/tabs.md +371 -0
  190. package/skills/web-guidance/references/ui-components/toolbar.md +277 -0
  191. package/skills/web-guidance/references/user-experience/form-factor-adaptation.md +120 -0
  192. package/skills/web-guidance/references/user-experience/natural-interactions.md +155 -0
  193. package/skills/web-guidance/references/visual-design/color.md +43 -0
  194. package/skills/web-guidance/references/visual-design/dark-mode.md +350 -0
  195. package/dist/web/assets/AgentWork-DwAI0_Of.js +0 -2
  196. package/dist/web/assets/ApiTests-C0vFSHmM.js +0 -10
  197. package/dist/web/assets/Browse-5jfdtRc5.js +0 -2
  198. package/dist/web/assets/Chat-B3uhI94O.js +0 -3
  199. package/dist/web/assets/CommandPalette-D2J4nf5y.js +0 -1
  200. package/dist/web/assets/Compare-CN75w1p9.js +0 -1
  201. package/dist/web/assets/Cost-QoxyjR95.js +0 -1
  202. package/dist/web/assets/Data-BAvkcBVt.js +0 -6
  203. package/dist/web/assets/Desktop-BXdOIalN.js +0 -1
  204. package/dist/web/assets/DesktopReview-Bl2SrPP0.js +0 -1
  205. package/dist/web/assets/Evidence-BJ_I52CD.js +0 -1
  206. package/dist/web/assets/Explore-D9AuyTip.js +0 -2
  207. package/dist/web/assets/Features-CusGMDR9.js +0 -1
  208. package/dist/web/assets/Flags-CycGFuUP.js +0 -2
  209. package/dist/web/assets/Flaky-BcSzJogN.js +0 -1
  210. package/dist/web/assets/Impact-CJHnyZ21.js +0 -3
  211. package/dist/web/assets/Jobs-4xcFzEFo.js +0 -5
  212. package/dist/web/assets/KindPage-BielEIej.js +0 -6
  213. package/dist/web/assets/Migration-NwanKpJg.js +0 -2
  214. package/dist/web/assets/PageAgent-CNw4NXva.js +0 -1
  215. package/dist/web/assets/Product-DS3LJZ4P.js +0 -7
  216. package/dist/web/assets/Production-D3zsyNIS.js +0 -1
  217. package/dist/web/assets/Quality-Ctj2YpC4.js +0 -1
  218. package/dist/web/assets/Readiness-DGcRr_co.js +0 -1
  219. package/dist/web/assets/Record-Cc-wGe_Y.js +0 -1
  220. package/dist/web/assets/Regression-DcsbrRa1.js +0 -5
  221. package/dist/web/assets/Reports-BkCn0-Sf.js +0 -2
  222. package/dist/web/assets/Response-BP0UwQcW.js +0 -9
  223. package/dist/web/assets/Responsive-C8U7dumd.js +0 -3
  224. package/dist/web/assets/RunDiff-BhABuhF_.js +0 -1
  225. package/dist/web/assets/Runs-OwdWEYBv.js +0 -2
  226. package/dist/web/assets/Steps-BvzbQyoD.js +0 -2
  227. package/dist/web/assets/TestCases-CLq_6JA5.js +0 -1
  228. package/dist/web/assets/TestData-B0oKAhp6.js +0 -2
  229. package/dist/web/assets/TestDebt-8NLQ5YV_.js +0 -1
  230. package/dist/web/assets/TestManagement-2LYQ7vsN.js +0 -1
  231. package/dist/web/assets/Tosca-DfvMpPTG.js +0 -3
  232. package/dist/web/assets/WhatsNew-BGFNGwqN.js +0 -1
  233. package/dist/web/assets/families-DYlN5v0i.js +0 -1
  234. package/dist/web/assets/filters-faaSnoIq.js +0 -1
  235. package/dist/web/assets/fold-CUjwWAK3.js +0 -1
  236. package/dist/web/assets/frame-BLPdAXUq.js +0 -13
  237. package/dist/web/assets/head-CsTxBsO0.js +0 -1
  238. package/dist/web/assets/index-CxiCvGZq.js +0 -78
  239. package/dist/web/assets/index-dOIsrzhD.css +0 -2
  240. package/dist/web/assets/line-icons-CwZWt93L.js +0 -1
  241. package/dist/web/assets/logos-dGuc1jIM.js +0 -1
  242. package/dist/web/assets/markdown-BI3F-SJ1.js +0 -10
  243. package/dist/web/assets/paletteCommands-QJiCuUEr.js +0 -1
  244. package/dist/web/assets/parts-CdF1f7yS.js +0 -1
  245. package/dist/web/assets/productParts-hNLD9fN0.js +0 -1
  246. package/dist/web/assets/qualityParts-CT25lBWU.js +0 -1
  247. package/dist/web/assets/recordTest-P792aBUt.js +0 -1
@@ -0,0 +1,39 @@
1
+ # Passkeys Orientation
2
+
3
+ This guide provides high-density, action-oriented orientation for implementing secure, framework-agnostic passkey authentication and credential management in modern web applications.
4
+
5
+ ## 1. Core Prerequisites for Passkeys
6
+
7
+ Passkeys rely on the Web Authentication API (WebAuthn), which imposes strict cross-cutting security constraints that must be satisfied before any implementation attempt:
8
+ * **Secure Contexts**: WebAuthn methods (`navigator.credentials.create` and `navigator.credentials.get`) are strictly gated behind Secure Contexts. Applications MUST run on `https://` in production, or `http://localhost` for local development.
9
+ * **Relying Party (RP) ID**: Every credential is tied to an RP ID (essentially the domain name of the application). The RP ID passed in the server-side options MUST match or be a valid registrable domain suffix of the current origin's domain name (e.g., `example.com` is valid for `login.example.com`), or be authorized via Related Origin Requests (`/.well-known/webauthn`). Mismatches result in `SecurityError` exceptions on the client side. **DO NOT** derive `rpId` from `window.location.hostname` on the client (for example, when calling WebAuthn Signal API methods), because `window.location.hostname` will not match a parent-domain or related-origin RP ID configured on the server; always read `rpId` from the server-provided WebAuthn options (`publicKey.rp.id` or `publicKey.rpId`) or backend API responses.
10
+
11
+ ## 2. The AAGUID UX Caveat
12
+
13
+ The Authenticator Attestation Globally Unique Identifier (AAGUID) is a 128-bit identifier returned in the registration attestation data that represents the model/provider of the authenticator (e.g., Google Password Manager, iCloud Keychain, 1Password).
14
+ * **UX Hinting Only**: Relying Parties MUST use the AAGUID exclusively for UX hints (such as rendering the passkey provider name and icon in a management list to help the user).
15
+ * **No Security Dependencies**: applications MUST NOT use AAGUID for cryptographic security or access decisions. Platform passkeys do not currently provide cryptographic attestation for their AAGUIDs, meaning it can be altered or simulated by user agents.
16
+
17
+ ## 3. Decoupled Library Recommendations
18
+
19
+ For backend FIDO2/WebAuthn options generation and signature verification, developers MUST rely on vetted open source libraries per language instead of hand-rolling cryptography:
20
+ * **JavaScript/TypeScript**: SimpleWebAuthn (github.com/MasterKale/SimpleWebAuthn)
21
+ * **Python**: py_webauthn (github.com/duo-labs/py_webauthn)
22
+ * **Java**: Java WebAuthn Server (github.com/Yubico/java-webauthn-server), WebAuthn4J (github.com/webauthn4j/webauthn4j)
23
+ * **.NET**: .NET library for FIDO2 (github.com/abergs/fido2-net-lib)
24
+ * **Go**: WebAuthn Go Library (github.com/go-webauthn/webauthn)
25
+ * **Ruby**: WebAuthn Ruby (github.com/cedarcode/webauthn-ruby)
26
+ * **PHP**: WebAuthn Framework (github.com/web-auth/webauthn-framework)
27
+
28
+ ## 4. Use Case Reference Matrix
29
+
30
+ Identify the matching use case below and retrieve its full implementation guide. Every use case has critical APIs (`PublicKeyCredential.parseCreationOptionsFromJSON`, `parseRequestOptionsFromJSON`, `signalAllAcceptedCredentials`, `signalCurrentUserDetails`, `signalUnknownCredential`, conditional mediation, AAGUID handling, etc.) that are documented only in the per-use-case guide. Do NOT skip this retrieval step, and do NOT substitute third-party library wrappers (such as SimpleWebAuthn's `startAuthentication`/`startRegistration`) on the client — call the native WebAuthn browser APIs directly. Library recommendations in Section 3 apply to the **server-side** (backend FIDO2 verification) only.
31
+
32
+ Specific passkey and WebAuthn implementation details are mapped to the following guides:
33
+ * **Passkey Registration**: `passkey-registration` (references/security/passkey-registration.md) — Offering new passkey registration and promotions.
34
+ * **Passkey Conditional Create**: `passkey-conditional-create` — Silently registering passkeys immediately after successful password login.
35
+ * **Passkey Authentication**: `passkey-authentication` (references/security/passkey-authentication.md) — Discoverable-autofill and button sign-ins.
36
+ * **Quick Sign-Ins**: `quick-sign-ins` — Contextual in-place sign-ins with local passkeys and saved passwords before page navigation.
37
+ * **Passkey Management**: `passkey-management` (references/security/passkey-management.md) — Syncing lists, renames, and deletions with password managers.
38
+ * **Passkey Reauthentication**: `passkey-reauthentication` (references/security/passkey-reauthentication.md) — Re-verifying returning signed-in users for sensitive steps.
39
+
@@ -0,0 +1,105 @@
1
+ # Sanitizing Untrusted HTML
2
+
3
+ Safely displaying user-generated HTML is a common security challenge. The native **Sanitizer API** provides a built-in, browser-optimized way to strip dangerous content (like `<script>` tags or `on*` attributes) before it reaches the DOM.
4
+
5
+ Client-side sanitization protects the page that renders the content. If the same user-generated content is also rendered elsewhere (other clients, server-rendered pages, or emails), sanitize it on the server as well as defence in depth, and make sure the server and client sanitization rules do not conflict.
6
+
7
+ ## 1. Safely Inserting HTML with `setHTML()`
8
+
9
+ The primary way to use the Sanitizer API is through the `setHTML()` method on any `Element`. This method handles parsing, sanitization and insertion in a single step, ensuring that content is sanitized specifically for the context in which it will be inserted.
10
+
11
+ ```javascript
12
+ const untrustedHTML = `
13
+ <p>Hello!</p>
14
+ <script>alert('XSS')</script>
15
+ <img src="x" onerror="alert('XSS')">
16
+ <div onclick="doBadThing()">Click me</div>
17
+ `;
18
+
19
+ const container = document.getElementById('output');
20
+
21
+ // Sanitize and insert in one call
22
+ // The default sanitizer removes scripts and event handlers, plus other
23
+ // elements and attributes outside its built-in allowlist (such as style)
24
+ container.setHTML(untrustedHTML);
25
+ ```
26
+
27
+ ## 2. Using Custom Sanitizer Configurations
28
+
29
+ You can customize the sanitization rules by creating a `Sanitizer` instance. This allows you to define exactly which elements and attributes are permitted for your specific use case.
30
+
31
+ When using `Element.setHTML()` and `Document.parseHTML()`, the default `Sanitizer` settings remove all XSS-unsafe elements and attributes. You cannot make a more permissive `Sanitizer` that allows those elements, but you can further restrict what is allowed.
32
+
33
+ ```javascript
34
+ // Define a restrictive configuration that only allows the specified elements and attributes.
35
+ const config = {
36
+ elements: ["p", "b", "i", "strong", "em"],
37
+ attributes: ["class"],
38
+ replaceWithChildrenElements: ['div']
39
+ };
40
+
41
+ const mySanitizer = new Sanitizer(config);
42
+
43
+ // Apply custom sanitization
44
+ container.setHTML(untrustedHTML, { sanitizer: mySanitizer });
45
+ ```
46
+
47
+ Elements that are not in `elements` are removed **together with their content**. List wrapper elements whose text you want to keep (such as `div` above) in `replaceWithChildrenElements`, which removes the element but keeps its children.
48
+
49
+ If you need a more permissive `Sanitizer` that allows some XSS-unsafe elements or attributes, you can use a custom Sanitizer with `Element.setHTMLUnsafe()` and `Document.parseHTMLUnsafe()`.
50
+
51
+ ## 3. Parsing User Input with `Document.parseHTML()`
52
+
53
+ If you need to parse untrusted HTML without immediately inserting it into the live DOM, use `Document.parseHTML()`. This method returns a `Document` that has been sanitized according to default or custom rules, so you can inspect or transform the sanitized nodes (for example, to build a preview or extract text) before inserting them.
54
+
55
+ Move the resulting nodes into the page rather than serializing them to a string and re-parsing it with `innerHTML`, which can reintroduce mutation XSS (mXSS).
56
+
57
+ ```javascript
58
+ const rawHTML = '<p>Hello <script>console.log("bad")</script></p>';
59
+
60
+ const doc = Document.parseHTML(rawHTML);
61
+ // doc.body now contains the sanitized nodes: <p>Hello </p>
62
+ preview.replaceChildren(...doc.body.childNodes);
63
+ ```
64
+
65
+ ## Fallbacks & browser support for Sanitizer API
66
+
67
+ Browser support for Sanitizer API: Limited availability.
68
+ Supported by: Chrome 146 (Mar 2026), Edge 146 (Mar 2026), and Firefox 148 (Feb 2026).
69
+ Unsupported in: Safari.
70
+
71
+ If the native Sanitizer API is not available in your target browsers, load a library like **DOMPurify** only when native support is missing, to avoid shipping it to browsers that don't need it. Use `in` checks for feature detection so the check itself works in older browsers.
72
+
73
+ ```javascript
74
+ let domPurifyPromise;
75
+
76
+ function loadDOMPurify() {
77
+ // Code-split with your bundler so DOMPurify is only downloaded when needed
78
+ domPurifyPromise ??= import('dompurify').then((mod) => mod.default ?? mod);
79
+ return domPurifyPromise;
80
+ }
81
+
82
+ export async function safeSetHTML(el, html) {
83
+ const elements = ['p', 'b', 'i', 'strong', 'em'];
84
+ const attributes = ['class'];
85
+
86
+ if ('setHTML' in Element.prototype) {
87
+ // setHTML() accepts a plain configuration object as the sanitizer
88
+ el.setHTML(html, { sanitizer: { elements, attributes } });
89
+ } else {
90
+ const DOMPurify = await loadDOMPurify();
91
+ el.innerHTML = DOMPurify.sanitize(html, {
92
+ ALLOWED_TAGS: [...elements, '#text'],
93
+ ALLOWED_ATTR: attributes,
94
+ // Match the native Sanitizer: strip aria-*/data-* and disallowed element content
95
+ ALLOW_ARIA_ATTR: false,
96
+ ALLOW_DATA_ATTR: false,
97
+ KEEP_CONTENT: false
98
+ });
99
+ }
100
+ }
101
+ ```
102
+
103
+ By default, DOMPurify keeps `aria-*` and `data-*` attributes (even when `ALLOWED_ATTR` is specified) as well as the text content of elements it removes, while the native Sanitizer strips `aria-*` and `data-*` attributes and removes disallowed elements together with their content. Setting `ALLOW_ARIA_ATTR: false`, `ALLOW_DATA_ATTR: false`, `KEEP_CONTENT: false`, and allowing `#text` makes DOMPurify match the native behavior. DOMPurify has no built-in option equivalent to `replaceWithChildrenElements`, so avoid that option in configurations that need a matching fallback.
104
+
105
+ If the page enforces Trusted Types (`require-trusted-types-for 'script'`), assigning a string to `innerHTML` throws. `setHTML()` does not need a Trusted Types policy, but the fallback does: pass `RETURN_TRUSTED_TYPE: true` to `DOMPurify.sanitize()` and allow its `dompurify` policy name in your `trusted-types` CSP directive.
@@ -0,0 +1,202 @@
1
+ # Secure external subresources with Subresource Integrity, CORS, and Referrer Policy
2
+
3
+ When loading scripts, stylesheets, fonts, or images from third-party CDNs or external origins, verify their cryptographic integrity with Subresource Integrity (`integrity` in HTML and `integrity()` in CSS `url()`), configure cross-origin credential handling (`crossorigin` and `cross-origin()`), and restrict outgoing `Referer` headers (`referrerpolicy` and `referrer-policy()`). For document-level Content Security Policy and outbound connection allowlists, see `security` (references/security/security.md) and `restrict-outbound-connections`.
4
+
5
+ ## 1. Generate cryptographic integrity digests for immutable assets
6
+
7
+ Subresource Integrity (SRI) ensures the browser only executes or renders an external asset if its bytes match the cryptographic hash declared by your application.
8
+
9
+ - **Compute digests at build or release time, never from live untrusted responses**: Generate integrity hashes during your build or release step from known-good local asset bytes (or copy the official digest published by the package author) and hardcode them into your HTML, CSS, or JavaScript. Never fetch a third-party URL in the browser at runtime to compute its own `integrity` hash, which trusts whatever bytes the remote server returns and defeats SRI.
10
+ - **Use `sha384-` by default**: Format integrity metadata as `<algorithm>-<base64-digest>` using `sha384-` (recommended default), `sha512-`, or `sha256-`.
11
+ - **Pin external subresources to immutable, versioned URLs**: Always reference third-party assets using immutable, version-pinned or content-addressed URLs (such as `https://cdn.example.com/ui@2.4.0/app.min.js`) rather than mutable floating URLs (`latest/app.min.js`), which expose your site to silent supply-chain changes and break SRI as soon as the remote file updates. If you must load a mutable third-party script that updates in place (such as a vendor analytics tag), omit `integrity` on that URL and restrict it with Content Security Policy (`strict-dynamic` / nonces) or iframe sandboxing instead.
12
+ - **Space-separate multiple digests when an endpoint may serve multiple valid payloads**: All browsers that support SRI implement `sha256-`, `sha384-`, and `sha512-`. If a URL may legitimately return one of several known-good payloads (such as during an A/B test, staged CDN rollout, or content-negotiated build), list multiple digests of the same algorithm separated by whitespace (for example, `integrity="sha384-variantA... sha384-variantB..."`). The browser accepts the response if it matches *any* listed digest of the strongest algorithm present.
13
+ - **Serve cross-origin subresources with CORS headers**: Browsers can only verify the integrity of a cross-origin response when it is CORS-readable (`Access-Control-Allow-Origin: *` for anonymous requests, or the exact requesting origin with `Access-Control-Allow-Credentials: true` for credentialed requests).
14
+
15
+ ```bash
16
+ # Generate a sha384- SRI hash at build time from a known-good local file
17
+ printf "sha384-%s\n" "$(openssl dgst -sha384 -binary app.min.js | openssl base64 -A)"
18
+ ```
19
+
20
+ ```javascript
21
+ // Build-time / tooling helper (Node.js 19+, Deno, Bun) to compute an SRI string from known-good local bytes
22
+ export async function computeIntegrityMetadata(bytes) {
23
+ const rawBytes =
24
+ typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes;
25
+ const digestBuffer = await crypto.subtle.digest('SHA-384', rawBytes);
26
+ const binary = Array.from(new Uint8Array(digestBuffer), (b) =>
27
+ String.fromCharCode(b),
28
+ ).join('');
29
+ return `sha384-${btoa(binary)}`;
30
+ }
31
+ ```
32
+
33
+ ## 2. Secure HTML scripts, stylesheets, and preloads
34
+
35
+ Set a document-level `Referrer-Policy: strict-origin-when-cross-origin` HTTP response header (or include `<meta name="referrer" content="strict-origin-when-cross-origin">` in `<head>`) as a baseline default so any subresource or CSS `url()` that omits a per-request referrer modifier still strips sensitive path and query parameters on cross-origin requests.
36
+
37
+ Then, on external `<script>`, `<link rel="stylesheet">`, `<link rel="preload">`, and `<link rel="modulepreload">` elements, always set `integrity`, `crossorigin`, and `referrerpolicy` together:
38
+
39
+ - **`integrity="sha384-..."`**: Blocks execution or application of the resource if the response bytes do not match the expected digest (for a blocked `<link rel="stylesheet">`, `linkElement.sheet` remains `null` and an `error` event fires).
40
+ - **`crossorigin="anonymous"`** (recommended default for public CDN assets) or **`crossorigin="use-credentials"`**: Required whenever `integrity` is set on a cross-origin resource. Omitting `crossorigin` causes the browser to fetch the resource in `no-cors` mode (producing an opaque response that cannot be hash-verified) and block the resource.
41
+ - **`referrerpolicy="no-referrer"`** (recommended default for third-party CDNs) or **`referrerpolicy="strict-origin-when-cross-origin"`**: Overrides the document referrer policy to prevent leaking any origin or path information in the `Referer` request header to the third-party host.
42
+
43
+ ```html
44
+ <!-- Document-level baseline referrer policy in <head> (or via Referrer-Policy HTTP header) -->
45
+ <meta name="referrer" content="strict-origin-when-cross-origin" />
46
+
47
+ <!-- External stylesheet with SRI, anonymous CORS, and no referrer -->
48
+ <link
49
+ rel="stylesheet"
50
+ href="https://cdn.example.com/ui@2.4.0/styles.css"
51
+ integrity="sha384-bs0EksOYBbU/g0IAHMXbSyH1Mgw83GKn+EZlSI+VE+zVchXmSbLwhVLrPzsOWnc5"
52
+ crossorigin="anonymous"
53
+ referrerpolicy="no-referrer"
54
+ />
55
+
56
+ <!-- External script with SRI, anonymous CORS, and no referrer -->
57
+ <script
58
+ src="https://cdn.example.com/ui@2.4.0/bundle.min.js"
59
+ integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
60
+ crossorigin="anonymous"
61
+ referrerpolicy="no-referrer"
62
+ ></script>
63
+ ```
64
+
65
+ When fetching external subresources programmatically with `fetch()`, pass the matching `integrity`, `mode`, `credentials`, and `referrerPolicy` options (a digest mismatch rejects the promise with `TypeError`):
66
+
67
+ ```javascript
68
+ const response = await fetch('https://cdn.example.com/ui@2.4.0/manifest.json', {
69
+ integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC',
70
+ mode: 'cors',
71
+ credentials: 'omit',
72
+ referrerPolicy: 'no-referrer',
73
+ });
74
+ ```
75
+
76
+ ## 3. Secure CSS images, fonts, and imported stylesheets with `url()` modifiers
77
+
78
+ CSS `url()` request modifiers (`cross-origin()`, `referrer-policy()`, and `integrity()`) control the fetch mode, referrer header, and Subresource Integrity verification of CSS-loaded resources—including `background-image`, `content`, `mask-image`, `border-image-source`, `filter`, `@font-face` `src`, and `@import` rules—directly from CSS:
79
+
80
+ | Modifier function | Argument syntax & allowed values | Purpose |
81
+ |---|---|---|
82
+ | `cross-origin(<ident>)` | **Unquoted keyword**: `anonymous` (recommended default) or `use-credentials` | Fetches the CSS resource using CORS and controls whether credentials are sent. Always include alongside `integrity()` on cross-origin CSS resources. |
83
+ | `referrer-policy(<ident>)` | **Unquoted keyword**: `no-referrer` (recommended default for third-party assets), `strict-origin-when-cross-origin`, `origin`, `same-origin`, `strict-origin`, `origin-when-cross-origin`, `no-referrer-when-downgrade`, or `unsafe-url` | Overrides the document referrer policy for this specific CSS request. |
84
+ | `integrity("<string>")` | **Quoted string**: `"sha384-<base64>"` (or space-separated digests `"sha384-... sha384-..."`) | Verifies the fetched CSS resource against the expected cryptographic digest before rendering or applying it. |
85
+
86
+ Follow these CSS syntax and security rules when authoring `url()` modifiers:
87
+
88
+ - **Quote the URL string inside `url("...")`**: Request modifiers are only valid when the URL inside `url(...)` is a quoted `<string>` (unquoted URLs cannot use modifiers).
89
+ - **Specify each modifier type at most once per `url()`**: You can combine `cross-origin()`, `referrer-policy()`, and `integrity()` in any order inside `url("..." ...)`, but repeating the same modifier type twice (such as two `integrity()` modifiers) is invalid. To supply multiple hashes, space-separate them inside a single `integrity("sha384-... sha384-...")` string.
90
+ - **Always pair cross-origin `integrity()` with `cross-origin(anonymous)`**: While `@font-face` `src` and `mask-image` already fetch in anonymous `cors` mode by default, `background-image`, `content`, `border-image-source`, and `@import` default to `no-cors` mode (producing an opaque response that cannot be hash-verified) and external SVG `filter` defaults to `same-origin` mode (blocking cross-origin URLs outright). Including `cross-origin(anonymous)` (or `cross-origin(use-credentials)`) ensures consistent CORS verification across every CSS property.
91
+ - **Place modifiers inside `url("...")` in `@import` and `@font-face` rules**: Keep `cross-origin()`, `referrer-policy()`, and `integrity()` inside `url("..." ...)`, while keeping font descriptors like `format("woff2")` and `tech(...)` outside `url(...)`.
92
+
93
+ ```css
94
+ @import url(
95
+ "https://cdn.example.com/theme@1.2.0/tokens.css"
96
+ cross-origin(anonymous)
97
+ referrer-policy(no-referrer)
98
+ integrity("sha384-bs0EksOYBbU/g0IAHMXbSyH1Mgw83GKn+EZlSI+VE+zVchXmSbLwhVLrPzsOWnc5")
99
+ );
100
+
101
+ @font-face {
102
+ font-family: "BrandSans";
103
+ src: url(
104
+ "https://cdn.example.com/fonts@1.0.0/brand-sans.woff2"
105
+ cross-origin(anonymous)
106
+ referrer-policy(no-referrer)
107
+ integrity("sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
108
+ ) format("woff2");
109
+ font-display: swap;
110
+ }
111
+
112
+ .verified-graphic {
113
+ background-image: url(
114
+ "https://cdn.example.com/media@1.0.0/badge.svg"
115
+ cross-origin(anonymous)
116
+ referrer-policy(no-referrer)
117
+ integrity("sha384-Iw/0p59dP96nGTzHvf2XIfqcBwBW7RM6JfOij8uZxyg5azfNaOOUW8SQy6H/hU91")
118
+ );
119
+ }
120
+ ```
121
+
122
+ ## Fallback strategies
123
+
124
+ Browser support for cross-origin() for url(): Limited availability.
125
+ Supported by: Chrome 150 (Jun 2026), Edge 150 (Jul 2026), and Safari 26.2 (Dec 2025).
126
+ Unsupported in: Firefox.
127
+
128
+ Browser support for referrer-policy() for url(): Limited availability.
129
+ Supported by: Chrome 150 (Jun 2026), Edge 150 (Jul 2026), and Safari 26.2 (Dec 2025).
130
+ Unsupported in: Firefox.
131
+
132
+ Browser support for integrity() for url(): Limited availability.
133
+ Supported by: Chrome 150 (Jun 2026) and Edge 150 (Jul 2026).
134
+ Unsupported in: Firefox and Safari.
135
+
136
+ If your Baseline target does not yet support CSS `url()` request modifiers (`cross-origin()`, `referrer-policy()`, or `integrity()`), combine document-level policies with cascading CSS declarations so subresources remain functional and protected:
137
+
138
+ 1. **Prefer HTML `<link rel="stylesheet">` over CSS `@import` when cross-browser SRI is required**: Because `subresource-integrity` and `referrer-policy` on `<link rel="stylesheet">` are widely available across all browsers, load external stylesheets with `<link rel="stylesheet" href="..." integrity="sha384-..." crossorigin="anonymous" referrerpolicy="no-referrer">` instead of `@import` whenever integrity verification must be enforced in every browser.
139
+ 2. **Rely on the document-level `Referrer-Policy` header or `<meta name="referrer">` from Step 2**: In browsers that do not support `referrer-policy()` inside CSS `url()`, the document-level `Referrer-Policy: strict-origin-when-cross-origin` header or `<meta name="referrer" content="strict-origin-when-cross-origin">` element automatically strips sensitive path and query parameters on cross-origin CSS requests.
140
+ 3. **Cascade separate CSS declarations for progressive enhancement**: Browsers that do not recognize a modifier inside `url("..." ...)` discard the entire declaration at CSS parse time. Declare a plain `url("...")` first, followed by a `cross-origin()` and `referrer-policy()` declaration (for browsers that support those two modifiers but not `integrity()`), followed by the full declaration including `integrity("sha384-...")`:
141
+ - **Never put an unverified `url()` inside the same comma-separated `@font-face` `src` list**: Writing `src: url("font.woff2" cross-origin(anonymous) integrity("sha384-...")), url("font.woff2");` in a single `src` descriptor bypasses Subresource Integrity at runtime—if a CDN serves a tampered font that fails the `integrity()` check, the browser treats it as a load failure and automatically falls back to the second comma-separated `url("font.woff2")`. Using **separate** `src:` declarations ensures supporting browsers overwrite the unverified declaration at CSS parse time and block tampered fonts at runtime.
142
+
143
+ ```css
144
+ @font-face {
145
+ font-family: "BrandSans";
146
+ /* 1. Parse-time fallback for browsers without url() modifier support */
147
+ src: url("https://cdn.example.com/fonts@1.0.0/brand-sans.woff2") format("woff2");
148
+ /* 2. Parse-time fallback for browsers supporting cross-origin() and referrer-policy() */
149
+ src: url(
150
+ "https://cdn.example.com/fonts@1.0.0/brand-sans.woff2"
151
+ cross-origin(anonymous)
152
+ referrer-policy(no-referrer)
153
+ ) format("woff2");
154
+ /* 3. Full protection in browsers supporting cross-origin(), referrer-policy(), and integrity() */
155
+ src: url(
156
+ "https://cdn.example.com/fonts@1.0.0/brand-sans.woff2"
157
+ cross-origin(anonymous)
158
+ referrer-policy(no-referrer)
159
+ integrity("sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
160
+ ) format("woff2");
161
+ font-display: swap;
162
+ }
163
+
164
+ .verified-graphic {
165
+ background-image: url("https://cdn.example.com/media@1.0.0/badge.svg");
166
+ background-image: url(
167
+ "https://cdn.example.com/media@1.0.0/badge.svg"
168
+ cross-origin(anonymous)
169
+ referrer-policy(no-referrer)
170
+ );
171
+ background-image: url(
172
+ "https://cdn.example.com/media@1.0.0/badge.svg"
173
+ cross-origin(anonymous)
174
+ referrer-policy(no-referrer)
175
+ integrity("sha384-Iw/0p59dP96nGTzHvf2XIfqcBwBW7RM6JfOij8uZxyg5azfNaOOUW8SQy6H/hU91")
176
+ );
177
+ }
178
+ ```
179
+
180
+ 4. **Feature-detect CSS `url()` modifier support in JavaScript with `CSS.supports()`**:
181
+
182
+ ```javascript
183
+ export function getCssUrlModifierSupport() {
184
+ const supportsCrossOriginAndReferrer =
185
+ typeof CSS !== 'undefined' &&
186
+ typeof CSS.supports === 'function' &&
187
+ CSS.supports(
188
+ 'background-image',
189
+ 'url("https://example.com/a.svg" cross-origin(anonymous) referrer-policy(no-referrer))',
190
+ );
191
+
192
+ const supportsUrlIntegrity =
193
+ typeof CSS !== 'undefined' &&
194
+ typeof CSS.supports === 'function' &&
195
+ CSS.supports(
196
+ 'background-image',
197
+ 'url("https://example.com/a.svg" cross-origin(anonymous) referrer-policy(no-referrer) integrity("sha384-Iw/0p59dP96nGTzHvf2XIfqcBwBW7RM6JfOij8uZxyg5azfNaOOUW8SQy6H/hU91"))',
198
+ );
199
+
200
+ return { supportsCrossOriginAndReferrer, supportsUrlIntegrity };
201
+ }
202
+ ```