Tuesday, December 7, 2010

Django CSRF 1.2

I have a PERL test script for DJANGO connection test. It works on
Django 1.1 admin login page, but doesn't work on 1.2. The request
contains:
<div id="summary">
<h1>Forbidden <span>(403)</span></h1>
<p>CSRF verification failed. Request aborted.</p>
</div>

Here is the perl script:
$response = $ua->get("$url/admin/");
my @lines = grep /id='csrfmiddlewaretoken'/,$response->content;
$lines[0] =~ /id='csrfmiddlewaretoken' name='csrfmiddlewaretoken'
value='([a-f0-9]+)'/;
$csrfid=$1;
my $req = HTTP::Request->new(POST => "$url/admin/",
[csrfmiddlewaretoken=>$csrfid]);
$req->header('Referer', "$url/admin/");
$ua->cookie_jar->add_cookie_header($req);
$response = $ua->request($req);

What's wrong? Have I forgot something?
1. Read the csrf hidden input
2. Keep cookies
3. Set csrf input to POST
4. Set cookie to headers
5. Set refer page (beacuse of HTTPS conection)
6. Make a POST request

Where can I find similar python script to test login page?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate