Skip to content

Escape reflected request parameters in the sample servlets - #1129

Merged
vharseko merged 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/sample-apps-xss
Sep 15, 2026
Merged

vharseko merged 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:fix/sample-apps-xss

Conversation

@vharseko

@vharseko vharseko commented Sep 14, 2026

Copy link
Copy Markdown
Member

The client SDK sample war (ServiceConfigServlet, UserProfileServlet) and the policy evaluation demo servlet (openam-distribution/.../demo/source/.../EvaluatePolicyServlet.java) echoed request parameters - service name, user name, resource - into their HTML response unescaped: a reflected XSS in code people deploy as-is and copy from.

  • Escaped with commons-lang3 StringEscapeUtils.escapeHtml4, the escaper Validate ID-FF forward targets, FilesRepo identity names and SAML1 POST target #1128 uses for the SAML1 POST target. The sample war gains the commons-lang3 dependency (version managed, 3.20.0): the shaded clientsdk jar does not bundle it and ESAPI only pulls in commons-lang 2.6. ESAPI itself is declared in the sample war but has no ESAPI.properties there, so it is not used.
  • The demo imported the long-gone com.iplanet.am.util.XMLUtils and therefore did not compile; the import is gone (both reflected values now go through escapeHtml4). Verified with a manual javac against the openam-core classpath, where commons-lang3 already is (the demo is shipped as source and not built by Maven).
  • openam-example-clientsdk-war compiles. No unit tests: the sample modules have no test infrastructure and the change is mechanical escaping.

CodeQL on this PR

The first revision escaped with XMLUtils.escapeSpecialCharacters (clientsdk jar, no new dependency) and drew the same java/xss findings on the escaped lines (#495, #496, #497): CodeQL follows taint through that method's char-by-char loop, and the only escapers it treats as XSS sanitizers are methods named htmlEscape*. It has no model for escapeHtml4, so taint stops there. 4e7797c switches to escapeHtml4; the three threads are answered inline.

Closes CodeQL java/xss alerts #112, #113, #114, #115.

The client SDK sample war (ServiceConfigServlet, UserProfileServlet) and
the policy evaluation demo servlet echoed request parameters (service name,
user name, resource) into their HTML response unescaped - a reflected XSS
in code people deploy as-is and copy from.

Escape them with XMLUtils.escapeSpecialCharacters. The demo also imported
the long-gone com.iplanet.am.util.XMLUtils, so it did not compile; it now
uses com.sun.identity.shared.xml.XMLUtils.

Closes CodeQL java/xss alerts OpenIdentityPlatform#112, OpenIdentityPlatform#113, OpenIdentityPlatform#114, OpenIdentityPlatform#115
@vharseko vharseko added java Pull requests that update java code security Security fix or hardening (CVE, GHSA, XSS/CSRF/SSRF) labels Sep 14, 2026
out.println("<h3>ServiceName:</h3> " + servicename);
out.println("<br><h3>Username:</h3> " + username);
// Request parameters are reflected into the page: escape them.
out.println("<h3>ServiceName:</h3> " + XMLUtils.escapeSpecialCharacters(servicename));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4e7797c replaces XMLUtils.escapeSpecialCharacters here with commons-lang3 StringEscapeUtils.escapeHtml4, the escaper #1128 uses for the SAML1 POST target. CodeQL follows taint through escapeSpecialCharacters' char-by-char loop (the only escapers it treats as XSS sanitizers are methods named htmlEscape*); it has no model for escapeHtml4, so taint stops there.

out.println("<br><h3>Username:</h3> " + username);
// Request parameters are reflected into the page: escape them.
out.println("<h3>ServiceName:</h3> " + XMLUtils.escapeSpecialCharacters(servicename));
out.println("<br><h3>Username:</h3> " + XMLUtils.escapeSpecialCharacters(username));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4e7797c replaces XMLUtils.escapeSpecialCharacters here with commons-lang3 StringEscapeUtils.escapeHtml4, the escaper #1128 uses for the SAML1 POST target. CodeQL follows taint through escapeSpecialCharacters' char-by-char loop (the only escapers it treats as XSS sanitizers are methods named htmlEscape*); it has no model for escapeHtml4, so taint stops there.


out.println("<br><h3>Username:</h3> " + username);
// The user name is a request parameter reflected into the page: escape it.
out.println("<br><h3>Username:</h3> " + XMLUtils.escapeSpecialCharacters(username));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4e7797c replaces XMLUtils.escapeSpecialCharacters here with commons-lang3 StringEscapeUtils.escapeHtml4, the escaper #1128 uses for the SAML1 POST target. CodeQL follows taint through escapeSpecialCharacters' char-by-char loop (the only escapers it treats as XSS sanitizers are methods named htmlEscape*); it has no model for escapeHtml4, so taint stops there.

CodeQL kept reporting java/xss on the escaped lines: it follows taint
through XMLUtils.escapeSpecialCharacters' char-by-char loop. Use
commons-lang3 StringEscapeUtils.escapeHtml4 instead, as OpenIdentityPlatform#1128 does for
the SAML1 POST target; taint does not flow through it. The clientsdk
sample war gains the commons-lang3 dependency (the shaded clientsdk jar
does not bundle it), the policy demo drops its XMLUtils import.
@vharseko
vharseko requested review from maximthomas and removed request for maximthomas September 15, 2026 10:56
@vharseko vharseko added the dependencies Pull requests that update a dependency file label Sep 15, 2026
@vharseko
vharseko merged commit 8891ce4 into OpenIdentityPlatform:master Sep 15, 2026
13 checks passed
@vharseko
vharseko deleted the fix/sample-apps-xss branch September 15, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file java Pull requests that update java code security Security fix or hardening (CVE, GHSA, XSS/CSRF/SSRF)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants