csrf

Symfony 1.4: Custom error message for CSRF in forms

喜欢而已 提交于 2019-11-29 14:31:19
问题 Can anyone tell me where/how to customise the CSRF token error message for forms in Symfony 1.4. I'm using sfDoctrineGuard for logins and in this form particularly, whenever a session runs out and you still have the page open, it throws a very user-unfriendly error: "CSRF attack detected". Something like "This session has expired. Please return to the home page and try again" sounds better. What's the right way to do this in the form class? Thanks. 回答1: The only way seems to be to overwrite

Django 1.9 AJAX form CSRF token 403 error - “CSRF cookie not set”

末鹿安然 提交于 2019-11-29 14:29:13
问题 I've seen a lot about this on SO, but nothing can fix my problem. Problem: With CSRF middleware enabled, Django responds with 403 on AJAX form request, stating: "CSRF cookie not set." Following the documentation, a JS functionality was implemented, that sets custom "X-CSRFToken" header. It works as expected, gets "csrftoken" cookie from browser and posts it along with AJAX request: x-csrftoken: 1a0u7GCQG0wepZHQNThIXeYpMy2lZOf2 But response is still 403. Tried solutions: I've tried everything

Django FBV CBV以及使用django提供的API接口

删除回忆录丶 提交于 2019-11-29 14:02:56
FBV 和 CBV 使用哪一种方式都可以,根据自己的情况进行选择 看看FBV的代码 URL的写法: from django.conf.urls import url from api import views urlpatterns = [ # FBV 方式 url(r'asset',views.asset,name='asset'), ] views的函数方法: from django.shortcuts import render,HttpResponse,reverse,redirect import json # Create your views here. # 第一种方式:FBV方式 # 由于post需要csrf校验,所以需要排除csrf校验 from django.views.decorators.csrf import csrf_exempt @csrf_exempt def asset(request): if request.method == "POST": ret = json.loads(request.body.decode('utf-8')) print(ret) return HttpResponse("接收成功") return HttpResponse("OK")   CBV的代码 URL的写法 from django.conf.urls

Laravel 5 TokenMismatchException on PHP 5.6.9

元气小坏坏 提交于 2019-11-29 13:49:51
问题 Post requests work fine running Laravel 5 app on PHP 5.4. Post requests on the same app running on PHP 5.6.9 generate: TokenMismatchException VerifyCsrfToken.php on line 46 This happens on every post request on both WAMP and IIS. Happens using database sessions and file sessions. Did a full reinstall and also tried all suggestions made here: https://laracasts.com/discuss/channels/general-discussion/keep-getting-tokenmismatchexception-verifycsrftokenphp-on-line-46?page=2. Folks are disabling

Cakephp Security

≡放荡痞女 提交于 2019-11-29 13:41:30
问题 I am new to Security of Web apps. I am developing an application in Cakephp and one of my friends told me about the Cross-site request forgery (CSRF) and cross-site scripting (XSS) attacks etc. not sure how many more are there. I need some help in understanding how to make Cakephp defend my web app against these. we are low budget and we cant hire a security consulant as of now. We are still developing the app and plan to release in by the end of the month. so wanna take care of the initial

xss,csrf,SQL注入

扶醉桌前 提交于 2019-11-29 11:54:08
一、Xss 1、定义:跨站脚步攻击,过滤用户表单提交的数据 2、防范措施: a.使用PHP内置函数:htmlspecialchars(),strip_tags,trim,addslashes。 b.PHP所有打印的语句如echo,print等,在打印前都要使用htmlentities() 进行过滤, 这样可以防止Xss,注意中文要写htmlentities($name,ENT_NOQUOTES,GB2312) c.php防注入和XSS攻击通用过滤函数 <?php //php防注入和XSS攻击通用过滤. //by qq:831937 $_GET && SafeFilter($_GET); $_POST && SafeFilter($_POST); $_COOKIE && SafeFilter($_COOKIE); function SafeFilter (&$arr) { $ra=Array('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/','/script/','/javascript/','/vbscript/','/expression/','/applet/','/meta/','/xml/','/blink/','/link/','/style/','/embed/','/object/','/frame/','/layer/','/title/'

External image vulnerabilities

喜欢而已 提交于 2019-11-29 10:39:23
What security holes can appear on my site by including external images via img tag and how to avoid them? I'm currently only checking the extension and mime-type of image on submission (that can be changed after URL is submitted) and URL is sanitized before putting it in src attribute. There's probably a differentiation to be made here between who is at risk. If all you're doing is storing URLs, and not uploading images to your server, then your site is probably safe, and any potential risk is to your users who view your site. In essence, you're putting your trust in the reliability of the

Symfony 2 Add CSRF Token when using a form without a class

耗尽温柔 提交于 2019-11-29 10:31:58
Firstly I'm a complete noobie with Symfony 2. The question sounds simple, if I try and put some context into why and how I need this it will start to get confusing. In essence I've created a form, which I manually process, validate and insert using Doctrine etc. I am manually creating the form within a controller action (it's built dynamically from retrieved values from another object). I'm assuming there maybe better ways to do this, but as I'm new to Symfony and days of trawling the net, I can't see any solutions to what I need to do. Therefore I'm not simply building a form against a class

How to handle CSRF protection with Spring RESTful web services?

余生长醉 提交于 2019-11-29 09:50:58
I have a Spring web application with CSRF protection enabled. I am able to access the RESTful service via AJAX calls, but when I am accessing the service with other applications like httpurlconnection, I get a 401 error (CSRF token null). I understand that to access the RESTful service I need to pass a token in the request header, but how can I get the CSRF token? You can create a mapping in Spring MVC that gets the CSRF token: @RequestMapping(value="/csrf-token", method=RequestMethod.GET) public @ResponseBody String getCsrfToken(HttpServletRequest request) { CsrfToken token = (CsrfToken

CSRF protection by storing nonce in Session variable and form

我的梦境 提交于 2019-11-29 08:34:11
问题 To protect against CSRF you should put a nonce in a hidden field in the form, and in a cookie or in the session variable. But what if the user opens several pages in different tabs? In this case each tab would have a form with a unique nonce, but there would be only one nonce stored in the session variable or cookie. Or if you try to store all the nonces in the cookie/session variable, how would you identify which one belongs to which form? 回答1: You can store the same nonce in each of the