Title: fix(security): wire Trusted Types into the framework's HTML sinks by JosunLP · Pull Request #191 · bQuery/bQuery · GitHub
Open Graph Title: fix(security): wire Trusted Types into the framework's HTML sinks by JosunLP · Pull Request #191 · bQuery/bQuery
X Title: fix(security): wire Trusted Types into the framework's HTML sinks by JosunLP · Pull Request #191 · bQuery/bQuery
Description: Summary Fixes #171 (Medium). createTrustedHtml / getTrustedTypesPolicy existed but no DOM-write path called them — they were only re-exported. So under an enforced require-trusted-types-for 'script' CSP, every innerHTML =/insertAdjacentHTML in dom.ts/collection.ts/element.ts/directives threw (framework fails closed but non-functional), and the documented "Trusted Types / CSP compliance" property was simply absent. Fix New trustedHtmlForSink(rawHtml) in security/trusted-types.ts: returns a TrustedHTML when a policy is active (so the write satisfies enforced TT), otherwise the sanitized string — sanitizing exactly once. All sanitized sinks now route through it: core/dom.ts: setHtml, createElementFromHtml, insertContent core/collection.ts: Collection.html(), insertAll() view/directives: bq-html (sanitized branch), bq-html-safe element.ts html() inherits it via setHtml The explicit htmlUnsafe() / sanitize: false escape hatches are deliberately left as raw writes (bypassing sanitization is their documented purpose). The sanitizeHtml JSDoc is corrected to describe actual behavior (returns a branded string; the framework's sinks wrap it for TT). Verification New test proves the positive path: with a mock TT policy installed (fresh module instance to avoid cached-policy leakage), trustedHtmlForSink invokes policy.createHTML and returns the branded TrustedHTML. New test for the fallback path: returns a sanitized, sink-safe string in a non-TT environment. Existing sink sanitization tests still pass (behavior unchanged without TT). Full suite: 2988 pass / 0 fail. tsc --noEmit + eslint clean. 🤖 Generated with Claude Code
Open Graph Description: Summary Fixes #171 (Medium). createTrustedHtml / getTrustedTypesPolicy existed but no DOM-write path called them — they were only re-exported. So under an enforced require-trusted-types-for 'sc...
X Description: Summary Fixes #171 (Medium). createTrustedHtml / getTrustedTypesPolicy existed but no DOM-write path called them — they were only re-exported. So under an enforced require-trusted-types-for ...
Opengraph URL: https://github.com/bQuery/bQuery/pull/191
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d40807c8-96ad-536e-506f-2df8c8d53d4f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8A78:E21C4:3ACCB85:52B5C02:6A4F992E |
| html-safe-nonce | 9d8c4e3164064ff51b0796d6363be325361cd5bc044f857240704eb3c3a4786c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTc4OkUyMUM0OjNBQ0NCODU6NTJCNUMwMjo2QTRGOTkyRSIsInZpc2l0b3JfaWQiOiIxNjUyNTkyNzk0OTc5MjY5NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1dd67c13f57755ff98aa0822ea1c3eb1187112469868c60924f9d5413fb349db |
| hovercard-subject-tag | pull_request:4001082747 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/bQuery/bQuery/pull/191/files |
| twitter:image | https://avatars.githubusercontent.com/u/20913954?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/20913954?s=400&v=4 |
| og:image:alt | Summary Fixes #171 (Medium). createTrustedHtml / getTrustedTypesPolicy existed but no DOM-write path called them — they were only re-exported. So under an enforced require-trusted-types-for 'sc... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/bQuery/bQuery git https://github.com/bQuery/bQuery.git |
| octolytics-dimension-user_id | 256381806 |
| octolytics-dimension-user_login | bQuery |
| octolytics-dimension-repository_id | 1139284244 |
| octolytics-dimension-repository_nwo | bQuery/bQuery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1139284244 |
| octolytics-dimension-repository_network_root_nwo | bQuery/bQuery |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width