csrf

Django CSRF cookie not set correctly

妖精的绣舞 提交于 2019-11-30 17:17:36
Update 7-18: Here is my nginx config for the proxy server: server { listen 80; server_name blah.com; # the blah is intentional access_log /home/cheng/logs/access.log; error_log /home/cheng/logs/error.log; location / { proxy_pass http://127.0.0.1:8001; } location /static { alias /home/cheng/diandi/staticfiles; } location /images { alias /home/cheng/diandi/images; } client_max_body_size 10M; } Here is nginx.conf : user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay

Django CSRF cookie not set correctly

爷,独闯天下 提交于 2019-11-30 16:30:45
问题 Update 7-18: Here is my nginx config for the proxy server: server { listen 80; server_name blah.com; # the blah is intentional access_log /home/cheng/logs/access.log; error_log /home/cheng/logs/error.log; location / { proxy_pass http://127.0.0.1:8001; } location /static { alias /home/cheng/diandi/staticfiles; } location /images { alias /home/cheng/diandi/images; } client_max_body_size 10M; } Here is nginx.conf : user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker

CSRF Validation Token: session id safe?

跟風遠走 提交于 2019-11-30 15:34:29
问题 In asp.net I am implementing an IHttpModule to mitigate CSRF attacks. It injects into the response html a hidden form parameter with the asp.net SessionID on GETs. On POSTs it then checks to make sure that hidden parameter's value matches the current SessionID. As far as I know, the only way to get the SessionID value is from the cookie, which couldn't be read or determined by the malicious site. Is there anything I am overlooking? 回答1: This approach is correct. You need to make sure that all

Django【十】Ajax

元气小坏坏 提交于 2019-11-30 15:08:31
一、Ajax基本用法 1.简介     AJAX ( Asynchronous Javascript And XML )翻译成中文就是 “ 异步的 Javascript 和 XML” 。即使用 Javascript 语言与服务器进行异步交互,传输的数据为 XML (当然,传输的数据不只是 XML,现在更多使用json数据 )。     AJAX 不是新的编程语言,而是一种使用现有标准的新方法。     AJAX 最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容。( 这一特点给用户的感受是在不知不觉中完成请求和响应过程)     AJAX 不需要任何浏览器插件,但需要用户允许JavaScript在浏览器上执行。       a.同步交互:客户端发出一个请求后,需要等待服务器响应结束后,才能发出第二个请求;       b.异步交互:客户端发出一个请求后,无需等待服务器响应结束,就可以发出第二个请求。   AJAX除了 异步 的特点外,还有一个就是: 浏览器页面 局部刷新 ;( 这一特点给用户的感受是在不知不觉中完成请求和响应过程 2.示例 html页面内容: {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title<

CSRF Protection for Refresh Token Cookie in SPA

*爱你&永不变心* 提交于 2019-11-30 15:07:23
问题 I am using the Resource Owner Password Credentials OAuth 2.0 flow in a AngularJS SPA. There are several articles (here, here..) and the answer to this question that explain that we should not store refresh tokens on the (web) client (LocalStorage), but store them encrypted in an HttpOnly Cookie and use a proxy API where we implement the decryption of the refreh token to forward it to the security token service. Most articles give a hint that we should care about CSRF by using one of the

CSRF Validation Token: session id safe?

倖福魔咒の 提交于 2019-11-30 14:28:10
In asp.net I am implementing an IHttpModule to mitigate CSRF attacks. It injects into the response html a hidden form parameter with the asp.net SessionID on GETs. On POSTs it then checks to make sure that hidden parameter's value matches the current SessionID. As far as I know, the only way to get the SessionID value is from the cookie, which couldn't be read or determined by the malicious site. Is there anything I am overlooking? This approach is correct. You need to make sure that all of the actions available via a GET operation are "safe" (which is best practice anyway), since you're

CSRF Protection for Refresh Token Cookie in SPA

随声附和 提交于 2019-11-30 13:59:09
I am using the Resource Owner Password Credentials OAuth 2.0 flow in a AngularJS SPA. There are several articles ( here , here ..) and the answer to this question that explain that we should not store refresh tokens on the (web) client (LocalStorage), but store them encrypted in an HttpOnly Cookie and use a proxy API where we implement the decryption of the refreh token to forward it to the security token service. Most articles give a hint that we should care about CSRF by using one of the common protection mechanisms. I'm wondering what's the best solution in a Single Page Application. The

Difference between CSRF and X-CSRF-Token

北城以北 提交于 2019-11-30 13:17:21
问题 What is the difference between use X-CSRF-Token in header or token in hidden field ? When use hidden field and when use header and why? I think that X-CSRF-Token is when i'm using javascript/ajax but im not sure 回答1: CSRF protection comes in a number of methods. The traditional way (the "Synchronizer token" pattern) usually involves setting a unique valid Token value for each request and then verifying that unique value when the request is subsequently sent in. It is usually done by setting a

Django之中间件

半世苍凉 提交于 2019-11-30 12:43:06
  一.django中间件()     1.是什么:django 中间件类似django 门户 保安     请求的时候需要先经过中间件才能到达django 后端(urls,vies,templates,)     响应走的时候也是需要经过中间件才能到达web服务网关接口     django 中间件的默认七个门户 ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.com]mon.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] from django.utils.deprecation import MiddlewareMixin

中间件

僤鯓⒐⒋嵵緔 提交于 2019-11-30 12:36:02
一. 中间件的简介   Django默认有七个中间件, 但是Django暴露给用户可以自定义中间件并且里面可以写五种方法   ps: 1.请求来的时候会依次执行每一个中间件里面的process_request方法(如果没有直接跳过)     2. 响应走的时候会依次执行每一个中间件里面的process_response方法(如果没有直接跳过)   Django的生命请求周期: 二. 中间件必掌握的知识点   上面我们已经知道可以自定义一个中间件,于是我们就马不停蹄的来创建一个,首先先了解下怎么去创建一个自定义的中间件,先在settings里面这样设置,因为我们不知道创建中间件所需要继承的父类,所以就要看下源码,那怎么看源码呢,就是我上面所说的在settings先这样复制一下   复制以上任意一个中间件,然后按最上面那种方式,前面加一个from, 中间添加一个import,这样就行了,然后用鼠标点击最后面的SecurityMiddleware,点进去就能看见这个是继承的哪个类,多话不说,我先创建一个类,看下图: 这就是我自定义的一个中间件,我们再视图函数写一个程序,运行结果如下:   通过运行结果可以看出,不管怎么样,都首先是执行我自定义的中间件函数的,那我们如果在中间件里面返回一个HTTPresponse对象,那结果会如何呢,闲话不说,看下面图   结果又是什么样子的呢?看下图