[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[WEB SECURITY] Re: [Webappsec] [WEB SECURITY] xss filter to protect from xss attacks



--0-775074399-1169594826=:34260
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

celf -=0A=0AI think i did not convey my message properly. I was trying to d=
emonstrate a PoC for validating input on a regular website (which does not =
take html tags or urls, etc as input). Lets take an example of a regular e-=
commerce website. That website is vulnerable to XSS because it is not doing=
 proper input validation. In my PoC I merely tried to demonstrate that a si=
mple filter like that could fix 9 out of 10 xss holes. Of course a website =
can add or delete to those filters mentioned in the code or change the repl=
acement character. =0A=0AI agree with you that html encoding during output =
is an additional check and will definitely help and i will add that approac=
h to this PoC too.=0A=0AThe other thing i want to mention here that i used =
blacklist filtering because in my discussion with a lot of architects, they=
 are ok with filtering known bad characters (including encoded representati=
ons) but they do not want to eliminate unknown bad characters. Their argume=
nt is "Though this approach may possibly become vulnerable when a character=
 not in this list can potentially be used maliciously but we dont want to c=
ompromise on functionality for a vulnerability which may not be identified =
for the next 5 years". To a certain extent i agree with them too.=0A=0A=0A =
=0ACheers,=0A =0AAnurag Agarwal=0A =0ASEEC - An application security search=
 engine=0AWeb: www.attacklabs.com , www.myappsecurity.com=0AEmail : anurag.=
agarwal@yahoo.com=0ABlog : http://myappsecurity.blogspot.com=0A =0A=0A=0A=
=0A----- Original Message ----=0AFrom: celf <celf@cudge.org>=0ATo: WASC For=
um <websecurity@webappsec.org>; "webappsec @OWASP" <webappsec@lists.owasp.o=
rg>=0ASent: Tuesday, January 23, 2007 12:51:26 PM=0ASubject: Re: [Webappsec=
] [WEB SECURITY] xss filter to protect from xss attacks=0A=0A=0A[sorry for =
the double posting]=0A=0AAgain,=0A=0AThis is not a problem if you don't "st=
rip" or "filter" input. Just do it=0Aright on the way out. Now, I'd never r=
ecommend leaving out input=0Avalidation, but if you're just doing HTML outp=
ut, then HTML entity=0Aencoding will prevent XSS, and it's way easier than =
blacklist filtering,=0Awhich hoses the incoming data.=0A=0AA simple proof:=
=0A=0A<%=0A' stupid trivial asp example=0Adim strInput=0AstrInput=3Dserver.=
htmlencode(trim(request.form("in")))=0A%>=0A<html>=0A<form name=3D"f" actio=
n=3D"" method=3D"post">=0ATry to run script in this:<br> <textarea name=3D"=
in"=0Arows=3D"5"cols=3D"80"><%=3DstrInput%></textarea>=0A<br><input type=3D=
"submit">=0A</form>=0AYou entered: <%=3DstrInput%>=0A</html>=0A=0AThe examp=
le above does not account for a bunch of stuff. It is only to=0Ashow that e=
ven fundamental, built in HTML encoding will go a long way.=0AAnd, no input=
 validation is used whatsoever. Again, not safe for all=0Acases, just an ex=
ample to illustrate a point that input "filtering" aka=0A"stripping charact=
ers" isn't the way to do output.=0A=0A-c=0A=0Aanurag.agarwal@yahoo.com wrot=
e:=0A> Dinis -=0A>  =0A> Thanks for your input. I know i am applying a blac=
klist filter but in my=0A> experience i have seen many of the architects do=
nt want to just look for=0A> the right characters. To them it limits their =
options. For example if=0A> & is not in my whitelist of characters then cus=
tomer cannot enter=0A> his company name as A&A industries. So, as much as i=
 favor not using=0A> blacklisting approach, industry still wants it. The ch=
aracters i am=0A> filtering cover most of the basis either individually or =
in combination.=0A>  =0A> To reply to your code example -=0A>  =0A> 1. Norm=
ally in most of the sites you wouldnt allow an external user to=0A> enter a=
 url for your website.=0A> 2. Lets say if you allow the user to input a url=
, which is internal to a=0A> website, just filter "http://";; and replace it=
 with "/".=0A> 3. If you want the user to input an external url then filter=
 for space=0A> in addition to the filter mentioned in the code(just a quick=
 thought).=0A> 4. If you want spaces too in the url then you have to develo=
p your own=0A> filter.=0A>  =0A> As i mentioned before, the code i demonstr=
ated is not for the=0A> websites(blogs, forums, etc) which require these sp=
ecial input=0A> characters but for those which doesn't and the majority of =
the websites=0A> dont require these as an input=0A> =0A> Cheers,=0A> =0A>  =
=0A> =0A> Anurag Agarwal=0A> =0A>  =0A> =0A> SEEC - An application security=
 search engine <http://www.myappsecurity.com/>=0A> =0A> Web: www.attacklabs=
.com <http://www.attacklabs.com/> ,=0A> www.myappsecurity.com <http://www.m=
yappsecurity.com/>=0A> =0A> Email : anurag.agarwal@yahoo.com <mailto:anurag=
.agarwal@yahoo.com>=0A> =0A> Blog : http://myappsecurity.blogspot.com=0A> <=
http://myappsecurity.blogspot.com/>=0A> =0A>  =0A> =0A> =0A> =0A> ----- Ori=
ginal Message ----=0A> From: Dinis Cruz <dinis@ddplus.net>=0A> To: Anurag A=
garwal <anurag.agarwal@yahoo.com>=0A> Cc: WASC Forum <websecurity@webappsec=
.org>; "webappsec @OWASP"=0A> <webappsec@lists.owasp.org>; Andrew van der S=
tock <vanderaj@owasp.org>;=0A> Jeff Williams <jeff.williams@owasp.org>=0A> =
Sent: Tuesday, January 23, 2007 7:46:33 AM=0A> Subject: Re: [WEB SECURITY] =
xss filter to protect from xss attacks=0A> =0A> This is a good but dangerou=
s effort, the problem is in this example is=0A> that Anurag is applying a b=
lackList filter and is only protecting=0A> against one case of xss.=0A> =0A=
> Here is the original code code:=0A> =0A>   String html =3D request.getPar=
ameter("html");=0A>   out.println("Here is the filtered output of the html =
you submitted.");=0A>   out.println(filterRequest(html));=0A> =0A> And if I=
 change it to:=0A> =0A> String html =3D "<a href=3D'" + filterRequest(reque=
st.getParameter("url")) +=0A> "'>XSS link</a>";=0A> out.println("Here is th=
e filtered output of the html you submitted.");=0A> out.println(html);=0A> =
=0A> which is another example of using user input to create a link=0A> =0A>=
 the filter can be easily bypassed.=0A> =0A> 1) normal request:=0A> http://=
127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3DnextServlet=0A> =
=0A> 2) already a type of XSS since this type of redirection should not be=
=0A> allowed:=0A> http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter=
?url=3Dhttp://www.google.com=0A> <http://127.0.0.1:8080/servlets-examples/s=
ervlet/XSSFilter?url=3Dhttp://www.google.com>=0A> =0A> 3) and here is an XS=
S 101 payload:=0A> http://127.0.0.1:8080/servlets-examples/servlet/XSSFilte=
r?url=3DnextPage'=0A> onmouseover=3D'Javascript:alert(document.cookie)=0A> =
<http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www=
.google.com%27%20onmouseover=3D%27Javascript:alert%28document.cookie%29>=0A=
> 4) or if you want to make sure the user cannot escape:=0A> http://127.0.0=
.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com'=0A=
> <http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://w=
ww.google.com%27>onmouseover=3D'Javascript:alert(document.cookie)";=0A> sty=
le=3D'display:block;position:absolute;left:0;right:0;width:100%25;height:10=
0%25  =0A> (thx pdp)=0A> =0A> 5) note that in example 4) above I could had =
used " in the payload since=0A> your filter will convert " to '   :=0A> htt=
p://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3DnextPage";=0A>=
 onmouseover=3D"Javascript:alert(document.cookie)=0A> =0A> <http://127.0.0.=
1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com%27%2=
0onmouseover=3D%27Javascript:alert%28document.cookie%29>6)=0A> of course th=
at in this case you could always just do:=0A> http://127.0.0.1:8080/servlet=
s-examples/servlet/XSSFilter?url=3Djavascript:alert(document.cookie)=0A> <h=
ttp://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Djavascript:a=
lert%28document.cookie%29> =0A> :)=0A> =0A> 7) and even if you added ' to t=
he filter (which might be a problem since=0A> in some case you will need to=
 accept it), it wouldn't cover for this=0A> case: String html =3D "<a href=
=3D" + filterRequest(=0A> request.getParameter("url")) + ">XSS link</a>";=
=0A> =0A> 8) and lets not forget the XSS caused by double encoding or doubl=
e=0A> decoding in the code=0A> =0A> I hope this shows how hard it is to pro=
perly mitigate against XSS and=0A> that in most cases white listing is the =
only safe option (and even in=0A> those cases XSS might occur).=0A> =0A> An=
other solution that is very rarely talked is to by default encode=0A> EVERY=
thing sent to out.println and force the developers to use=0A> strong-typed =
html classes to create HTML tags.=0A> =0A> In the above example your would =
change=0A> =0A>   String html =3D "<a href=3D'" + filterRequest(request.get=
Parameter("url"))=0A> + "'>XSS link</a>";=0A>   out.println(html);=0A> for=
=0A> =0A>   safeHtmlBuilder.a html =3D=0A> safeHtmlBuilder.a(request.getPar=
ameter("html"), "XSS link")=0A>   safeHtml.out(html);=0A> =0A> Assuming of =
course that safeHtmlBuilder.a(...) was built properly=0A> =0A> Even better =
than encoding out.println would be to block the developer=0A> from invoking=
 out.println directly (which could be enforced via ('Shock=0A> Horror!!!') =
the Java security manager (or in Partial Trust in .Net)).=0A> =0A> We would=
 have a nice solution for XSS (and this is a good example of=0A> what I was=
 talking about a while back on using Sandboxes to create=0A> environments w=
here these types of vulnerabilities are very hard to exists )=0A> =0A> Dini=
s Cruz=0A> Chief OWASP Evangelist=0A> http://www.owasp.org <http://www.owas=
p.org/>=0A> =0A> =0A> On 1/23/07, *Anurag Agarwal* <anurag.agarwal@yahoo.co=
m=0A> <mailto:anurag.agarwal@yahoo.com>> wrote:=0A> =0A>     I have created=
 a xss filter to protect from xss attacks. Though i=0A>     have filtered o=
