title: In what case can CSRF-exempt be dangerous?
body: <p>This question is more a re-insurance than one directly about how to code. As an autodidact i did not have a lot of possibilities to ask professionals such things, so i try here.</p>
  
  <p>I have read the documents in the django-docs ( <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/" rel="noreferrer">https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/</a> ) and some info on that page: <a href="http://cwe.mitre.org/top25/#CWE-352" rel="noreferrer">http://cwe.mitre.org/top25/#CWE-352</a></p>
  
  <p>As far as i have understood, django delivers a token (some kind of pin-code) to a user. And to verify it really is him, he has to return it the next time he does a request. And some guys at Google found out that this is even possible with ajax-requests, which is why we have the new policy of protecting them too since 1.2.6. And CSRF is about someone giving me something (bad, dangerous code, corrupt files or something like that) pretending to be someone else.</p>
  
  <p>So if i have some code like this:</p>
  
  <pre><code>@csrf_exempt    
  def grab(request):
      """
      view to download an item
      POST because it stores that a user has downloaded this item
      """
      item_id = request.POST.get('item', None)
      if not loop: return HttpResponseBadRequest('no item id provided')
      item = Item.objects.get(pk=int(item_id))
  </code></pre>
  
  <p>that should be save, as i'm not giving access to the database or any part of my application before trying to convert the given value to an integer. And there is not too much damage if i do a wrong record of someone downloading a file (in this case it is almost none). Assuming i would write bills relying on this view, the CSRF-exempt would be vary bad idea (Is that right?).</p>
  
  <p>I also do not understand why somebody can't steal the CSRF-token from a user and use it to still trick me (or the user). So i have some questions about this topic:</p>
  
  <p>1) are my assumptions from above right?</p>
  
  <p>2) can somebody tell me, what (and probably how) some not so nice guy could use the view above to do dirty tricks, and what would they be?</p>
  
  <p>3) is a CSRF an example of a man-in-the-middle attack, is it just related to it, or is it something entirely different?</p>
  
  <p>4) Any valuable links to do further reading on such dangers?</p>
  
  <p>Maybe some of these questions sound no too well informed, but i'm trying to get over that. I would be very glad if someone could help me.</p>