csrf

Pass Django CSRF token to Angular with CSRF_COOKIE_HTTPONLY

不想你离开。 提交于 2019-12-01 02:52:53
问题 In Django, when the CSRF_COOKIE_HTTPONLY setting is set to True, the CSRF cookie gains the httponly flag, which is desirable from a security perspective, but breaks the standard angular solution of adding this cookie to the httpProvider like so: $httpProvider.defaults.xsrfCookieName = 'csrftoken'; $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; Through Django 1.9, there was a workaround where you could just pass the cookie directly to the app by putting this in the template: <script>

what is the use of anti-forgery token salt?

浪子不回头ぞ 提交于 2019-12-01 02:31:38
In ASP.NET MVC 1.0, there is a new feature for handling cross site request forgery security problem: <%= Html.AntiForgeryToken() %> [ValidateAntiForgeryToken] public ViewResult SubmitUpdate() { // ... etc } I found the token generated in html form keep changing every time a new form is rendered. I want to know how these token is generated? And when use some software to scan this site, it will report another security problem: Session fixed. Why? Since the token keep changed, how can this problem come ? And there is another function, that is "salt" for the antiForgeryToken , but I really know

AngularJS can't find XSRF-TOKEN cookie

放肆的年华 提交于 2019-12-01 00:43:21
I'm using angular 1.0.4 with an ASP.NET MVC4 + Web API project. I'm trying to leverage angular's CSRF protection to no avail. I can see that I'm passing along a cookie named XSRF-TOKEN, but when angular tries to add the value as a header named X-XSRF-TOKEN in the response, the value appears as undefined. I tried following the advice here , but the HTML has yet to render, so no element is found. What might I be missing? Is the RequestVerificationToken cookie generated by ASP.NET MVC protected from javascript access? Also, is it possible to have angular lazily retrieve either the cookie or form

Protection against CSRF and XSS (Hashing + Encrypting)

隐身守侯 提交于 2019-11-30 23:12:57
Security. Today, no application can survive the internet if it does not have proper security programmed into it - either by the framework used by the developer, or by the developer himself. I am currently developing a RESTful API to work using Bearer token authentication but have been reading about XSS and CSRF attacks. Question 1) From what I've read, I see that applications consuming RESTful APIs that use token-based authentication are vulnerable to XSS and not CSRF if the token is stored in localStorage/sessionStorage of the browser instead of in cookies. This is because, for CSRF to work,

nodejs的数据上传与安全

青春壹個敷衍的年華 提交于 2019-11-30 21:58:09
  Node提供了相对底层的API,通过它构建各种各样的Web应用都是相对容易的,但在Web应用中,不得不重视数据上传相关的安全问题。由于Node与前端Javascript的近缘性,前端Javascript甚至可以上传至服务器直接执行,但在这里我们并不讨论这样危险的动作,而是介绍内存和CSRF相关的安全问题。   1. 内存限制   在解析用户提交的表单、JSON和XML的时候,我们采取的策略是先保存所有数据,然后再解析处理,最后才传递给业务逻辑。这种策略存在潜在的问题是,它仅仅适合数据量小的提交请求, 一旦数据量过大,将发生内存被占光的情况。攻击者通过客户端能够十分容易地模拟伪造大量数 据,如果攻击者每次提交1 MB的内容,那么只要并发请求数量一大,内存就会很快地被吃光。   要解决这个问题主要有两个方案。    限制上传内容的大小,一旦超过限制,停止接收数据,并响应400状态码。    通过流式解析,将数据流导向到磁盘中,Node只保留文件路径等小数据。   首先介绍一下 Connect 框架中采用的上传数据量的限制方式,如下所示:   const bytes = 1024; (req, res) => { let received = 0, const len = req.headers['content-length'] ? parseInt(req.headers[

How to enable Spring Security POST redirect after log in with CSRF?

£可爱£侵袭症+ 提交于 2019-11-30 21:12:37
I'm using Spring Security 3.2 with CSRF. My configuration includes this: <csrf /> <form-login default-target-url="/defaultPage"/> When the user does a POST form submit (with a CSRF token) that requires authentication, he is redirected to the log in page. Afterwards, instead of submitting the request, the user is redirected to the defaultPage by Spring Security. I suspect the issue is that the CSRF token gets reset during log in. How can I get such a POST redirect after log in working? Update : I tried to create a custom SavedRequestAwareAuthenticationSuccessHandler to redirect to the original

WTForms

淺唱寂寞╮ 提交于 2019-11-30 21:01:34
文章出处 https://www.cnblogs.com/wupeiqi/articles/8202357.html 简介 W TForms是一个支持多个web框架的form组件,主要用于对用户请求数据进行验证。 安装: ? 1 pip3 install wtforms 用户登录注册示例 1. 用户登录 当 用户登录时候,需要对用户提交的用户名和密码进行多种格式校验。如: 用户不能为空;用户长度必须大于6; 密码不能为空;密码长度必须大于12;密码必须包含 字母、数字、特殊字符等(自定义正则); #!/usr/bin/env python # -*- coding:utf-8 -*- from flask import Flask, render_template, request, redirect from wtforms import Form from wtforms.fields import core from wtforms.fields import html5 from wtforms.fields import simple from wtforms import validators from wtforms import widgets app = Flask(__name__, template_folder='templates') app.debug

Laravel CSRF Token

我是研究僧i 提交于 2019-11-30 19:22:22
EDIT: I should have said this at the start, I'm using AngularJS in the FronEnd, and I'm making all the request via XHR. I'm developing an Application using CSRF Token for every user request. Should I regenerate the Token after each request? Something like Session::forget("_token") and Session::put("_token", RANDOM_SOMETHING) Or is it enough to use the same one each user Session ? Is there any benefit? With Laravel 5 using Blades templates, it's pretty easy. If you only want the value of the csrf token, you can generate it by writing: {{ csrf_token() }} which generates the token value like this

Django CSRF cookie HttpOnly

江枫思渺然 提交于 2019-11-30 18:28:50
Is it possible to set the django csrf cookie to be http-only? Alike to SESSION_COOKIE_HTTPONLY with session cookie, but for the csrf one? A new setting, CSRF_COOKIE_HTTPONLY , is available in Django 1.6+. For Django1.6+, check the accepted answer. For Django1.5 and prev, there is not setting option for this. You could override the process_response() method of django.middleware.csrf.CsrfViewMiddleware and using the customized one instead of CsrfViewMiddleware in MIDDLEWARE_CLASSES class Foo(CsrfViewMiddleware): def process_response(self, request, response): response = super(Foo, self).process

Prevent CSRF in JSF2 with client side state saving

纵饮孤独 提交于 2019-11-30 17:41:35
问题 I'm Using MyFaces 2.2.3 with client side state saving + PrimeFaces After asking how to prevent the re-use of a ViewState in different sessions I was told by BalusC , that I can inject my own CSRF token by override the from renderer to let the value be a CSRF token , I'm looking for a solution that wont force me to modify my xhtml pages at all :) BalusC has suggested a better way to prevent CSRF attack by extending ViewHandlerWrapper , and it works great, I only had to modify a bit the