nly for 8 characters but i was able to test against=0A>     all the attacks=
 mentioned in the RSnake's cheat sheet. Appscan was=0A>     not able to det=
ect any xss attacks on it. I request the application=0A>     security commu=
nity to help test this filter. 90% i am sure that you=0A>     wont be able =
to perform any xss attack on it, the rest 10% i will=0A>     find out after=
 the feedback from the community. For the curious=0A>     mind, it is writt=
en in java=0A>      =0A>     In case if you are successful in performing xs=
s attack, please=0A>     do reply to this email with your name, browser and=
 the xss attack=0A>     string.=0A>      =0A>     url - http://www.attackla=
bs.com/xssfilter/=0A>      =0A>     I appreciate your time and effort. Than=
ks a lot in advance=0A>      =0A> =0A>     Cheers,=0A> =0A>      =0A> =0A> =
    Anurag Agarwal=0A> =0A>      =0A> =0A>     SEEC - An application securi=
ty search engine=0A>     <http://www.myappsecurity.com/>=0A> =0A>     Web: =
www.attacklabs.com <http://www.attacklabs.com/> ,=0A>     www.myappsecurity=
.com <http://www.myappsecurity.com/>=0A> =0A>     Email : anurag.agarwal@ya=
hoo.com <mailto:anurag.agarwal@yahoo.com>=0A> =0A>     Blog : http://myapps=
ecurity.blogspot.com=0A>     <http://myappsecurity.blogspot.com/>=0A> =0A> =
     =0A> =0A> =0A> =0A> =0A> -- =0A> =0A> =0A> =0A> ----------------------=
--------------------------------------------------=0A> =0A> _______________=
________________________________=0A> Webappsec mailing list=0A> Webappsec@l=
ists.owasp.org=0A> http://lists.owasp.org/mailman/listinfo/webappsec=0A=0A_=
______________________________________________=0AWebappsec mailing list=0AW=
ebappsec@lists.owasp.org=0Ahttp://lists.owasp.org/mailman/listinfo/webappse=
c
--0-775074399-1169594826=:34260
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head><style type=3D"text/css"><!-- DIV {margin:0px;} --></style></he=
ad><body><div style=3D"font-family:arial, helvetica, sans-serif;font-size:1=
0pt"><P>celf -</P>=0A<P>&nbsp;</P>=0A<DIV></DIV>=0A<DIV>I think&nbsp;i did =
not convey my message&nbsp;properly. I was&nbsp;trying to demonstrate a PoC=
 for&nbsp;validating input on a&nbsp;regular website (which&nbsp;does not&n=
bsp;take html tags or urls, etc as input).&nbsp;Lets take an example of a&n=
bsp;regular e-commerce website. That website&nbsp;is vulnerable to XSS&nbsp=
;because it is not&nbsp;doing&nbsp;proper input validation. In my PoC I mer=
ely&nbsp;tried to demonstrate that a simple filter like that could&nbsp;fix=
 9 out of 10 xss holes. Of course&nbsp;a website can add&nbsp;or delete to =
those filters mentioned in the code or change the replacement character. </=
DIV>=0A<DIV>&nbsp;</DIV>=0A<DIV>I agree with you that html encoding during =
output is an additional check and will definitely help and i will add that =
approach to this PoC too.</DIV>=0A<DIV>&nbsp;</DIV>=0A<DIV>The other thing =
i want to mention here that i used&nbsp;blacklist filtering because in my d=
iscussion with a lot of architects, they&nbsp;are ok with filtering known b=
ad characters (including encoded representations)&nbsp;but they do not want=
 to eliminate unknown bad characters. Their argument is "Though&nbsp;this a=
pproach may possibly become vulnerable when a character not in this list ca=
n&nbsp;potentially&nbsp;be used maliciously but&nbsp;we dont want to compro=
mise on functionality for a&nbsp;vulnerability which may not be identified =
for the next 5 years". To a certain extent i agree with them too.</DIV>=0A<=
DIV>&nbsp;</DIV>=0A<DIV><BR>&nbsp;</DIV>=0A<P>Cheers,</P>=0A<P>&nbsp;</P>=
=0A<P>Anurag Agarwal</P>=0A<P>&nbsp;</P>=0A<P><A href=3D"http://www.myappse=
curity.com/">SEEC - An application security search engine</A></P>=0A<P>Web:=
&nbsp;<A href=3D"http://www.attacklabs.com/";>www.attacklabs.com</A>&nbsp;, =
<A href=3D"http://www.myappsecurity.com/";>www.myappsecurity.com</A></P>=0A<=
P>Email : <A href=3D"mailto:anurag.agarwal@yahoo.com";>anurag.agarwal@yahoo.=
com</A></P>=0A<P>Blog : <A href=3D"http://myappsecurity.blogspot.com/";>http=
://myappsecurity.blogspot.com</A></P>=0A<P>&nbsp;</P>=0A<DIV style=3D"FONT-=
SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><BR><BR>=0A<DIV styl=
e=3D"FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"=
>----- Original Message ----<BR>From: celf &lt;celf@cudge.org&gt;<BR>To: WA=
SC Forum &lt;websecurity@webappsec.org&gt;; "webappsec @OWASP" &lt;webappse=
c@lists.owasp.org&gt;<BR>Sent: Tuesday, January 23, 2007 12:51:26 PM<BR>Sub=
ject: Re: [Webappsec] [WEB SECURITY] xss filter to protect from xss attacks=
<BR><BR>=0A<DIV>[sorry for the double posting]<BR><BR>Again,<BR><BR>This is=
 not a problem if you don't "strip" or "filter" input. Just do it<BR>right =
on the way out. Now, I'd never recommend leaving out input<BR>validation, b=
ut if you're just doing HTML output, then HTML entity<BR>encoding will prev=
ent XSS, and it's way easier than blacklist filtering,<BR>which hoses the i=
ncoming data.<BR><BR>A simple proof:<BR><BR>&lt;%<BR>' stupid trivial asp e=
xample<BR>dim strInput<BR>strInput=3Dserver.htmlencode(trim(request.form("i=
n")))<BR>%&gt;<BR>&lt;html&gt;<BR>&lt;form name=3D"f" action=3D"" method=3D=
"post"&gt;<BR>Try to run script in this:&lt;br&gt; &lt;textarea name=3D"in"=
<BR>rows=3D"5"cols=3D"80"&gt;&lt;%=3DstrInput%&gt;&lt;/textarea&gt;<BR>&lt;=
br&gt;&lt;input type=3D"submit"&gt;<BR>&lt;/form&gt;<BR>You entered: &lt;%=
=3DstrInput%&gt;<BR>&lt;/html&gt;<BR><BR>The example above does not account=
 for a bunch of stuff. It is only to<BR>show that even fundamental, built i=
n HTML encoding will go a long way.<BR>And,
 no input validation is used whatsoever. Again, not safe for all<BR>cases, =
just an example to illustrate a point that input "filtering" aka<BR>"stripp=
ing characters" isn't the way to do output.<BR><BR>-c<BR><BR>anurag.agarwal=
@yahoo.com wrote:<BR>&gt; Dinis -<BR>&gt;&nbsp;&nbsp;<BR>&gt; Thanks for yo=
ur input. I know i am applying a blacklist filter but in my<BR>&gt; experie=
nce i have seen many of the architects dont want to just look for<BR>&gt; t=
he right characters. To them it limits their options. For example if<BR>&gt=
; &amp; is not in my whitelist of characters then customer cannot enter<BR>=
&gt; his company name as A&amp;A industries. So, as much as i favor not usi=
ng<BR>&gt; blacklisting approach, industry still wants it. The characters i=
 am<BR>&gt; filtering cover most of the basis either individually or in com=
bination.<BR>&gt;&nbsp;&nbsp;<BR>&gt; To reply to your code example -<BR>&g=
t;&nbsp;&nbsp;<BR>&gt; 1. Normally in most of the sites you wouldnt allow a=
n external
 user to<BR>&gt; enter a url for your website.<BR>&gt; 2. Lets say if you a=
llow the user to input a url, which is internal to a<BR>&gt; website, just =
filter "<A href=3D'http://"/' target=3D_blank>http://";</A>; and replace it =
with "/".<BR>&gt; 3. If you want the user to input an external url then fil=
ter for space<BR>&gt; in addition to the filter mentioned in the code(just =
a quick thought).<BR>&gt; 4. If you want spaces too in the url then you hav=
e to develop your own<BR>&gt; filter.<BR>&gt;&nbsp;&nbsp;<BR>&gt; As i ment=
ioned before, the code i demonstrated is not for the<BR>&gt; websites(blogs=
, forums, etc) which require these special input<BR>&gt; characters but for=
 those which doesn't and the majority of the websites<BR>&gt; dont require =
these as an input<BR>&gt; <BR>&gt; Cheers,<BR>&gt; <BR>&gt;&nbsp;&nbsp;<BR>=
&gt; <BR>&gt; Anurag Agarwal<BR>&gt; <BR>&gt;&nbsp;&nbsp;<BR>&gt; <BR>&gt; =
SEEC - An application security search engine &lt;<A href=3D"http://www.myap=
psecurity.com/"
 target=3D_blank>http://www.myappsecurity.com/</A>&gt;<BR>&gt; <BR>&gt; Web=
: <A href=3D"http://www.attacklabs.com/"; target=3D_blank>www.attacklabs.com=
</A> &lt;<A href=3D"http://www.attacklabs.com/"; target=3D_blank>http://www.=
attacklabs.com/</A>&gt; ,<BR>&gt; <A href=3D"http://www.myappsecurity.com/"=
 target=3D_blank>www.myappsecurity.com</A> &lt;<A href=3D"http://www.myapps=
ecurity.com/" target=3D_blank>http://www.myappsecurity.com/</A>&gt;<BR>&gt;=
 <BR>&gt; Email : anurag.agarwal@yahoo.com &lt;mailto:anurag.agarwal@yahoo.=
com&gt;<BR>&gt; <BR>&gt; Blog : <A href=3D"http://myappsecurity.blogspot.co=
m/" target=3D_blank>http://myappsecurity.blogspot.com</A><BR>&gt; &lt;<A hr=
ef=3D"http://myappsecurity.blogspot.com/"; target=3D_blank>http://myappsecur=
ity.blogspot.com/</A>&gt;<BR>&gt; <BR>&gt;&nbsp;&nbsp;<BR>&gt; <BR>&gt; <BR=
>&gt; <BR>&gt; ----- Original Message ----<BR>&gt; From: Dinis Cruz &lt;din=
is@ddplus.net&gt;<BR>&gt; To: Anurag Agarwal &lt;anurag.agarwal@yahoo.com&g=
t;<BR>&gt; Cc: WASC Forum
 &lt;websecurity@webappsec.org&gt;; "webappsec @OWASP"<BR>&gt; &lt;webappse=
c@lists.owasp.org&gt;; Andrew van der Stock &lt;vanderaj@owasp.org&gt;;<BR>=
&gt; Jeff Williams &lt;jeff.williams@owasp.org&gt;<BR>&gt; Sent: Tuesday, J=
anuary 23, 2007 7:46:33 AM<BR>&gt; Subject: Re: [WEB SECURITY] xss filter t=
o protect from xss attacks<BR>&gt; <BR>&gt; This is a good but dangerous ef=
fort, the problem is in this example is<BR>&gt; that Anurag is applying a b=
lackList filter and is only protecting<BR>&gt; against one case of xss.<BR>=
&gt; <BR>&gt; Here is the original code code:<BR>&gt; <BR>&gt;&nbsp;&nbsp; =
String html =3D request.getParameter("html");<BR>&gt;&nbsp;&nbsp; out.print=
ln("Here is the filtered output of the html you submitted.");<BR>&gt;&nbsp;=
&nbsp; out.println(filterRequest(html));<BR>&gt; <BR>&gt; And if I change i=
t to:<BR>&gt; <BR>&gt; String html =3D "&lt;a href=3D'" + filterRequest(req=
uest.getParameter("url")) +<BR>&gt; "'&gt;XSS link&lt;/a&gt;";<BR>&gt; out.=
println("Here is
 the filtered output of the html you submitted.");<BR>&gt; out.println(html=
);<BR>&gt; <BR>&gt; which is another example of using user input to create =
a link<BR>&gt; <BR>&gt; the filter can be easily bypassed.<BR>&gt; <BR>&gt;=
 1) normal request:<BR>&gt; <A href=3D"http://127.0.0.1:8080/servlets-examp=
les/servlet/XSSFilter?url=3DnextServlet" target=3D_blank>http://127.0.0.1:8=
080/servlets-examples/servlet/XSSFilter?url=3DnextServlet</A><BR>&gt; <BR>&=
gt; 2) already a type of XSS since this type of redirection should not be<B=
R>&gt; allowed:<BR>&gt; <A href=3D"http://127.0.0.1:8080/servlets-examples/=
servlet/XSSFilter?url=3Dhttp://www.google.com"; target=3D_blank>http://127.0=
.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com</=
A><BR>&gt; &lt;<A href=3D"http://127.0.0.1:8080/servlets-examples/servlet/X=
SSFilter?url=3Dhttp://www.google.com"; target=3D_blank>http://127.0.0.1:8080=
/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com</A>&gt;<BR=
>&gt; <BR>&gt; 3) and here is an XSS
 101 payload:<BR>&gt; <A href=3D"http://127.0.0.1:8080/servlets-examples/se=
rvlet/XSSFilter?url=3DnextPage" target=3D_blank>http://127.0.0.1:8080/servl=
ets-examples/servlet/XSSFilter?url=3DnextPage</A>'<BR>&gt; onmouseover=3D'J=
avascript:alert(document.cookie)<BR>&gt; &lt;<A href=3D"http://127.0.0.1:80=
80/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com%27%20onm=
ouseover=3D%27Javascript:alert%28document.cookie%29" target=3D_blank>http:/=
/127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google=
.com%27%20onmouseover=3D%27Javascript:alert%28document.cookie%29</A>&gt;<BR=
>&gt; 4) or if you want to make sure the user cannot escape:<BR>&gt; <A hre=
f=3D"http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp:/=
/www.google.com" target=3D_blank>http://127.0.0.1:8080/servlets-examples/se=
rvlet/XSSFilter?url=3Dhttp://www.google.com</A>'<BR>&gt; &lt;<A href=3D"htt=
p://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.goo=
gle.com%27>onmouseover=3D" target=3D_blank
 Javascript:alert(document.cookie)&quot?>http://127.0.0.1:8080/servlets-exa=
mples/servlet/XSSFilter?url=3Dhttp://www.google.com%27&gt;onmouseover=3D'Ja=
vascript:alert(document.cookie)"</A>;<BR>&gt; style=3D'display:block;positi=
on:absolute;left:0;right:0;width:100%25;height:100%25&nbsp;&nbsp;<BR>&gt; (=
thx pdp)<BR>&gt; <BR>&gt; 5) note that in example 4) above I could had used=
 " in the payload since<BR>&gt; your filter will convert " to '&nbsp;&nbsp;=
 :<BR>&gt; <A href=3D'http://127.0.0.1:8080/servlets-examples/servlet/XSSFi=
lter?url=3DnextPage"' target=3D_blank>http://127.0.0.1:8080/servlets-exampl=
es/servlet/XSSFilter?url=3DnextPage"</A>;<BR>&gt; onmouseover=3D"Javascript=
:alert(document.cookie)<BR>&gt; <BR>&gt; &lt;<A href=3D"http://127.0.0.1:80=
80/servlets-examples/servlet/XSSFilter?url=3Dhttp://www.google.com%27%20onm=
ouseover=3D%27Javascript:alert%28document.cookie%29>6"
 target=3D_blank>http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?=
url=3Dhttp://www.google.com%27%20onmouseover=3D%27Javascript:alert%28docume=
nt.cookie%29&gt;6</A>)<BR>&gt; of course that in this case you could always=
 just do:<BR>&gt; <A href=3D"http://127.0.0.1:8080/servlets-examples/servle=
t/XSSFilter?url=3Djavascript:alert(document.cookie" target=3D_blank>http://=
127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=3Djavascript:alert(d=
ocument.cookie</A>)<BR>&gt; &lt;<A href=3D"http://127.0.0.1:8080/servlets-e=
xamples/servlet/XSSFilter?url=3Djavascript:alert%28document.cookie%29" targ=
et=3D_blank>http://127.0.0.1:8080/servlets-examples/servlet/XSSFilter?url=
=3Djavascript:alert%28document.cookie%29</A>&gt; <BR>&gt; :)<BR>&gt; <BR>&g=
t; 7) and even if you added ' to the filter (which might be a problem since=
<BR>&gt; in some case you will need to accept it), it wouldn't cover for th=
is<BR>&gt; case: String html =3D "&lt;a href=3D" + filterRequest(<BR>&gt; r=
equest.getParameter("url")) + "&gt;XSS
 link&lt;/a&gt;";<BR>&gt; <BR>&gt; 8) and lets not forget the XSS caused by=
 double encoding or double<BR>&gt; decoding in the code<BR>&gt; <BR>&gt; I =
hope this shows how hard it is to properly mitigate against XSS and<BR>&gt;=
 that in most cases white listing is the only safe option (and even in<BR>&=
gt; those cases XSS might occur).<BR>&gt; <BR>&gt; Another solution that is=
 very rarely talked is to by default encode<BR>&gt; EVERYthing sent to out.=
