fix: Set style properties directly in mutation#211
fix: Set style properties directly in mutation#211
Conversation
| export function splitStyleAttributes(styles: string) { | ||
| const splitStyles = styles.split(';'); | ||
| return splitStyles | ||
| .filter((value) => value.split(':').length == 2) |
There was a problem hiding this comment.
Q: Is this safe? Could styles not include colons in other places? Not 100% sure, just want to double check!
There was a problem hiding this comment.
That will probably be an issue sooner or later, you're right
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
|
I have tried several options on injecting these styles (with nonces), like using a shadow dom, an iframe or just a style tag but all of these were still triggering the csp error. The only option that really worked were setting the attributes directly using javascript, which is most likely too brittle and expensive to do. The only other alternative that kinda worked was:
but this alters values (e.g. |
|
Unsure, if this is viable in your case, but some libraries offer a |
|
Was there any updates on this @chargome ? |
|
Hey @sminnee no updates tbh, what I wrote in previous comment is still status quo. I will likely not be able to work on this soon but will re-visit at some point – Open for any ideas and contributions meanwhile! |
|
Yeah, it's tricky, the other approach is to avoid needing the temporary createElement at all.
This is a quick GPT-4o mockup of a parser that handles that case using a regex with lookahead. The regex is a bit of a beast and would need some tests in a real implementation. Outputs Do you think this would reduce the brittleness sufficiently? |
This PR sets style attributes directly instead of rewriting the full
styleattribute. That avoids users running into runtime CSP errors when they have not configuredunsafe-inlinein their CSP.fixes #145
relates to #10481