Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

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...

share|improve this question

4 Answers 4

up vote 7 down vote accepted

You should review the XSS Street-Fight (with ModSecurity) Blackhat preso - http://www.modsecurity.org/documentation/XSS_Street_Fight-Ryan_Barnett-BlackhatDC-2011.pdf

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)
share|improve this answer
    
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 Apr 11 '11 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 - –  Ryan Barnett Apr 11 '11 at 12:44
    
    
@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. –  Ryan Barnett Apr 11 '11 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.

share|improve this answer
    
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 Apr 11 '11 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.

share|improve this answer

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.

share|improve this answer
    
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 Apr 11 '11 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 Apr 11 '11 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 Apr 11 '11 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 Apr 11 '11 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 Apr 11 '11 at 22:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.