Title: DomSanitizer should keep style attributes in HTML but sanitize them if needed · Issue #45270 · angular/angular · GitHub
Open Graph Title: DomSanitizer should keep style attributes in HTML but sanitize them if needed · Issue #45270 · angular/angular
X Title: DomSanitizer should keep style attributes in HTML but sanitize them if needed · Issue #45270 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? platform-browser Is this a regression? No Description DOM sanitizer removes style attribute from all elements. Expected behavior DOM santitizer keeps the style attribute on elements,...
Open Graph Description: Which @angular/* package(s) are the source of the bug? platform-browser Is this a regression? No Description DOM sanitizer removes style attribute from all elements. Expected behavior DOM santitize...
X Description: Which @angular/* package(s) are the source of the bug? platform-browser Is this a regression? No Description DOM sanitizer removes style attribute from all elements. Expected behavior DOM santitize...
Opengraph URL: https://github.com/angular/angular/issues/45270
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DomSanitizer should keep style attributes in HTML but sanitize them if needed","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\nplatform-browser\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nDOM sanitizer removes style attribute from all elements.\r\nExpected behavior\r\nDOM santitizer keeps the style attribute on elements, but sanitizes the actual style value if needed, so something innocuous like style=\"text-align: center\" isn't lost.\r\nSo when I use sanitizer.sanitize(SecurityContext.HTML, someHtmlContainedString) I expect to receive html with attributes like id, styles, class if the original string contained them. But if it contaied tags like \u003cscript> \u003ca href=\"javascript:alert('hack')\">\u003c/a> - the javascript / script tags should be sanitized. \r\n\r\nThis issue was mistakely closed in https://github.com/angular/angular/issues/19645 with explanation that the latest version of angular should fix it, but it don't.\r\nSo this one is just a reopen.\r\n\r\n\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\nhttp://plnkr.co/edit/AjJMr2pDz8IxvucnpTbC?p=preview\r\n\r\n### Please provide the exception or error you saw\r\n\r\n```true\r\nI receive incorrect html with sanitized style attr.\r\n```\r\n\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 13.2.5\r\nNode: 16.13.0 \r\nPackage Manager: npm 7.24.2\r\nOS: win32 x64\r\n\r\nAngular: 13.2.5\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1302.5\r\n@angular-devkit/build-angular 13.2.5\r\n@angular-devkit/core 13.2.5\r\n@angular-devkit/schematics 13.2.5\r\n@schematics/angular 13.2.5\r\nrxjs 7.5.4\r\ntypescript 4.5.5\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\nMy guessing is - the fix should be something like adding 'style' str into\r\nconst HTML_ATTRS = tagSet(\r\n 'abbr,accesskey,align,alt,autoplay,axis,bgcolor,border,cellpadding,cellspacing,class,clear,color,cols,colspan,' +\r\n 'compact,controls,coords,datetime,default,dir,download,face,headers,height,hidden,hreflang,hspace,' + 'ismap,itemscope,itemprop,kind,label,lang,language,loop,media,muted,nohref,nowrap,open,preload,rel,rev,role,rows,rowspan,rules,' +\r\n 'scope,scrolling,shape,size,sizes,span,srclang,start,summary,tabindex,target,title,translate,type,usemap,' +\r\n 'valign,value,vspace,width');\r\n or if it's still causes security vulnerability - add separate parse rules to sanitize style attrs.\r\n which is defined in https://github.com/angular/angular/blob/13.2.x/packages/core/src/sanitization/html_sanitizer.ts\r\nIf you might believe this is a correct behavior - please close with an explanation why.\r\nThanks!","author":{"url":"https://github.com/amaestr0","@type":"Person","name":"amaestr0"},"datePublished":"2022-03-04T21:47:53Z","url":"https://github.com/angular/angular/issues/45270"}
| 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:56c8c619-2d53-d85f-6f16-780c77db92e1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6D0:26ECEB:1892256:1F51847:6B012EE1 |
| html-safe-nonce | 39150a6ab73fab057f4de1c14ffd0475fb88f2fa97215874a136d07f9d224107 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkQwOjI2RUNFQjoxODkyMjU2OjFGNTE4NDc6NkIwMTJFRTEiLCJ2aXNpdG9yX2lkIjoiNjE5MjEwMzg2OTExNjM5NTIzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0e6e49e052e31c0497ac378ef638a1df85122c3b560acef07f2d39497e886263 |
| hovercard-subject-tag | issue:1160078225 |
| 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/45270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc084313dce04d1d0173b19d47e9dfe84963be4fdeed7c8c9b63a337ecca21cd/angular/angular/issues/45270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc084313dce04d1d0173b19d47e9dfe84963be4fdeed7c8c9b63a337ecca21cd/angular/angular/issues/45270 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? platform-browser Is this a regression? No Description DOM sanitizer removes style attribute from all elements. Expected behavior DOM santitize... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | amaestr0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width