zoukankan      html  css  js  c++  java
  • CSRF Laravel Cross Site Request Forgery protection¶

    Laravel 使得防止应用 遭到跨站请求伪造攻击变得简单。 Laravel 自动为每一个被应用管理的有效用户会话生成一个 CSRF “令牌”,该令牌用于验证授权用 户和发起请求者是否是同一个人。 任何时候在 Laravel 应用中定义 HTML 表单,都需要在表单中引入 CSRF 令牌字段,这样 CSRF 保护中间件才能够正常验证请求。想要生成包含 CSRF 令牌的隐藏输入字段,可以使用辅助函 数 csrf_field 来实现:

    中间件组 web 中的中间件 VerifyCsrfToken 会自动为我们验证请求输入的 token 值和 Session 中存储的 token 是否一致。
    <form method="POST" action="/profile"> {{ csrf_field() }}
    ...
    </form>

    跨站请求伪造(Cross-Site Request Forgery, CSRF),恶意网站通过脚本向当前用户浏览器打开的其它页面的 URL 发起恶意请求,由于同一浏览器进程下 Cookie 可见性,导致用户身份被盗用,完成恶意网站脚本中指定的操作。

    漏洞危害

    • 信息泄露:如登录ID,隐私信息等。
    • 恶意操作:如加好友,加购物车,删除数据等。

    开放平台文档中心 https://docs.open.alipay.com/399/106918/

     Cross Site Request Forgery protection | Django documentation | Django https://docs.djangoproject.com/en/3.0/ref/csrf/

    Cross Site Request Forgery protection

    The CSRF middleware and template tag provides easy-to-use protection against Cross Site Request Forgeries. This type of attack occurs when a malicious website contains a link, a form button or some JavaScript that is intended to perform some action on your website, using the credentials of a logged-in user who visits the malicious site in their browser. A related type of attack, ‘login CSRF’, where an attacking site tricks a user’s browser into logging into a site with someone else’s credentials, is also covered.

    The first defense against CSRF attacks is to ensure that GET requests (and other ‘safe’ methods, as defined by RFC 7231#section-4.2.1) are side effect free. Requests via ‘unsafe’ methods, such as POST, PUT, and DELETE, can then be protected by following the steps below.

    Why might a user encounter a CSRF validation failure after logging in?

    For security reasons, CSRF tokens are rotated each time a user logs in. Any page with a form generated before a login will have an old, invalid CSRF token and need to be reloaded. This might happen if a user uses the back button after a login or if they log in a different browser tab.

  • 相关阅读:
    Java Json 数据下划线与驼峰格式进行相互转换
    php 将数组转换网址URL参数
    Swagger2常用注解及其说明 (转)
    Java中 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念(转)
    bootstrap.css.map 404
    Git发生SSL certificate problem: certificate ha错误的解决方法
    防火墙禁ping:虚拟机ping不通主机,但主机可以ping虚拟机
    PhpStorm本地断点调试
    Java语言中姐种遍历List的方法总结
    Ubuntu18.04安装mysql5.7
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6650975.html
Copyright © 2011-2022 走看看