Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace URI is not encoded #107

Open
Marcono1234 opened this issue Sep 3, 2020 · 2 comments
Open

Namespace URI is not encoded #107

Marcono1234 opened this issue Sep 3, 2020 · 2 comments
Assignees
Labels

Comments

@Marcono1234
Copy link

Related to #48

It appears the URI argument for org.dom4j.Namespace is not encoded but is written as is to the XML string. This can cause malformed XML and might even allow XML injection.

Element root = DocumentHelper.createElement("root");
root.addElement("name", "http://example.com/namespace\"><test>");
// <root><name xmlns="http://example.com/namespace"><test>"/></root>
System.out.println(root.asXML());

This is also problematic because the Namespace URI is decoded when read from XML. So reading valid XML with a URI containing encoded characters can lead to malformed XML when the same document is written again.

@FilipJirsak FilipJirsak self-assigned this Sep 21, 2020
@ecki
Copy link

ecki commented Nov 13, 2020

Is it better to url encode or xml encode those attributes? (I would think xml encoding or rejecting those values is better than messing with url escaping/normalization.

@Marcono1234
Copy link
Author

Marcono1234 commented Nov 14, 2020

The right approach might be to XML encode them since the W3C Recommendation for Namespaces in XML §2.3 says:

[Definition: The two URIs are treated as strings, and they are identical if and only if the strings are identical, that is, if they are the same sequence of characters. ] The comparison is case-sensitive, and no %-escaping is done or undone.

So (to my understanding) performing URL encoding could change the meaning and should therefore not be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants