Skip to content

Bug 66609 - invalid XML in directory listing with file names containing "&" and "'"#621

Closed
alexkachanov wants to merge 5 commits into
apache:mainfrom
alexkachanov:Bug_66609_invalid_XML
Closed

Bug 66609 - invalid XML in directory listing with file names containing "&" and "'"#621
alexkachanov wants to merge 5 commits into
apache:mainfrom
alexkachanov:Bug_66609_invalid_XML

Conversation

@alexkachanov

Copy link
Copy Markdown
Contributor
  • fix and junit test


public static final URLEncoder DEFAULT = new URLEncoder();
public static final URLEncoder QUERY = new URLEncoder();
public static final URLEncoder XML = new URLEncoder();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added new XML encoder that encodes strings that are valid in XML

QUERY.addSafeCharacter('=');
QUERY.addSafeCharacter('&');

XML.addSafeCharacter('/');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"/" is a valid symbol

sb.append(" urlPath='")
.append(rewrittenContextPath)
.append(rewriteUrl(directoryWebappPath + entry))
.append(rewriteUrl(directoryWebappPath + entry, URLEncoder.XML))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

using XML encoder to encode path attribute which may contain "'" and "&" symbols

}

@Test
public void testBug66609() throws Exception {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added test to test the fix

@markt-asf

Copy link
Copy Markdown
Contributor

(Ab)using the URLEncoder for this seems wrong. Tomcat has a class specifically for escaping values in content - org.apache.tomcat.util.security.Escape. The fix should use this.

Further, it appears that there are still multiple implementations of XML escaping in the Tomcat code base. These need to be rationalised to use Escape class.

I agree having a test case for this is an improvement. I'd like to see that test case cover all the XML characters that need to be escaped and also test the WebDAV case as well as the directory listing case.

@alexkachanov

Copy link
Copy Markdown
Contributor Author

I was using URLEncoder class because it was used in original rewriteUrl method. So I wanted to keep it consistent and keep the changes it to minimum. I see that Escape.xml(String content) makes sense here. Let me change the patch

@alexkachanov
alexkachanov marked this pull request as draft May 24, 2023 11:41
sb.append(" urlPath='")
.append(rewrittenContextPath)
.append(rewriteUrl(directoryWebappPath + entry))
.append(Escape.xml(directoryWebappPath + entry))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

using Escape.xml instead of rewriteUrl

@alexkachanov
alexkachanov marked this pull request as ready for review May 24, 2023 12:06
markt-asf added a commit that referenced this pull request May 24, 2023
@markt-asf

Copy link
Copy Markdown
Contributor

Thanks for the PR. Applied manually with a few tweaks (e.g. CheckStyle config).

@markt-asf markt-asf closed this May 24, 2023
markt-asf added a commit that referenced this pull request May 24, 2023
markt-asf added a commit that referenced this pull request May 24, 2023
markt-asf added a commit that referenced this pull request May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants