cookie

Template-less Django + AJAX: Does Django's CSRF token get updated during the course of a browsing session?

匿名 (未验证) 提交于 2019-12-03 08:50:26
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: My current setup is AngularJS + Django 1.5 and I have completely thrown away the use of Django's template engine (ie. the backend is pretty much an API server). Since I am not using the csrf_token template tag, Django, in turn, does not set and send the csrftoken cookie in response. As instructed by the official docs, the ensure_csrf_cookie() decorator should be used to force the decorated view to send the csrftoken cookie. I have applied the ensure_csrf_cookie() decorator to the view, which serves the first GET request that my web

django/ajax: Unable to get Ajax post data in the views.py

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I had a problem getting ajax post data from django backend, I don't know how to pass the value, please help. In html I have simply this: <form id="get_vulns_from_family"> <label for="family_content">Enter a family name to display the NVTs</label> <input id="family_content" /> <input type="submit" value="search" /> </form> In javascript I wrote this: $(function() { $("#get_vulns_from_family").submit(function(event) { var family_text = $("#family_content").val(); var family_data = {"family": family_text}; $.ajax({ url: "/template_conf/get

Setting up cookies for Guzzle CookieJar

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am doing unit testing in PHP for a site that requires authentication. Authentication is cookie based, so I need to be able to put a cookie like this in the cookie jar: [ 'user_token' => '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' ] The web application can then use this known good token for the testing data, and will be able to authenticate under testing conditions to interact with the data fixtures. Also, it must be a secure cookie, and I (obviously) need to set the domain. Problem is: I don't know how to make and

Python: Persistent cookie, generate `expires` field

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to generate the text for a persistent cookie in a simple Python web application. I'm having trouble finding a way to generate the expires field. The text format for the field is somewhat complicated, and I'd rather not write code to generate it myself. Is there something in Python that will help? I've cooked at the docs for cookie and cookielib and they seem to handle a lot of the cookie business, except for generating the expires field 回答1: I think you want to do something like this: import Cookie, datetime, uuid ck = Cookie

Set cookie for request in CasperJS

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to load a page using CapserJS, but how can I send cookie which was exported from chrome's http request header at that page? Such as: "SUB=_2AkMjHt3gf8NhqwJRmPkQzG_qZIp_yA3EiebDAHzsJxJTHmMJ7IUyLkMN2K7WzRJvm-Tv3YY0xyZo; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhCT_2hbJ1W1Cc4xfF-mFPo;" 回答1: There are multiple ways, but the easiest would be to use the page.addCookie or phantom.addCookie functions which PhantomJS provides, but you would have to set the domain (and path). Keep in mind that page.addCookie has to be done on a loaded page

Django CSRF cookie HttpOnly

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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? 回答1: A new setting, CSRF_COOKIE_HTTPONLY , is available in Django 1.6+. 回答2: 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

Django jquery ajax 403 error

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to get ajax to work, but I keep getting a 403 error. I am quite new to jquery. The following is my code $ ( '#prod_search_button' ). click ( function (){ if ( $ ( '#inv_prod_list' ). length ) { //insert a new record } else { //create the #inv_prod_list table and insert first record var inv_table = '<table id="inv_prod_list" style="border: 2px solid #dddddd;"></table>' ; // create query object var prod_query = { query : jQuery . trim ( $ ( '#id_prod_query' ). val ()) }; // convert object to JSON data var jsonQuery = JSON

Angular 4 can&#039;t set CSRF-TOKEN in header

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a Spring boot RESTful service with Spring security configured like so: protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity.cors().and() /*.formLogin().loginPage("/auth") .permitAll().and() .authorizeRequests() .anyRequest() .authenticated() .and().httpBasic().and()*/ .csrf() .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .and() .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class); } & public class CsrfHeaderFilter extends OncePerRequestFilter { private static final String

ajax 跨域的解决 cors

匆匆过客 提交于 2019-12-03 08:08:58
package com.leyou.gateway.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.cors.CorsConfiguration;import org.springframework.web.cors.UrlBasedCorsConfigurationSource;import org.springframework.web.filter.CorsFilter;/** * @author li * @time:2018/8/7 * 处理跨域请求的过滤器 */@Configurationpublic class GlobalCorsConfig { @Bean public CorsFilter corsFilter() { //1.添加CORS配置信息 CorsConfiguration config = new CorsConfiguration(); //1) 允许的域,不要写*,否则cookie就无法使用了 config.addAllowedOrigin("http://manager.leyou.com");

XSS攻击(跨站脚本攻击)

岁酱吖の 提交于 2019-12-03 07:41:57
一、什么是XSS?怎么发生的?   XSS(Cross site scripting)全称为 跨站脚本攻击 ,是web程序中最常见的漏洞。指攻击者在网页中嵌入客户端脚本(例如Javascript),当用户浏览此网页时,脚本就会在用户的浏览器上执行,从而达到攻击者的目的。比如获取用户的cookie,导航到恶意网站,携带木马病毒等。    二、XXS漏洞的分类   XXS漏洞按照攻击利用手法的不同,有以下三种类型:    类型A,本地利用漏洞: 这种漏洞存在于页面中客户端脚本自身。其攻击过程如下所示:     Alice给Bob发送了一个恶意构造了web的URL。     Bob点击并查看了这个URL。     恶意页面中的Javascript打开了一个具有漏洞的HTML页面并将其安装在Bob电脑上。     具有漏洞的HTML页面包含了在Bob电脑本地域执行的Javascript。     Alice的恶意脚本可以在Bob的电脑上执行Bob所持有的权限下的命令。    类型B,反射式漏洞: 这种漏洞和类型A有些类似,不同的是web客户端使用server端脚本生成页面为用户提供数据时,如果未经验证的用户数据被包含在页面中而未经HTML实体编码,客户端代码便能够注入到动态页面中。其攻击过程如下:;     Alice经常浏览某个网站,此网站为Bob所拥有