Title: Extensible Sanitizer · Issue #36650 · angular/angular · GitHub
Open Graph Title: Extensible Sanitizer · Issue #36650 · angular/angular
X Title: Extensible Sanitizer · Issue #36650 · angular/angular
Description: 🚀 feature request Relevant Package @angular/core this line and file are of key interest: angular/packages/core/src/sanitization/html_sanitizer.ts Line 95 in 486cade export const VALID_ATTRS = merge(URI_ATTRS, SRCSET_ATTRS, HTML_ATTRS, AR...
Open Graph Description: 🚀 feature request Relevant Package @angular/core this line and file are of key interest: angular/packages/core/src/sanitization/html_sanitizer.ts Line 95 in 486cade export const VALID_ATTRS = merge...
X Description: 🚀 feature request Relevant Package @angular/core this line and file are of key interest: angular/packages/core/src/sanitization/html_sanitizer.ts Line 95 in 486cade export const VALID_ATTRS = merge...
Opengraph URL: https://github.com/angular/angular/issues/36650
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Extensible Sanitizer","articleBody":"# 🚀 feature request\r\n\r\n### Relevant Package\r\n@angular/core\r\n\r\nthis line and file are of key interest:\r\nhttps://github.com/angular/angular/blob/486cade596a57b7c146ae3aa269d69d7d828a6ab/packages/core/src/sanitization/html_sanitizer.ts#L95\r\n\r\n\r\n### Description\r\nThe ability to trust a custom whitelist of HTML tags, attributes, and values with a DOM sanitizer, without bypassing the whole sanitizer.\r\n\r\nThis would allow preservation of `id`, `style`, data attributes, and other common attributes. These attributes are useful in a variety of use cases for many Angular developers. This issue is a common cause of many GitHub issues, StackOverflow questions, and other indicators that there is a real problem with demand for a secure and flexible solution.\r\n\r\n[Related SO 1](https://stackoverflow.com/questions/57400432/angular-how-to-retain-html-id-attribute-when-sanitized)\r\n[Related SO 2](https://stackoverflow.com/questions/39628007/angular2-innerhtml-binding-remove-style-attribute)\r\n[Tutorial on a best practice approach to doing what I am requesting](https://www.intricatecloud.io/2019/10/using-angular-innerhtml-to-display-user-generated-content-without-sacrificing-security/)\r\nthis would close a bunch of github issues and resolve many SO questions.\r\n\r\n### Describe the solution you'd like\r\nI would like to be able to specify three things to allow keys and values to be sanitized in a SecurityContext.HTML.\r\n\r\nThis could be implemented as an options argument to DomSanitizer.sanitize, or it could be implemented as a custom SecurityContext, but I will use options object in my description below:\r\n\r\n```\r\n trustedFirstParagraph$ = this.translateService\r\n .translate('some-translation-key')\r\n .pipe(map(s => this.domSanitizer.sanitize(SecurityContext.HTML, s, options)));\r\n```\r\n\r\nHere, options can be an object with any of three keys:\r\n```\r\nconst options = {\r\n trustAttributeKeyExpression: /some-regex-to-trust/,\r\n trustAttributeValueExpression: /some-value-to-trust/,\r\n trustAttribute: (el, key, value): boolean | string[] => {\r\n // arbitrary logic that can return a boolean\r\n // or [string, string] sanitized/transformed [key, value].\r\n }\r\n}\r\n```\r\n\r\n`trustAttributeKeyExpression` and `trustAttributeValueExpression` must both match if both are specified. To implement an OR operation, and other more complex algorithms, a developer can use `trustAttribute`.\r\n\r\n### Describe alternatives you've considered\r\n1. hiding data inside the class attribute and parsing it\r\n2. using a span or div inside my element which is visually hidden but which I can access through my component dom ref and parse out the value\r\n3. de-DRYing my code and having component-specific content across n components instead of being able to leverage a generic service","author":{"url":"https://github.com/Vandivier","@type":"Person","name":"Vandivier"},"datePublished":"2020-04-15T22:58:16Z","url":"https://github.com/angular/angular/issues/36650"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:029b8647-93c3-ff35-3acf-7945dfbdf2fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 917E:A99C2:1186A76:1675AE2:6B010790 |
| html-safe-nonce | 7edb4568bace3cd1c746f66202c5dcfa407f16312610eddf5eed6c401cf3148a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTdFOkE5OUMyOjExODZBNzY6MTY3NUFFMjo2QjAxMDc5MCIsInZpc2l0b3JfaWQiOiI0MzQ0Mzk0NTI4NzYxOTA3MDg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e9d4d4a3f0d9da5ce03240e08309f1484eb06a3a84f55da4c0ea5599949fa77f |
| hovercard-subject-tag | issue:600636742 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/angular/angular/36650/issue_layout |
| twitter:image | https://opengraph.githubassets.com/30d8f44f7a88267324bf0707fd95eaea760e6adba9781d073e9053620ed7b96a/angular/angular/issues/36650 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/30d8f44f7a88267324bf0707fd95eaea760e6adba9781d073e9053620ed7b96a/angular/angular/issues/36650 |
| og:image:alt | 🚀 feature request Relevant Package @angular/core this line and file are of key interest: angular/packages/core/src/sanitization/html_sanitizer.ts Line 95 in 486cade export const VALID_ATTRS = merge... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Vandivier |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width