@@ -454,9 +454,24 @@ public static final void testStylingCornerCase() {
454454 assertEquals (want , sanitize (input ));
455455 }
456456
457+ /**
458+ * These 5 tests cover regression scenarios for CVE-2025-66021, which relates to
459+ * improper sanitization of HTML content involving <style> and <noscript> tags.
460+ * The tests ensure that HTMLSanitizer:
461+ * - properly closes any opened elements,
462+ * - only allows allowed elements inside <style> blocks,
463+ * - prevents injection of forbidden HTML or scripts within style or noscript,
464+ * - does not allow unexpected element escape or context breaking.
465+ */
466+
467+ /**
468+ * Test #1:
469+ * Verify that unallowed elements (<div>) injected inside <style> are removed,
470+ * and only allowed content (CSS and allowed elements) remain.
471+ */
457472 @ Test
458473 public static final void testCVE202566021_1 () {
459- // Arrange
474+ // Arrange: Attempt to inject a <div> inside <style>. Only 'style' and 'noscript' are allowed.
460475 String actualPayload = "<noscript><style>/* user content */.x { font-size: 12px; }<div id=\" evil\" >XSS?</div></style></noscript>" ;
461476 String expectedPayload = "<noscript><style>/* user content */.x { font-size: 12px; }</style></noscript>" ;
462477
@@ -473,9 +488,14 @@ public static final void testCVE202566021_1() {
473488 assertEquals (expectedPayload , sanitized );
474489 }
475490
491+ /**
492+ * Test #2:
493+ * Ensure that <script> tags (attempting script injection) are stripped out
494+ * even when they appear inside allowed <style> tags.
495+ */
476496 @ Test
477497 public static final void testCVE202566021_2 () {
478- // Arrange
498+ // Arrange: Attempt to inject a <script> inside <style>. Only 'style' and 'noscript' are allowed.
479499 String actualPayload = "<noscript><style>/* user content */.x { font-size: 12px; }<script>alert('XSS Attack!')</script></style></noscript>" ;
480500 String expectedPayload = "<noscript><style>/* user content */.x { font-size: 12px; }</style></noscript>" ;
481501
@@ -492,9 +512,14 @@ public static final void testCVE202566021_2() {
492512 assertEquals (expectedPayload , sanitized );
493513 }
494514
515+ /**
516+ * Test #3:
517+ * Ensure that, if <div> is allowed, then <div> injected inside <style>
518+ * is retained by the sanitizer (since it is now in the policy).
519+ */
495520 @ Test
496521 public static final void testCVE202566021_3 () {
497- // Arrange
522+ // Arrange: <div> is now allowed, so it should survive sanitization inside <style>.
498523 String actualPayload = "<noscript><style>/* user content */.x { font-size: 12px; }<div id=\" good\" >ALLOWED?</div></style></noscript>" ;
499524 String expectedPayload = "<noscript><style>/* user content */.x { font-size: 12px; }<div id=\" good\" >ALLOWED?</div></style></noscript>" ;
500525
@@ -511,9 +536,14 @@ public static final void testCVE202566021_3() {
511536 assertEquals (expectedPayload , sanitized );
512537 }
513538
539+ /**
540+ * Test #4:
541+ * Confirm that an attempt to prematurely close <style> with </noscript>, then inject a script,
542+ * does not allow the injected script. Sanitizer closes elements properly and only emits allowed tags.
543+ */
514544 @ Test
515545 public static final void testCVE202566021_4 () {
516- // Arrange
546+ // Arrange: Try to break out of <style> and <noscript>, then add a script. Only style/noscript/p allowed.
517547 String actualPayload = "<noscript><style></noscript><script>alert(1)</script>" ;
518548 String expectedPayload = "<noscript><style></noscript></style></noscript>" ;
519549
@@ -530,9 +560,14 @@ public static final void testCVE202566021_4() {
530560 assertEquals (expectedPayload , sanitized );
531561 }
532562
563+ /**
564+ * Test #5:
565+ * Like Test #4, but with <p> instead of <noscript>. Ensures sanitizer emits correctly closed tags
566+ * and strips the injected script tag completely.
567+ */
533568 @ Test
534569 public static final void testCVE202566021_5 () {
535- // Arrange
570+ // Arrange: Try to break out of <style> through <p>, then add a script. Only style/noscript/p allowed.
536571 String actualPayload = "<p><style></p><script>alert(1)</script>" ;
537572 String expectedPayload = "<p><style></p></style></p>" ;
538573
0 commit comments