Skip to content
Myr

First pass to reword security doc for word flow.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ron DuPlain · committed by Armin Ronacher · parent 6875a05 · Browse files · 1 file+21 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+21 added−21 removed

  • other:+21 added−21 removed

1 file+21 added−21 removed

modified:docs/security.rst+21 added-21 removed
60 unmodified lines
61Another big problem is CSRF. This is a very complex topic and I won't62outline it here in detail just mention what it is and how to theoretically63prevent it.6465So if your authentication information is stored in cookies you have66implicit state management. By that I mean that the state of "being logged67in" is controlled by a cookie and that cookie is sent with each request to68a page. Unfortunately that really means "each request" so also requests69triggered by 3rd party sites. If you don't keep that in mind some people70might be able to trick your application's users with social engineering to71do stupid things without them knowing.65If your authentication information is stored in cookies, you have implicit66state management. The state of "being logged in" is controlled by a67cookie, and that cookie is sent with each request to a page.68Unfortunately that includes requests triggered by 3rd party sites. If you69don't keep that in mind, some people might be able to trick your70application's users with social engineering to do stupid things without71them knowing.7273Say you have a specific URL that, when you sent `POST` requests to will74delete a user's profile (say `http://example.com/user/delete`). If an75attacker now creates a page that sends a post request to that page with76some JavaScript he just has to trick some users to that page and their77profiles will end up being deleted.76some JavaScript he just has to trick some users to load that page and77their profiles will end up being deleted.7879Imagine you would run Facebook with millions of concurrent users and80someone would send out links to images of little kittens. When a user81would go to that page their profiles would get deleted while they are79Imagine you were to run Facebook with millions of concurrent users and80someone would send out links to images of little kittens. When users81would go to that page, their profiles would get deleted while they are82looking at images of fluffy cats.8384So how can you prevent yourself from that? Basically for each request85that modifies content on the server you would have to either use a86one-time token and store that in the cookie **and** also transmit it with87the form data. After recieving the data on the server again you would88then have to compare the two tokens and ensure they are equal.84How can you prevent that? Basically for each request that modifies85content on the server you would have to either use a one-time token and86store that in the cookie **and** also transmit it with the form data.87After receiving the data on the server again, you would then have to88compare the two tokens and ensure they are equal.8990Why does not Flask do that for you? The ideal place for this to happen is91the form validation framework which does not exist in Flask.90Why does Flask not do that for you? The ideal place for this to happen is91the form validation framework, which does not exist in Flask.9293.. _json-security:9495JSON Security
14 unmodified lines
110generate JSON.111112So what is the issue and how to avoid it? The problem are arrays at113toplevel in JSON. Imagine you send the following data out in a JSON114request. Say that's exporting the names and email adresses of all your115friends for a part of the userinterface that is written in JavaScript.114request. Say that's exporting the names and email addresses of all your115friends for a part of the user interface that is written in JavaScript.116Not very uncommon:117118.. sourcecode:: javascript119
49 unmodified lines