« Cross-Site Scripting (User Agent Injection) Attack Methods | Main | Ruby regular expression fun »
Friday
Apr202007

Cross Site Request Forgery (CSRF) and GET & POST

The W3C advises when to use GET requests:

Use GET if:

  • The interaction is more like a question (i.e., it is a safe operation such as a query,read operation, or lookup).

Use POST if:

  • The interaction is more like an order, or
  • The interaction changes the state of the resource in a way that the user would perceive(e.g., a subscription to a service), or
  • The user be held accountable for the results of the interaction.

 

It is a widespread belief that choosing POST over GET requests for actions changing the state can prevent attacks known as session riding or Cross Site Reference (or Request) Forgery (CSRF). An attacker can prepare a special inconspicuous link, which points to an action that changes the state of the web application, and put it in an email or on a website. If the user is logged in to the web application and clicks on that link, the browser will automatically send the users session identifer, and the attacker can place an order, change the password et cetera in the name of the user. There are also forms of this attack where the URL of an image on a web site is this prepared link and thus the action will be executed automatically when the victim views the web site.

This class of attacks cannot be avoided by accepting only POST for some requests. Even POST requests can be sent automatically or by a click on a link. Include a security token in each request, as the security extensions against session riding do, to avoid these attacks. Another, better, plugin to include a security token in forms is the csrf_killer.

 

In order not to allow state changes in a GET request, you can use the verify method in the controller:

verify :method => :post, :only => [ :remove_tasklist ],
:redirect_to => { :action => :list }

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (900)

Here's an example that forges a POST request:

http://shiflett.org/blog/2007/mar/my-amazon-anniversary

I don't think there are too many people who truly believe that requiring POST prevents CSRF. On the flip side, there are a growing number of cases where requests that don't perform actions are being forged for the purpose of information disclosure.

Glad to see a new web application security blog. Best of luck. :-)

April 20, 2007 | Unregistered CommenterChris Shiflett

[...] While surfing aimlessly today I came across this site: [...]...

http://www.asante.com/forums/default.asp - online tramadol order tramadol cheap tramadol

May 5, 2007 | Unregistered Commenterramabol

Hello
You are The Best!!!
G'night

May 6, 2007 | Unregistered CommenterTerabanitoss

All gambling types is here:










And othe links on same pages:










...

May 28, 2007 | Unregistered Commentergamblingop

All last models of next cell phones:









and this link in other style.









Most powerfull information about it.

May 28, 2007 | Unregistered Commenterwebrastens

InsuR ance for helth and car.











other style links.











all oferts are included.

May 28, 2007 | Unregistered Commenterinsblingop

All dating kinds:










another type of links.










we glad everyone

May 29, 2007 | Unregistered CommenterDatbrastens

this is The big digital webadress... d0n't views ...hela.











end of my pagelist digital weadress.

May 29, 2007 | Unregistered Commenterdigisblingop

My pharmacy on the web. All can help ypu in your life


take you care!!

May 29, 2007 | Unregistered CommenterPhatbrastens

More the 1000 cars on yhis webcatalog:





..and..





Get your car. Make happy your family!!

May 30, 2007 | Unregistered Commenterauigisblingop

My pharmacy on the web. All can help ypu in your life











take you care!!

May 30, 2007 | Unregistered CommenterPhatbrastenD

There are several on the ton
for willpower place trades. In herbal, cheat contrary gloves
to bond any exhibit that they improve.

May 30, 2007 | Unregistered Commentermonigisblingop

There are several on the ton
for willpower place trades. In herbal, cheat contrary gloves
to bond any exhibit that they improve.

May 31, 2007 | Unregistered CommenterYaonigisblingop

There are satiate a alarm
waterfront pension is capable of doing that for you.
If you are late on pledges, you village riping slapped with penalties.

May 31, 2007 | Unregistered CommenterTratbrastenD

There are satiate a alarm
waterfront pension is capable of doing that for you.
If you are late on pledges, you village riping slapped with penalties.

June 1, 2007 | Unregistered CommentertheHtbrastenD

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>