-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
xmlsec vulnerable to XXE #43
Comments
Actually this is LibXML2 problem: https://bugzilla.gnome.org/show_bug.cgi?id=772726 I've added a patch there and xmlsec will work just fine if this patch is applied. |
Thanks. I will follow up on the bug there. It seams it will be a good chance to have this applied by default and not being optionals. |
Given there's no activity on the libxml ticket, is it time to consider applying the patch proposed there to xmlsec as a workaround? Eyeballing the patch, it looks applicable as an external (only using libxml2's public API). It could be refined further to allow DTD/external references to a restricted path. |
I think it might be a good idea. Libxml bug is still not fixed and there is no indication it will be fixed any time soon. |
Unfortunately I don't see any xmlsec only patches. Could you please point to the comment that you think has it? |
This is an approach that works if the patch from comment 15 is applied. These changes from comment 14 w/o corresponding libxml2 changes are not going to make any difference. This is what this bug is about: even if all the proper flags are set, libxml2 is still loading external entities. |
Here is an attempt to apply the patch from libxml2 as a workaround in xmlsec. It lacks tests, but it doesn't seem to trigger any new failures in the existing test suite. 0001-attempt-XXE-prevention-using-custom-external-entity-.patch.txt |
Per curiosity, does xmlsec really need "Standard" entities (& < etc) are handled by libxml2 with no special directives; replaceEntities (aka XML_PARSE_NOENT) enables internal and external entity expansion. The conservative in me says XML security should avoid this function if at all possible, simply to reduce the potential attack surface .. which would make the above patch redundant. No idea if this is realistic though! |
This patch probably works. This means that apps using xmlsec library can handle this using the same approach. Thus, it is only a problem with xmlsec command line tool. Could you please send a pull request with this patch? I will extend it to control this behavior through command line parameter. Re entity substitution -- this is required by C14N used in XMLDsig (https://www.w3.org/TR/2001/REC-xml-c14n-20010315#XMLCanonicalization). |
#93 created |
I'd suggest making "noxxe" the default behaviour, requiring an switch to enable processing external entities. It would be nice if library clients could get the same protection easily, but the main ones I care about for now are using the xmlsec1 binary. Any chance yet to review? I'm happy to do some more work to add tests and expose a switch to turn this change on/off, if you can provide some guidance .. particularly on structuring new tests :) |
@d-hat I second your proposal. I think we should make this safe by default but allow others to accept and process EE when needed. It is the behavior others are taking regarding this problem. Others libraries downstream that depend on xmlsec and libxml , such as pySAML, are currently implementing their own fixes/filters due to the lack of traction on both libXML and here and directly blocked all external entities. IdentityPython/pysaml2#366 |
Sorry, got busy at day job :) If you have time, then the only thing needed is a command line parameter to control it. I am fine with making it default "off". |
okay, I think the MR branch is now suitable. A couple of comments:
The parameter is Does this look reasonable to you? Anything further needed .. docs? On the way through, I noticed a couple of things perhaps worth noting for later attention:
The options |
Fixed in PR #93 |
The patch doesn't work. The input_id check is not reliable (https://bugzilla.gnome.org/show_bug.cgi?id=772726#c29) and there is a simple test case: $ cat /tmp/a.xml
$ xmlsec1 verify /tmp/a.xml |
Daniel has a patch that should address the issue. Please try the current Libxml2 master and confirm that it is resolved. |
Description
An XML External Entity attack is a type of attack against an application that parses XML input. This attack occurs when XML input containing a reference to an external entity is processed by a weakly configured XML parser. This attack may lead to the disclosure of confidential data, denial of service, server side request forgery, port scanning from the perspective of the machine where the parser is located, and other system impacts.
Whenever xmlsec verifies, encrypt, decrypt an XML document the parse by default reads external entities resulting on an XXE Vulnerability.
Proof of Concept
Running a fake command to test:
Listener:
Note: The same results were found as a result of trying to encrypt or decyrpt content.
Recommendations
It is my recommendation that the xmlsec library by default denies External Entities and local file inclusion and/or provides a command line option that can be used to block them.
For more information refer to:
https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing
https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet
The text was updated successfully, but these errors were encountered: