It's been a few years since I mucked around with modsecurity...

Will simply installing the package with the default rules provide enough validation to prevent any (okay, let's be honest - best we can hope for is "most") type of XSS? My assumption is no... and even if we consider only Type I - Reflected XSS.

What about the Core Rule Set? Is that XSS-proof enough?
If not, what kind of rules are missing, and what should I look to add/customize, maybe on a per-page basis? (uggh...)

Last part of the question, what about AJAX-heavy apps? How does ModSecurity, and in particular the CRS, handle AJAX requests without blocking them? I assume that hoping that it actually manages to parse out the AJAX and validate each parameter seperately would be too much to hope for...

To clarify, fixing the code to remove all XSS, including input validation and especially contextual output encoding, is of course the best way to go, and really the only long-term solution.
However, I was looking for a temporary, "quick fix", to pop something in place to protect the app for now, while they go and fix the XSS in the code, and search for more...

4 Answers 4


You should review the XSS Street-Fight (with ModSecurity) Blackhat preso

It outlines the following ModSecurity mitigation strategies for XSS:

  1. Input Validation (Whitelist/Blacklist Filtering)
  2. Generic Attack Payload Detection
  3. Identifying Improper Output Handling Flaws (Dynamic Taint Propagation)
  4. Application Response Profiling (Monitoring the number of scripts/iFrames)
  5. JavaScript Sandbox Injection (ModSecurity’s Content Injection Capabilities)
  • oo, I got the big man himself! :) Now that Ofer and Or are not involved, I didn't know who to turn to... So, bottom line, ModSecurity+CRS does the job, in generic cases?
    – AviD
    Commented Apr 11, 2011 at 5:48
  • Well, ModSecurity can help to introduce many layers to help identify both XSS attacks and locations that are vulnerable however packaging it up to work out of the box for every site is challenging. The first 4 items are in the lastest CRS in trunk. We haven't included the JS Sandbox feature yet however you can test it out here - Commented Apr 11, 2011 at 12:44
  • modsecurity.org/demo/demo-deny-noescape.html Commented Apr 11, 2011 at 12:45
  • @Rook: regarding W3AF's evasion plugins for ModSecurity - that was a NUL byte parsing issue from 2007 which was quickly fixed. Your larger point of bypasses/evasions is correct however and that is why you should look to tackle these issues from many different angles. Commented Apr 11, 2011 at 12:50

I was going to suggest that you check out Ryan Barnett's work, but he already answered!

Data validation is not enough to prevent XSS, even if it's a pure whitelist.

The identification of improper output handling must occur on all outputs. They might be able to be fixed contextually with ModSecurity, but certainly this is the wrong place in the architecture to do it -- since if anything changes with regards to that content -- the encoding/escaping would suddenly become useless. Web content has a way of changing a lot.

The correct answer is to monitor output escaping issues with ModSecurity -- and actually remediate XSS issues elsewhere.

One of the best approaches I've heard lately is to Stop Building HTML on the Server. In particular, this would kill two birds with one stone: you could solve the problems with AJAX (e.g. DOM-based XSS) as well as stored and reflected XSS issues.

However, I strongly encourage you to check out the Encoding libraries in OWASP ESAPI and OWASP ESAPI JS. The best remediation advice comes from contextual output encoding. Remediating XSS is a lot of work, but it's worth to think about these problems as longer-lasting and with serious impact if we don't fix them now.

  • I'm going to +1 you, even though its not really an answer to my question - but it is the CORRECT answer, unfortunately I'm dealing here with my client's constraints... Of course the long term solution is to fix the code, but I was looking for a temporary quick fix.
    – AviD
    Commented Apr 11, 2011 at 5:32

Mod Security is absolutely fantastic work by everyone involved. However, don't expect to just "set and forget". It took us a lot of work to fine tune the install to get rid of false positives from the core rule set.


Probably not, but you should test it for your self. Sitewatch, Acunetix, and W3AF are all free and they will test your application for XSS. Beyond that, an attacker can build a payload for XSS specifically to bypass mod_secuirty. For instnace there are Mod_Security bypass modules for W3AF. So using a WAF like this is is not a Defense in Depth approach.

  • The author of Sitewatch in particular references that some XSS are hard to find even when performing code-assisted penetration-tests. No scanner or tool can do the job of a bunch of expert humans.
    – atdre
    Commented Apr 11, 2011 at 17:43
  • @atdre you should always use automation to find the low hanging fruit. Then move on to more expensive methods of bug hunting.
    – rook
    Commented Apr 11, 2011 at 18:54
  • @Rook: Don't tell me what to do! I won't use automation and you can't stop me! ;) -- but seriously, it's true -- spending time and money on automation can actually be more expensive. I'm not just speaking to corner-cases. Automation should be up to the person driving the test on where and how to implement it. Pure or full automation is only useful in very rare cases -- but the infosec vendors would have you believe otherwise.
    – atdre
    Commented Apr 11, 2011 at 19:15
  • @atdre I'm sorry but I don't see how running a free service is somehow expensive. It does take about 5 minutes to setup, I'll give you that. You won't only hear this from me, run an automated tool to find low hanging fruit. Especially for xss, there are too many edge cases, you can't just use htmlspeicalcahrs() and expect it to be safe. After that then use time consuming tools like RIPS (very cool tool) or RATS. You shouldn't take this with a grain of salt afterall I should know.
    – rook
    Commented Apr 11, 2011 at 19:20
  • 1
    @Rook: All programs have the opportunity to crash or loop. I don't care about your lists of exploits or the Google Hall of Fame. I care about reality
    – atdre
    Commented Apr 11, 2011 at 22:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .