You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2000/12/15 06:44:16 UTC

Struts and Web Application Safety

Hello Struts Developers and Users,

As Struts becomes ever more popular (look for additional discussion of Struts in
various articles and book chapters in the next few months), one of our
responsibilities as framework designers is to make sure we encourage/require
"safe programming" practices, whenever that goal is feasible.  I was inspired to
write this message by reading on Linux Weekly News <http://lwn.net> this week
about a vulnerability in the Charles Schwab online trading system.

The problem is generally known in security circles as a "cross-site scripting"
vulnerability.  There was even a CERT advisory on this issue last February:

    http://www.cert.org/advisories/CA-2000-02.html

The sad point of the LWN coverage is that this problem is not a new one, and is
by no means restricted to Charles Schwab.  In the same industry, E*Trade has
also suffered from a very similar problem.  There are undoubtedly many other
applications that are vulnerable.  And it's all the application developer's
fault.

The key vulnerability that causes the problem here is accepting text, say in a
<form:textarea> tag, and displaying it back to the user as HTML text without
filtering out HTML tags.  Anyone who has used a naively-written guestbook app,
for example, has probably suffered from a user entering text like this in their
message:

    <a href="http://www.my-favorite-x-rated-site.com">Cool Pictures</a>

which, if you don't take appropriate measures when you render your page, could
generate a real hyperlink to a site you would normally never willingly link to.

Now imagine, instead of an embarrassing link to a site like this, the crafty
guestbook user entered JavaScript code that sent everything the client browser
knows about the user to some hacker's site.  At best, such information could be
used to make it look like a particular user is accessing inappropriate sites.
At worst, such code could be used to hijack the user's session and execute
unauthorized transactions on an online brokerage system -- as both Schwab and
others have discovered.

What does this have to do with Struts?  Well, we have the opportunity to protect
application developers from some consequences like this, if they are using the
Struts custom tags to render their output.  For example, with the <bean:write>
tag, you can ask for the output to be filtered for characters that are important
in HTML and XML (such as the "<" character that opens a tag).  If you carefully
do this on all input received from the user, you dramatically reduce the risk
that your application can be subject to the particular attack described in this
CERT Advisory.

Right now, though, the <bean:write> tag defaults to filtering only when you ask
for it.  I'd like to propose that we change the default to "true", so that
output is filtered unless you explicitly ask for it *not* to be.

In addition, I'd ask for your help in identifying places where Struts can help
developers create *safe* applications, not just *functional* ones.  Are there
other areas where you see vulnerabilities in Struts-based applications, where
the framework can assist in improving the security of an application based on
it?

Craig McClanahan



Re: Struts and Web Application Safety

Posted by Didier Girard <ll...@wanadoo.fr>.
Here is my solution for the redirect hole.
I think this solution can also be used to avoid resubmition of forms.

There is a new interface :
org.apache.struts.action.SecureForm
If a form has to be secured it must implement this interface.

There is a modification in :
org.apache.struts.taglib.form.FormTag
-> modification of doStartTag()
Puts the formKey in the generated form and in the HttpSession

There is a modification in :
org.apache.struts.action.ActionServlet
-> new method (processSecureForm())
-> modificiaton of processValidate()
These modification checks the validity of the form


There is a modification in :
struts-form.tld
-> add formKeyName field to form:form tag

