csrf

Rails API design without disabling CSRF protection

最后都变了- 提交于 2019-12-17 07:08:11
问题 Back in February 2011, Rails was changed to require the CSRF token for all non-GET requests, even those for an API endpoint. I understand the explanation for why this is an important change for browser requests, but that blog post does not offer any advice for how an API should handle the change. I am not interested in disabling CSRF protection for certain actions. How are APIs supposed to deal with this change? Is the expectation that an API client makes a GET request to the API to get a

New CSRF token per request or NOT?

两盒软妹~` 提交于 2019-12-17 06:30:11
问题 So I am reading around and was really confused about having a CSRF token, whetever I should generate a new token per each request, or just per hour or something? $data['token'] = md5(uniqid(rand(), true)); $_SESSION['token'] = $data['token']; But let's say it's better to generate a token each hour, then I would need two sessions: token, expiration, And how will I proceed it to the form? Just put echo $_SESSION['token'] on the hidden value form and then compare on submit? 回答1: If you do it per

1205

故事扮演 提交于 2019-12-17 05:30:16
一、模拟实现中间件的编程思想 (一)impotlib模块 importlib模块可以通过字符串的形式导入模块 importlib模块也支持 notify.email 的from···import类型 最小单位只能到文件名,不能用来导入文件中的变量名 # importlib模块(以导入json模块为例) import importlib json = importlib.import_module('json') module = importlib.import_module('notify.email') (二)实现功能的配置使用 基于Django中间件的思想实现功能的配置使用 可以通过在settings.py中注释某个字符串来动态取消或增加某个功能的实现 # settings.py NOTIFY_LIST = [ 'notify.email.Email', 'notify.msg.Msg', 'notify.wechat.WeChat', 'notify.qq.Qq', ] # noyify/eamil.py class Email(object): def __init__(self): pass # 发送邮件需要的前期准备 def send(self,content): print('邮件通知:%s'%content) # noyify/msg.py class Msg

django配置*app*登录案例*orm简用

蓝咒 提交于 2019-12-17 05:20:03
1.静态文件的配置和使用 1.静态文件的配置和使用 没有css样式: 添加样式 结果: <html lang="en"> <head> <meta charset="utf-8"> <title>Signin Template for Bootstrap</title> <!-- Bootstrap core CSS --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="signin.css" rel="stylesheet"> <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> <!--[if lt IE 9]><script src="../../assets

六、CsrfViewMiddleware

廉价感情. 提交于 2019-12-17 05:16:34
CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSRF/XSRF。 你这可以这么理解CSRF攻击:攻击者盗用了你的身份,以你的名义发送恶意请求。CSRF能够做的事情包括:以你名义发送邮件,发消息,盗取你的账号,甚至于购买商品,虚拟货币转账......造成的问题包括:个人隐私泄露以及财产安全。 关于更多关于CSRF的介绍,请参考以下链接: http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#CSRF_Specific_Defense Django应对CSRF攻击的机制是通过csrftoken(HTTP请求)或者csrftoken + HTTP_REFERER(HTTPS)来实现的。 CSRF防护的粒度主要有两类: 1、全局使能,所有视图(view)使能CSRF认证。 这个主要通过CsrfViewMiddleware中间件来实现。当该中间件添加到setting.py的MIDDLEWARE列表内时,即使能了CSRF中间件

Spring CSRF token does not work, when the request to be sent is a multipart request

对着背影说爱祢 提交于 2019-12-17 05:12:36
问题 I use, Spring Framework 4.0.0 RELEASE (GA) Spring Security 3.2.0 RELEASE (GA) Struts 2.3.16 In which, I use an in-built security token to guard against CSRF attacks. The Struts form looks like the following. <s:form namespace="/admin_side" action="Category" enctype="multipart/form-data" method="POST" validate="true" id="dataForm" name="dataForm"> <s:hidden name="%{#attr._csrf.parameterName}" value="%{#attr._csrf.token}"/> </s:form> The generated HTML code is as follows. <form id="dataForm"

rails - “WARNING: Can't verify CSRF token authenticity” for json devise requests

社会主义新天地 提交于 2019-12-17 04:41:10
问题 How can I retrieve the CSRF token to pass with a JSON request? I know that for security reasons Rails is checking the CSRF token on all the request types (including JSON/XML). I could put in my controller skip_before_filter :verify_authenticity_token , but I would lose the CRSF protection (not advisable :-) ). This similar (still not accepted) answer suggests to Retrieve the token with <%= form_authenticity_token %> The question is how? Do I need to do a first call to any of my pages to

CSRF攻击

…衆ロ難τιáo~ 提交于 2019-12-17 02:57:22
django攻击 csrf攻击 xss攻击 clickjacking攻击 sql注入 CSRF攻击: CSRF攻击概述: CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,它在 2007 年曾被列为互联网 20 大安全隐患之一。其他安全隐患,比如 SQL 脚本注入,跨站域脚本攻击等在近年来已经逐渐为众人熟知,很多网站也都针对他们进行了防御。然而,对于大多数人来说,CSRF 却依然是一个陌生的概念。即便是大名鼎鼎的 Gmail, 在 2007 年底也存在着 CSRF 漏洞,从而被黑客攻击而使 Gmail 的用户造成巨大的损失。 CSRF攻击原理: 网站是通过 cookie 来实现登录功能的。而 cookie 只要存在浏览器中,那么浏览器在访问这个 cookie 的服务器的时候,就会自动的携带 cookie 信息到服务器上去。那么这时候就存在一个漏洞了,如果你访问了一个别有用心或病毒网站,这个网站可以在网页源代码中插入js代码,使用js代码给其他服务器发送请求(比如ICBC的转账请求)。那么因为在发送请求的时候,浏览器会自动的把 cookie 发送给对应的服务器,这时候相应的服务器(比如ICBC网站),就不知道这个请求是伪造的,就被欺骗过去了。从而达到在用户不知情的情况下,给某个服务器发送了一个请求(比如转账)。 防御CSRF攻击:

Django 设置 cookie 中的 csrftoken

感情迁移 提交于 2019-12-17 02:25:17
遇到一个问题是,CMDB项目的前端删除数据要向后端发送 DELETE 请求,需要验证 CSRF 。但是之前项目一直都是 GET 请求获取的数据,浏览器的 cookies 中没有 csrftoken 的值,而发送请求之前是从 cookies 中获取 csrftoken 的值,没有值也就没法通过验证。所以就要人为的设置一下 cookies 中的 csrftoken 值。   出现这个问题的前提是:   1、习惯ajax方式提交POST等请求;   2、习惯从cookie中找csrftoken;   一般我们认为cookie里的csrftoken是由csrftoken middleware所设置的,事实确实如此,但也不完全是。贴一段CsrfViewMiddleware的代码: def process_response(self, request, response): if not getattr(request, 'csrf_cookie_needs_reset', False): if getattr(response, 'csrf_cookie_set', False): return response if not request.META.get("CSRF_COOKIE_USED", False): return response # Set the CSRF cookie

CSRF基础学习

。_饼干妹妹 提交于 2019-12-17 02:10:41
CSRF 上一篇博客说的是XSS跨站脚本攻击,现在说的是另一种跨站攻击,CSRF(Cross-Site Request Forgery),跨站请求伪造。 1、概述 正如其名,CSRF是伪造请求,就是冒充用户在站内进行正常操作。我们知道,绝大多数网站是通过Cookie等方式辨别用户身份(包括使用服务器端Session的网站,因为Session ID也是保存在Cookie里面),再予以授权。这就是为什么要保护好用户的Cookie。所以要想要伪造用户的正常操作,就是要偷Cookie了,那么可能就和上一篇里面说过的XSS优点关联了,利用XSS攻击获取被攻击者的Cookie,在或者就是使用链接欺骗等途径,让用户在本机发起用户所不知道的请求,这里说的本机是拥有Cookie的浏览器端。 2008年时由多个国内外大型社区和交互网站爆出CSRF漏洞,也是让大家聚焦这个漏洞。其实这种攻击方式在2000年就已经被国外的安全人员提出,但是在国内,直到2006年才开始被关注。 2、分类 CSRF漏洞的攻击一般分为站内和站外两种类型。 CSRF站内类型的漏洞一般都是因为程序员滥用 $_REQUEST类变量造成的,一些敏感数据本来应该使用POST请求传参,但是因为使用了 $_REQUEST等变量,程序也可以接受GET类型请求传参,这样无形之中就给攻击者提供了使用CSRF的条件