This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Commit 2fab3d4
fix($sanitize): do not trigger CSP alert/report in Firefox and Chrome
If `ngSanitize` is added as a module dependency and a Content-Security-Policy
is set that does not allow inline styles then Firefox and Chrome show the
following message:
> Content Security Policy: The page’s settings observed the loading of a
resource at self (“default-src”). A CSP report is being sent.
This message is caused because AngularJS is creating an inline style tag
to test for a browser bug that we use to decide what sanitization strategy
to use, which causes CSP violation errors if inline CSS is prohibited.
This test is no longer necessary, since the `DOMParser` is now safe to use
and the `style` based check is redundant.
In this fix, we default to using `DOMParser` if it is available and fall back
to `createHTMLDocument()` if needed. This is the approach used by DOMPurify
too.
The related unit tests in `sanitizeSpec.js`, "should not allow JavaScript
execution when creating inert document" and "should not allow JavaScript
hidden in badly formed HTML to get through sanitization (Firefox bug)", are
left untouched to assert that the behavior hasn't changed in those scenarios.
Fixes #16463.1 parent 72fbd48 commit 2fab3d4
1 file changed
+13
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
428 | 427 | | |
429 | 428 | | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
| 429 | + | |
| 430 | + | |
435 | 431 | | |
436 | | - | |
437 | 432 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
| 433 | + | |
| 434 | + | |
450 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
451 | 439 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| 440 | + | |
456 | 441 | | |
457 | | - | |
| 442 | + | |
458 | 443 | | |
459 | | - | |
| 444 | + | |
460 | 445 | | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | 446 | | |
469 | 447 | | |
470 | 448 | | |
| |||
0 commit comments