csrf

Flask之WTForms

萝らか妹 提交于 2020-01-30 05:38:13
Flask之WTForms 简介 WTForms是一个支持多个web框架的form组件,主要用于对用户请求数据进行验证。 安装: 1 pip3 install wtforms 用户登录注册示例 1. 用户登录 当用户登录时候,需要对用户提交的用户名和密码进行多种格式校验。如: 用户不能为空;用户长度必须大于6; 密码不能为空;密码长度必须大于12;密码必须包含 字母、数字、特殊字符等(自定义正则); app.py #!/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 = True class LoginForm(Form): name =

常见六大Web安全攻防解析

大兔子大兔子 提交于 2020-01-28 12:49:55
转自:https://www.cnblogs.com/fundebug/p/details-about-6-web-security.html 一、XSS XSS (Cross-Site Scripting),跨站脚本攻击,因为缩写和CSS重叠,所以只能叫XSS。跨站脚本攻击是指通过存在安全漏洞的Web网站注册用户的浏览器内运行非法的HTML标签或JavaScript进行的一种攻击 跨站脚本攻击有可能造成以下影响: 利用虚假输入表单骗取用户个人信息 利用脚本窃取用户的Cookie值,被害者在不知情的情况下,帮助攻击者发送恶意请求 显示伪造的文章或图片 XSS的原理是恶意攻击者往Web页面里插入恶意可执行网页脚本代码,当用户浏览该页之时,嵌入其中Web里面的脚本代码会被执行,从而可以达到攻击者盗取用户信息或其他侵犯用户安全隐私的目的 XSS的攻击方式千变万化,但还是可以大致细分为几种类型 1.非持久型XSS(反射型XSS) 非持久型XSS漏洞,一般是通过给别人发送 带有恶意脚本代码参数的URL ,当URL地址被打开时,特有的恶意代码参数被HTML解析、执行 举一个例子,比如页面中包含有以下代码: <select> <script> document.write('' + '<option value=1>' + location.href.substring(location

Django之路——9 Django的form组件的信息校验

给你一囗甜甜゛ 提交于 2020-01-28 06:31:19
forms组件 校验字段功能 针对一个实例:注册用户讲解。 模型:models.py class UserInfo(models.Model): name=models.CharField(max_length=32) pwd=models.CharField(max_length=32) email=models.EmailField() tel=models.CharField(max_length=32) 模板: register.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="" method="post"> {% csrf_token %} <div> <label for="user">用户名</label> <p><input type="text" name="name" id="name"></p> </div> <div> <label for="pwd">密码</label> <p><input type="password" name="pwd" id="pwd"></p> </div> <div> <label for="r_pwd">确认密码</label> <p>

Grails 3 CSRF protection

感情迁移 提交于 2020-01-28 05:25:25
问题 Is it possible to configure CSRF protection in grails3 app using spring-security plugin, I can't find anything except useToken attribute for grails form and then call withForm inside controller. But this is actually not a very flexible solution. I like approach with filter like here 回答1: For csrf protection I reused org.springframework.security.web.csrf.CsrfFilter . You need to define new bean in grails resouces.groovy (See snipet below - csrfFilter bean). You can define your own

Is it possible to have CSRF if developer mitigates by referrer header

空扰寡人 提交于 2020-01-26 03:44:07
问题 After pentration testing, developer mitigates the CSRF vulnerability by using only referrer header. The application have other vulnerability like XSS. Is it possible to exploit CSRF with the help of XSS? if yes how? 回答1: Short story: Its very difficult to design effective CSRF protection when XSS is present. Mitigation of CSRF via referrer header is generally considered a weak defense - there are situations where these are stripped (by the browsers or proxies) and you would need to fail these

What is the difference between XSS and CSRF from their execution perspective?

跟風遠走 提交于 2020-01-26 01:02:52
What is the difference between XSS and CSRF from their execution perspective? https://www.quora.com/What-is-the-difference-between-XSS-and-CSRF-from-their-execution-perspective/answer/Deepthi-210 Fundamental difference is that CSRF (Cross-site Request forgery) happens in authenticated sessions when the server trusts the user/browser, while XSS (Cross-Site scripting) doesn't need an authenticated session and can be exploited when the vulnerable website doesn't do the basics of validating or escaping input. In case of XSS, when the server doesn't validate or escapes input as a primary control,

how to change csrf field id from YII_CSRF_TOKEN to any other

别等时光非礼了梦想. 提交于 2020-01-24 10:30:55
问题 i am using Get method for form post but i am not interested if person could see if i am using yii framework. So instead of using YII_CSRF_TOKEN i need to make my own defined id name e.g. like only TOKEN. I don't want to reveal what framework i am using , any kind of tip or help ??? 回答1: in your application config add the below code 'request'=>array( 'csrfTokenName'=>'YOUR_TOKEN_NAME_HERE', ), 来源: https://stackoverflow.com/questions/11809448/how-to-change-csrf-field-id-from-yii-csrf-token-to

Rails Integration Testing - How to Simulate bad CSRF token and Expired Session

核能气质少年 提交于 2020-01-23 22:47:08
问题 I just changed exception handling code in my application_controller.rb to correctly capture ActionController::InvalidAuthenticityToken . I was previously doing a rescue_from Exception that was defined after the recuse_from ActionController::InvalidAuthenticityToken. This was taking priority and my intended rescue_from code was not being executed. I'd like to write an integration test to verify this behavior. How can I create an object that will allow me to send a bad CSRF token to a post

Completely disable Django's CSRF protection in SVN Trunk

点点圈 提交于 2020-01-23 17:39:06
问题 I've spend a few hours in frustration, trying to disable the CSRF which Django now tries to force on me, to no avail. Had anyone else tried this with more success? I'm fine with anything that works, except for a source patch (but monkeypatches are okay). 回答1: Don't do it. But if you must, try this. 回答2: I haven't actually tried to disable it (never had the need), but I imagine it's just a matter of removing the CSRF middleware(s) from the MIDDLEWARE_CLASSES setting in your settings.py. 回答3:

vue+django前后端分析解决csrf token问题

▼魔方 西西 提交于 2020-01-23 02:21:52
vue-resource post数据 参考:https://www.cnblogs.com/linxizhifeng/p/8995077.html 阅读django CsrfViewMiddleware源码可知,csrftoken可以放在请求参数(csrfmiddlewaretoken)里面或者请求头(X-CSRFToken)里: # Check non-cookie token for match. request_csrf_token = "" if request.method == "POST": try: request_csrf_token = request.POST.get('csrfmiddlewaretoken', '') except IOError: # Handle a broken connection before we've completed reading # the POST data. process_view shouldn't raise any # exceptions, so we'll ignore and serve the user a 403 # (assuming they're still listening, which they probably # aren't because of the error).