To test the patch, I made some modification in the
struts-example webapp
-> securisation of the LogonForm (in order to test the patch on
a form which is directly requested through a jsp
-> securisation of the RegistrationForm (in order to test the patch on
a form which is requested through a *.do (mapping)

To secure a form, two things must be done :
- first, the form class should implement SecureForm
- second,  attribut formKeyName of the form:form tag should be set to some
value.

Is it enough clear ?

didier

Re: Struts and Web Application Safety

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
I had started down a similar path, although not for security reasons, so that you
could reliably detect when a user tried to submit the same form twice (because they
used the back arrow).  I'd like to see what you have in mind -- we might be able to
kill two birds with one stone.

Craig


Didier Girard wrote:

> Hello,
>
> I'm working on a patch for the redirect security hole.
> You can find more information on this hole here :
> http://lwn.net/2000/features/Redirect.phtml
>
> With this hole it is possible to redirect you to a page
> which performs some actions on a site where you have already
> authenticated yourself.
>
> In order to protect "sensible" forms on a site,
> the best way is to
> put a random key in the HttpSession and in the sensible form.
> When the form is submitted, if the keys in the
> request and in the HttpSession are the same,
> it is pretty sure that the redirect hole has not been exploited.
>
> I have already coded a solution for Struts, can we discuss
> it ?
>
> didier
>
> "Craig R. McClanahan" wrote:
> >
> > Hello Struts Developers and Users,
> >
> > As Struts becomes ever more popular (look for additional discussion of Struts in
> > various articles and book chapters in the next few months), one of our
> > responsibilities as framework designers is to make sure we encourage/require
> > "safe programming" practices, whenever that goal is feasible.  I was inspired to
> > write this message by reading on Linux Weekly News <http://lwn.net> this week
> > about a vulnerability in the Charles Schwab online trading system.
> >
> > The problem is generally known in security circles as a "cross-site scripting"
> > vulnerability.  There was even a CERT advisory on this issue last February:
> >
> >     http://www.cert.org/advisories/CA-2000-02.html
> >
> > The sad point of the LWN coverage is that this problem is not a new one, and is
> > by no means restricted to Charles Schwab.  In the same industry, E*Trade has
> > also suffered from a very similar problem.  There are undoubtedly many other
> > applications that are vulnerable.  And it's all the application developer's
> > fault.
> >
> > The key vulnerability that causes the problem here is accepting text, say in a
> > <form:textarea> tag, and displaying it back to the user as HTML text without
> > filtering out HTML tags.  Anyone who has used a naively-written guestbook app,
> > for example, has probably suffered from a user entering text like this in their
> > message:
> >
> >     <a href="http://www.my-favorite-x-rated-site.com">Cool Pictures</a>
> >
> > which, if you don't take appropriate measures when you render your page, could
> > generate a real hyperlink to a site you would normally never willingly link to.
> >
> > Now imagine, instead of an embarrassing link to a site like this, the crafty
> > guestbook user entered JavaScript code that sent everything the client browser
> > knows about the user to some hacker's site.  At best, such information could be
> > used to make it look like a particular user is accessing inappropriate sites.
> > At worst, such code could be used to hijack the user's session and execute
> > unauthorized transactions on an online brokerage system -- as both Schwab and
> > others have discovered.
> >
> > What does this have to do with Struts?  Well, we have the opportunity to protect
> > application developers from some consequences like this, if they are using the
> > Struts custom tags to render their output.  For example, with the <bean:write>
> > tag, you can ask for the output to be filtered for characters that are important
> > in HTML and XML (such as the "<" character that opens a tag).  If you carefully
> > do this on all input received from the user, you dramatically reduce the risk
> > that your application can be subject to the particular attack described in this
> > CERT Advisory.
> >
> > Right now, though, the <bean:write> tag defaults to filtering only when you ask
> > for it.  I'd like to propose that we change the default to "true", so that
> > output is filtered unless you explicitly ask for it *not* to be.
> >
> > In addition, I'd ask for your help in identifying places where Struts can help
> > developers create *safe* applications, not just *functional* ones.  Are there
> > other areas where you see vulnerabilities in Struts-based applications, where
> > the framework can assist in improving the security of an application based on
> > it?
> >
> > Craig McClanahan


Re: Struts and Web Application Safety

Posted by Didier Girard <ll...@wanadoo.fr>.
Hello,

I'm working on a patch for the redirect security hole.
You can find more information on this hole here :
http://lwn.net/2000/features/Redirect.phtml

With this hole it is possible to redirect you to a page 
which performs some actions on a site where you have already 
authenticated yourself.

In order to protect "sensible" forms on a site,
the best way is to
put a random key in the HttpSession and in the sensible form.
When the form is submitted, if the keys in the
request and in the HttpSession are the same,
it is pretty sure that the redirect hole has not been exploited.

I have already coded a solution for Struts, can we discuss
it ?

didier

"Craig R. McClanahan" wrote:
> 
> Hello Struts Developers and Users,
> 
> As Struts becomes ever more popular (look for additional discussion of Struts in
> various articles and book chapters in the next few months), one of our
> responsibilities as framework designers is to make sure we encourage/require
> "safe programming" practices, whenever that goal is feasible.  I was inspired to
> write this message by reading on Linux Weekly News <http://lwn.net> this week
> about a vulnerability in the Charles Schwab online trading system.
> 
> The problem is generally known in security circles as a "cross-site scripting"
> vulnerability.  There was even a CERT advisory on this issue last February:
> 
>     http://www.cert.org/advisories/CA-2000-02.html
> 
> The sad point of the LWN coverage is that this problem is not a new one, and is
> by no means restricted to Charles Schwab.  In the same industry, E*Trade has
> also suffered from a very similar problem.  There are undoubtedly many other
> applications that are vulnerable.  And it's all the application developer's
> fault.
> 
> The key vulnerability that causes the problem here is accepting text, say in a
> <form:textarea> tag, and displaying it back to the user as HTML text without
> filtering out HTML tags.  Anyone who has used a naively-written guestbook app,
> for example, has probably suffered from a user entering text like this in their
> message:
> 
>     <a href="http://www.my-favorite-x-rated-site.com">Cool Pictures</a>
> 
> which, if you don't take appropriate measures when you render your page, could
> generate a real hyperlink to a site you would normally never willingly link to.
> 
> Now imagine, instead of an embarrassing link to a site like this, the crafty
> guestbook user entered JavaScript code that sent everything the client browser
> knows about the user to some hacker's site.  At best, such information could be
> used to make it look like a particular user is accessing inappropriate sites.
> At worst, such code could be used to hijack the user's session and execute
> unauthorized transactions on an online brokerage system -- as both Schwab and
> others have discovered.
> 
> What does this have to do with Struts?  Well, we have the opportunity to protect
> application developers from some consequences like this, if they are using the
> Struts custom tags to render their output.  For example, with the <bean:write>
> tag, you can ask for the output to be filtered for characters that are important
> in HTML and XML (such as the "<" character that opens a tag).  If you carefully
> do this on all input received from the user, you dramatically reduce the risk
> that your application can be subject to the particular attack described in this
> CERT Advisory.
> 
> Right now, though, the <bean:write> tag defaults to filtering only when you ask
> for it.  I'd like to propose that we change the default to "true", so that
> output is filtered unless you explicitly ask for it *not* to be.
> 
> In addition, I'd ask for your help in identifying places where Struts can help
> developers create *safe* applications, not just *functional* ones.  Are there
> other areas where you see vulnerabilities in Struts-based applications, where
> the framework can assist in improving the security of an application based on
> it?
> 
> Craig McClanahan