How to best prevent CSRF attacks in a GAE app?

前端 未结 3 1016
-上瘾入骨i
-上瘾入骨i 2021-02-04 12:01

So, what is the best way to prevent an XSRF attack for a GAE application? Imagine the following:

  1. Anyone can see a user\'s public object, and the db.Model id is us
3条回答
  •  一生所求
    2021-02-04 12:10

    In server's response displaying the form create a magic hash (based on client ip + date/time + random salt, whatever). Put it into a cookie and store somewhere on the server. During submit action handling check the cookie hash against the database entry.

    If there's no such hash or it's different, reject the submission.

    After successful submit you can remove the hash entry, change it's state to submitted - whatever suits you.

    That method should protect you in many cases, but surely is still not 100% bulletproof.

    Do a search for articles on CSRF, maybe you'll find some good answers on this Stack Overflow thing. ;)

    Don't do any referrer checks or client ip validations - it's too error-prone (the referrer information might be cleared by the user agent, a proxy or by user's preferences) and client's IP might change between the form creation and submission - don't punish the user for dynamic IP address allocation.

提交回复
热议问题