File tree Expand file tree Collapse file tree
java10-shim/src/main/java/org/owasp/shim
owasp-java-html-sanitizer/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ perl -i.bak \
6969 -pe ' if (m/^ [*] / && !$added) { $_ = qq( * Release $ENV{"NEW_VERSION"}\n$_); $added = 1; }' \
7070 change_log.md
7171
72- $EDITOR change_log.md
72+ $EDITOR change_log.md SECURITY.md
7373
7474# A dry run.
7575mvn -f pom.xml clean source:jar javadoc:jar verify \
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Only the lastest version are supported with updates.
66
77| Version | Supported |
88| ---------- | ------------------ |
9- | 20240325 .1 | :white_check_mark : |
9+ | 20260103 .1 | :white_check_mark : |
1010
1111
1212
Original file line number Diff line number Diff line change 11# Known & public vulnerabilities in this project
22
3+ * [ CVE-2025 -66021] ( https://github.com/OWASP/java-html-sanitizer/security/advisories/GHSA-g9gq-3pfx-2gw2 ) - 25 Nov. 2025 - Recommend upgrade to v20260102.1 or later.
34 * [ CVE-2021 -42575] ( cve202142575.md ) - 18 Oct. 2021 - Recommend upgrade to v20211018.1 or later.
45 * [ CVE-2011 -4457] ( cve20114457.md ) - 17 Nov. 2011 - Recommend upgrade to r88 or later.
Original file line number Diff line number Diff line change @@ -62,6 +62,6 @@ final class ForJava9AndLater extends Java8Shim {
6262 }
6363
6464 @ Override public <T > Set <T > setCopyOf (Collection <? extends T > c ) {
65- return Set . copyOf ( c );
65+ return Collections . unmodifiableSet ( new LinkedHashSet <>( c ) );
6666 }
6767}
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public HtmlElementTables(
109109 LI_TAG = indexForName ("li" );
110110 SELECT_TAG = indexForName ("select" );
111111 OPTION_TAG = indexForName ("option" );
112- OPTGROUP_TAG = indexForName ("opgroup " );
112+ OPTGROUP_TAG = indexForName ("optgroup " );
113113 SCRIPT_TAG = indexForName ("script" );
114114 STYLE_TAG = indexForName ("style" );
115115 TABLE_TAG = indexForName ("table" );
Original file line number Diff line number Diff line change 3333import java .util .HashMap ;
3434import java .util .HashSet ;
3535import java .util .LinkedHashMap ;
36+ import java .util .LinkedHashSet ;
3637import java .util .List ;
3738import java .util .Map ;
3839import java .util .Set ;
@@ -428,7 +429,7 @@ public HtmlPolicyBuilder requireRelNofollowOnLinks() {
428429 public HtmlPolicyBuilder requireRelsOnLinks (String ... linkValues ) {
429430 this .invalidateCompiledState ();
430431 if (this .extraRelsForLinks == null ) {
431- this .extraRelsForLinks = new HashSet <>();
432+ this .extraRelsForLinks = new LinkedHashSet <>();
432433 }
433434 for (String linkValue : linkValues ) {
434435 linkValue = HtmlLexer .canonicalKeywordAttributeValue (linkValue );
@@ -1112,8 +1113,8 @@ static final class JoinRelsOnLinksPolicies
11121113
11131114 public JoinableElementPolicy join (
11141115 Iterable <? extends JoinableElementPolicy > toJoin ) {
1115- Set <String > extra = new HashSet <>();
1116- Set <String > skip = new HashSet <>();
1116+ Set <String > extra = new LinkedHashSet <>();
1117+ Set <String > skip = new LinkedHashSet <>();
11171118 for (JoinableElementPolicy ep : toJoin ) {
11181119 RelsOnLinksPolicy p = (RelsOnLinksPolicy ) ep ;
11191120 extra .addAll (p .extra );
Original file line number Diff line number Diff line change 1+ package org .owasp .html ;
2+
3+ import org .junit .Test ;
4+ import static org .junit .Assert .assertEquals ;
5+
6+ public class OptgroupBugTest {
7+
8+ /**
9+ * Test that optgroup elements inside select are not corrupted with extra select tags.
10+ *
11+ * Before fix: <select><optgroup><select><option></option></select></optgroup></select>
12+ * After fix: <select><optgroup><option></option></optgroup></select>
13+ */
14+ @ Test
15+ public void testOptgroupInsideSelectDoesNotAddExtraSelectTags () {
16+ PolicyFactory factory = new HtmlPolicyBuilder ()
17+ .allowElements ("select" , "optgroup" , "option" )
18+ .allowAttributes ("label" ).globally ()
19+ .toFactory ();
20+
21+ String input = "<select><optgroup label=\" mygroup\" ><option>My option</option></optgroup></select>" ;
22+ String result = factory .sanitize (input );
23+
24+ // The key assertion: no extra select tags should be inserted
25+ assertEquals (input , result );
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -251,6 +251,30 @@ void testLinks() {
251251 s .sanitize ("<a name=\" header\" id=\" header\" >Header text</a>" ));
252252 }
253253
254+ @ Test
255+ void testLinksRelAttributeAdditionsOrder () {
256+ // Issue 336.
257+ PolicyFactory pf = Sanitizers .LINKS .and (
258+ new HtmlPolicyBuilder ()
259+ .allowElements ("a" )
260+ .requireRelsOnLinks ("noopener" , "noreferrer" )
261+ .toFactory ());
262+
263+ assertEquals (
264+ "<a href=\" foo.html\" rel=\" nofollow noopener noreferrer\" >Link text</a>" ,
265+ pf .sanitize ("<a href=\" foo.html\" >Link text</a>" ));
266+
267+ pf = Sanitizers .LINKS .and (
268+ new HtmlPolicyBuilder ()
269+ .allowElements ("a" )
270+ .requireRelsOnLinks ("noreferrer" , "noopener" )
271+ .toFactory ());
272+
273+ assertEquals (
274+ "<a href=\" foo.html\" rel=\" nofollow noreferrer noopener\" >Link text</a>" ,
275+ pf .sanitize ("<a href=\" foo.html\" >Link text</a>" ));
276+ }
277+
254278 @ Test
255279 void testExplicitlyAllowedProtocolsAreCaseInsensitive () {
256280 // Issue 24.
@@ -552,7 +576,7 @@ void testStyleGlobally() {
552576 String want = "<h1 style=\" color:green\" >This is some green text</h1>" ;
553577 assertEquals (want , policyBuilder .sanitize (input ));
554578 }
555-
579+
556580 static int fac (int n ) {
557581 int ifac = 1 ;
558582 for (int i = 1 ; i <= n ; ++i ) {
You can’t perform that action at this time.
0 commit comments