question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve XML External Entity (XXE) detection

See original GitHub issue

Motivation

I could be wrong but as far as I can tell, the XML External Entity (XXE) protection offered by CRS is fairly poor. There have been multiple attempts in the past to address these shortcomings but they have not succeeded and there are currently no ongoing efforts to improve the situation.

These are the issues and pull requests that have been created in the past:

From the discussions in the tickets and pull requests above, the problem appears to be that there is a shortcoming of ModSecurtiy which causes the targeted collections (REQUEST_BODY and FULL_REQUEST) to be empty if a body parser has been activated. This, of course, would be the case in most situation where XXE detection is desired, braking the proposed rules.

However, since the information related to XXEs is contained in <!DOCTYPE ...> tags, which are not accessible through the XML collection using XPath expressions, is not possible to write reliable ModSecurity rules to detect XXEs for these requests.

This issue is known but considering the following discussion, it is unlikely to be fixed in ModSecurity any time soon: https://github.com/SpiderLabs/ModSecurity/issues/2087.

There have been comments that a plugin leveraging ModSecurity’s Lua capabilities might help but as far as I can tell, this was never implemented: https://github.com/coreruleset/coreruleset/pull/2163#issuecomment-997432471.

Proposed solution

Implement a plugin similar to the antivirus plugin which can reliably detect XXEs in requests independently of whether or not a body parser has been activated.

Alternatives

A cleaner approach might be to create a pull request to ModSecurity to provide additional information about the payload like the DOCTYPE through either the existing XML collection or through a new collection. This would allow for regular rules to be written in order to detect XXEs. However, this would require a change to ModSecurity, which is outside the control of the Core Rule Set Project.

Additional context

There is a ModSecurity directive related to XXEs: SecXmlExternalEntity. This directive is turned off by default. From what I understand, this directive only configures whether ModSec expands External Entities in XML or not. It does not configure whether XXEs are allowed in general or not. XML containing XXEs are not blocked, even if SecXmlExternalEntity is turned off.

There are rules that might detect XXEs in certain circumstances, however, this is mostly incidental as they do not explicitly check for XXEs.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:57 (57 by maintainers)

github_iconTop GitHub Comments

1reaction
azuritcommented, Jun 23, 2022

I’m able to maintain both versions.

1reaction
studersicommented, Apr 22, 2022

Simple XPath expressions like the ones used in CRS for the XML collection could be implemented using Regexes as far as I can tell as long as the elements and their attributes are available in the TX collection. An example for this was given by @azurit.

This would not necessarily have been the case if CRS made use of more complex XPath expression.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XML External Entity Prevention Cheat Sheet
The safest way to prevent XXE is always to disable DTDs (External Entities) completely. Depending on the parser, the method should be similar...
Read more >
How to find and mitigate XML External Entity (XXE) Injection
In this article, we will explain XML External Entity (XXE) Injection, When will XXE vulnerability arise, the most common scenarios to test ...
Read more >
What Is XXE Processing Vulnerability and How to Fix It?
What are XXE Attacks? What are XML External Entities? What Are the Risk Factors for XXE Attacks; Type of XXE Attacks; How to...
Read more >
XML External Entity (XXE) Attacks and How to Avoid Them
XXE injection attacks exploit support for XML external entities and are used against web applications that process XML inputs.
Read more >
Prevention of XML External Entity (XXE) attacks
Libraries vulnerable to XML External Entity attacks ... Many teams are not aware that their own applications include XML processing features ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found