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

XML serialization does not escape special characters #103

Open
mickdekkers opened this issue Aug 21, 2024 · 2 comments
Open

XML serialization does not escape special characters #103

mickdekkers opened this issue Aug 21, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@mickdekkers
Copy link

Hi @ballsteve, @Devasta, I'm reporting this as an issue on GitHub as discussed.

I noticed that the XML serialization in xrust doesn't seem to be escaping special characters like & and ". This can produce invalid syntax, but could also theoretically lead to XML injection attacks if someone passes malicious input to an application using xrust (e.g. if that application includes a parse -> serialize -> parse sequence somewhere). Practically speaking however, given the limited download count of the package, we believe it very unlikely that any application using xrust is written in such a way as to be vulnerable as a result of this issue, especially without it being noticed during development.

Example main.rs code:

use std::rc::Rc;
use xrust::parser::xml;
use xrust::trees::smite::Node as SmiteNode;
use xrust::Node;

fn main() {
    let input = r"
<doc attr='&apos;'>
    XML escape test: &lt; &gt; &amp; &apos; &quot;
</doc>";

    let doc = xml::parse(Rc::new(SmiteNode::new()), input, None).unwrap();
    println!("{}", doc.to_xml());
}

Outputs:

<doc attr='''>
  XML escape test: < > & ' "
</doc>
@ballsteve ballsteve self-assigned this Aug 21, 2024
@ballsteve ballsteve added the bug Something isn't working label Aug 21, 2024
@ballsteve
Copy link
Owner

Thanks for the bug report, Mick. I'll take a look at this ASAP.

Maybe once bugs like this are fixed the download count will become more respectable ;-)

@Devasta
Copy link
Collaborator

Devasta commented Aug 22, 2024

So the current escaping is down by the transformation step, to allow us support disable-output-escaping, so we need to move that to the serialiser, but also support that.

The XSLT spec suggests the way to go about this is expand the data model with a Boolean to flag of the output is to be escaped or not, we can look into that approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants