V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
beny2mor
V2EX  ›  Python

后台服务器的 csrftoken 是如何起到防御 csrf 的作用的?

  •  
  •   beny2mor · Jun 23, 2018 · 3212 views
    This topic created in 2875 days ago, the information mentioned may be changed or developed.
    对 csrftoken 的概念不了解,我的理解是发 post 请求前,先向后台请求一个一次性的 token,然后 post 请求带上这个 token ?

    一般请求比如发表新的文章,后端应该是需要验证用户凭证 uuid 的吧。uuid 如果没被盗取的话请求不会通过,uuid 被盗取应该可以利用它来获取 csrftoken,那么 csrftoken 就没有必要?
    不过大部分后台服务器都能配置 csrftoken 那么它肯定有效用的。请教下我的理解错在哪里了。
    Supplement 1  ·  Jun 23, 2018
    那么 csrftoken 比起 Access-Controll-Allow-Origin 有什么优势
    wwqgtxx
        1
    wwqgtxx  
       Jun 23, 2018 via iPhone
    你还是先查一下 csrf 这个简写是什么意思再过来问比较好
    ipwx
        2
    ipwx  
       Jun 23, 2018 via iPhone
    楼上+1
    beny2mor
        3
    beny2mor  
    OP
       Jun 23, 2018
    @wwqgtxx 跨域攻击... 那如果限制了 Access-Controll-Allow-Origin 还有必要使用 csrftoken 吗?
    beny2mor
        4
    beny2mor  
    OP
       Jun 23, 2018
    @ipwx 其实是这样, 我爬数据的时候做了登录,结果发现有个 csrftoken 参数找不到。分析页面源码找到 token 的请求方式,请求新的 csrftoken 需要就的 csrftoken 作参数,这就限制了我并发爬取..
    感觉 csrftoken 在防爬虫方面比防 csrf 更有效.. 毕竟主流浏览器都实现了 Access-Controll-Allow-Origin 能够很好地避免 csrf 攻击
    wwqgtxx
        5
    wwqgtxx  
       Jun 23, 2018 via iPhone   ❤️ 1
    @beny2mor Access-Controll-Allow-Origin 出现的还是比较晚的,部分古老的浏览器不支持,而 csrftoken 则没有这个问题,另外 csrftoken 还能阻止 get 模式下的跨域攻击,而 acao 并做不到(根据 mdn 文档,acao 对 get 请求无效)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2962 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:21 · PVG 23:21 · LAX 08:21 · JFK 11:21
    ♥ Do have faith in what you're doing.