println and force the developers to use<BR>&gt; strong-typed html classes t=
o create HTML tags.<BR>&gt; <BR>&gt; In the above example your would change=
<BR>&gt; <BR>&gt;&nbsp;&nbsp; String html =3D "&lt;a href=3D'" + filterRequ=
est(request.getParameter("url"))<BR>&gt; + "'&gt;XSS link&lt;/a&gt;";<BR>&g=
t;&nbsp;&nbsp; out.println(html);<BR>&gt; for<BR>&gt; <BR>&gt;&nbsp;&nbsp; =
safeHtmlBuilder.a html =3D<BR>&gt; safeHtmlBuilder.a(request.getParameter("=
html"), "XSS link")<BR>&gt;&nbsp;&nbsp; safeHtml.out(html);<BR>&gt; <BR>&gt=
; Assuming of
 course that safeHtmlBuilder.a(...) was built properly<BR>&gt; <BR>&gt; Eve=
n better than encoding out.println would be to block the developer<BR>&gt; =
from invoking out.println directly (which could be enforced via ('Shock<BR>=
&gt; Horror!!!') the Java security manager (or in Partial Trust in .Net)).<=
BR>&gt; <BR>&gt; We would have a nice solution for XSS (and this is a good =
example of<BR>&gt; what I was talking about a while back on using Sandboxes=
 to create<BR>&gt; environments where these types of vulnerabilities are ve=
ry hard to exists )<BR>&gt; <BR>&gt; Dinis Cruz<BR>&gt; Chief OWASP Evangel=
ist<BR>&gt; <A href=3D"http://www.owasp.org/"; target=3D_blank>http://www.ow=
asp.org</A> &lt;<A href=3D"http://www.owasp.org/"; target=3D_blank>http://ww=
w.owasp.org/</A>&gt;<BR>&gt; <BR>&gt; <BR>&gt; On 1/23/07, *Anurag Agarwal*=
 &lt;anurag.agarwal@yahoo.com<BR>&gt; &lt;mailto:anurag.agarwal@yahoo.com&g=
t;&gt; wrote:<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; I have created a xss=
 filter to protect
 from xss attacks. Though i<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; have filtered o=
nly for 8 characters but i was able to test against<BR>&gt;&nbsp;&nbsp;&nbs=
p;&nbsp; all the attacks mentioned in the RSnake's cheat sheet. Appscan was=
<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; not able to detect any xss attacks on it. =
I request the application<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; security communit=
y to help test this filter. 90% i am sure that you<BR>&gt;&nbsp;&nbsp;&nbsp=
;&nbsp; wont be able to perform any xss attack on it, the rest 10% i will<B=
R>&gt;&nbsp;&nbsp;&nbsp;&nbsp; find out after the feedback from the communi=
ty. For the curious<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; mind, it is written in =
java<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt;&nbsp;&nbsp;&nbsp;&=
nbsp; In case if you are successful in performing xss attack, please<BR>&gt=
;&nbsp;&nbsp;&nbsp;&nbsp; do reply to this email with your name, browser an=
d the xss attack<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;
 string.<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt;&nbsp;&nbsp;&nb=
sp;&nbsp; url - <A href=3D"http://www.attacklabs.com/xssfilter/"; target=3D_=
blank>http://www.attacklabs.com/xssfilter/</A><BR>&gt;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; I appreciate your time and =
effort. Thanks a lot in advance<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Cheers,<BR>&gt; <BR>&gt;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Anurag=
 Agarwal<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt; <BR>&=
gt;&nbsp;&nbsp;&nbsp;&nbsp; SEEC - An application security search engine<BR=
>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<A href=3D"http://www.myappsecurity.com/"=
 target=3D_blank>http://www.myappsecurity.com/</A>&gt;<BR>&gt; <BR>&gt;&nbs=
p;&nbsp;&nbsp;&nbsp; Web: <A href=3D"http://www.attacklabs.com/"; target=3D_=
blank>www.attacklabs.com</A> &lt;<A href=3D"http://www.attacklabs.com/";
 target=3D_blank>http://www.attacklabs.com/</A>&gt; ,<BR>&gt;&nbsp;&nbsp;&n=
bsp;&nbsp; <A href=3D"http://www.myappsecurity.com/"; target=3D_blank>www.my=
appsecurity.com</A> &lt;<A href=3D"http://www.myappsecurity.com/"; target=3D=
_blank>http://www.myappsecurity.com/</A>&gt;<BR>&gt; <BR>&gt;&nbsp;&nbsp;&n=
bsp;&nbsp; Email : anurag.agarwal@yahoo.com &lt;mailto:anurag.agarwal@yahoo=
.com&gt;<BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Blog : <A href=3D"http://=
myappsecurity.blogspot.com/" target=3D_blank>http://myappsecurity.blogspot.=
com</A><BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<A href=3D"http://myappsecurity=
.blogspot.com/" target=3D_blank>http://myappsecurity.blogspot.com/</A>&gt;<=
BR>&gt; <BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt; <BR>&gt; <BR>&=
gt; <BR>&gt; <BR>&gt; -- <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; --------------=
----------------------------------------------------------<BR>&gt; <BR>&gt;=
 _______________________________________________<BR>&gt; Webappsec mailing =
list<BR>&gt;
 Webappsec@lists.owasp.org<BR>&gt; <A href=3D"http://lists.owasp.org/mailma=
n/listinfo/webappsec" target=3D_blank>http://lists.owasp.org/mailman/listin=
fo/webappsec</A><BR><BR>_______________________________________________<BR>=
Webappsec mailing list<BR>Webappsec@lists.owasp.org<BR><A href=3D"http://li=
sts.owasp.org/mailman/listinfo/webappsec" target=3D_blank>http://lists.owas=
p.org/mailman/listinfo/webappsec</A></DIV></DIV><BR></DIV></div></body></ht=
ml>
--0-775074399-1169594826=:34260--



Brought to you by http://www.webappsec.org
Search this site