It's been a while since I dealt with those things, but what about this
scenario:

The attacker detects the CSRF code using an attack resembling the
scenario here:

http://wiki.developerforce.com/index.php/Secure_Coding_Secure_Communications#Secure_Communications_and_Cookies

[to save some time, this is the quote:

Failure to set the Secure flag for security-critical cookies is the
most common vulnerability in this category. Simply setting a cookie
over an HTTPS connection does not prevent it from being returned over
HTTP unless the Secure flag is set. Even if your site does not have an
HTTP version, malicious parties on the network may be able to steal
session cookies.

There are several ways to achieve this. For example, the attacker may
insert references to HTTP URLs to your application into sites that
your users are likely to visit. Assume your application is 
https://app.example.com,
and your users frequent a discussion forum/blog at http://exampleappblog.com.
ExampleAppBlog allows commenters to include limited HTML in their
posts, including img tags. A commenter inserts HTML into one of their
comments like the following:

<img src="<a href="http://app.example.com/example-logo.png";
class="external free" title="http://app.example.com/example-logo.png";
rel="nofollow">http://app.example.com/example-logo.png</a>" />
When a user authenticated to app.example.com views this comment, their
browser will fire off a request for example-logo.png over an insecure
HTTP connection. Since the app.example.com cookie was not set Secure,
the browser will include the cookie over this connection — exposing it
to the network.

]

Once they have the CSRF cookie, they use the site itself (example.com)
and post malicious code there with the right CSRF.

I agree it's not an easy attack, but why not turning on the secured
flag for cookies on https?




On Feb 10, 9:28 am, Ian Clelland <clell...@gmail.com> wrote:
> On Wed, Feb 9, 2011 at 11:51 AM, Brian Craft <bc...@thecraftstudio.com> wrote:
> > I thought, rather, that the csrf token was a cookie that was put in a
> > hidden form field.
>
> You're absolutely right; I wasn't thinking about that side of the token.
>
> > With firebug or webkit dev tools you can see the django csrf token in
> > the cookies. I would also refer you to middleware/csrf.py, where you
> > can see it doing the set_cookie.
>
> > I thought the security of the csrf token relied on the fact that the
> > 3rd party wouldn't know what value to put in the hidden form field.
> > The csrf middleware is, I believe, validating the value in the form
> > field, against the value in cookie. But when it creates the form, it
> > uses the value in the cookie.
>
> > If the token is stored in an insecure cookie, it can be sniffed. Then
> > I don't understand what prevents the attacker from constructing a
> > valid form.
>
> If you want a secure cookie, that means that your entire site (or at
> least the form-handling bits) must already be protected by SSL (since
> a secure cookie will only be returned over an SSL connection).
>
> The threat model you are proposing, then, sounds like this: There is a
> website, running Django, using Django's CSRF protection, in which all
> of the form-handling views are only accessible over HTTPS, but there
> are other resources in the same domain (or its subdomains) which are
> accessible over HTTP.
>
> Further, there is an attacker, who can sniff the unencrypted HTTP
> traffic, and can construct an HTML page at a different site (this is
> Cross-Site Request Forgery, after all)
>
> A lot of the potential damage seems to be mitigated by another check
> in django/middleware/csrf.py, for HTTPS requests only, that inpects
> the referer header of the incoming request, to ensure that the browser
> was not submitting the form from a different site. To get around that,
> the attacker would have to be able to construct a form on the
> SSL-protected site (a serious html-injection vulnerability would have
> to be present), or cause the request to be submitted over plain HTTP
> -- but the site is already HTTPS-only, so there shouldn't be any
> form-handling code listening on that port.
>
> Does this threat model correspond to what you're thinking? If so, I
> don't see away around the CSRF protection (at least, not one that
> involves the victim's browser)
>
> --
> Regards,
> Ian Clelland
> <clell...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to