express中设置cookie的httpOnly属性防御xss攻击
2017-05-16 10:08
751 查看
大部分是xss攻击(跨站脚本攻攻击),都是尝试在客户的浏览器中注入脚本,然后获取cookie发送到黑客指定的地址。因为服务端的session都是通过一个记录seesionId的cookie来识别的。黑客拿到了cookie, 自然就能够伪造身份,进而获取到权限。cookie的httpOnly属性意味着,浏览器中不能通过document.cookie访问到这个cookie,从而达到防御xss攻击的目的。
在express-session中,默认已经开启了cookie的httpOnly: true,原文说明如下
cookie.httpOnly
Specifies the
for the
When truthy, the
is set, otherwise it is not. By default, the
is set.
但是express本身提供的cookie的api默认值却是false, 需要手动设置为true. 代码如下:
res.cookie('rememberme', '1', {httpOnly: true });
在express-session中,默认已经开启了cookie的httpOnly: true,原文说明如下
cookie.httpOnly
Specifies the
booleanvalue
for the
HttpOnly
Set-Cookieattribute.
When truthy, the
HttpOnlyattribute
is set, otherwise it is not. By default, the
HttpOnlyattribute
is set.
但是express本身提供的cookie的api默认值却是false, 需要手动设置为true. 代码如下:
res.cookie('rememberme', '1', {httpOnly: true });
相关文章推荐
- Cookie设置HttpOnly属性,防止前端脚本更改cookie的XSS攻击
- cookie设置httponly属性防护XSS攻击
- jsp设置cookie的HTTPOnly属性
- cookie 设置 httpOnly属性
- PHP设置COOKIE的HttpOnly属性
- Cookie设置HttpOnly,Secure,Expire属性
- cookie的httponly的设置(可简单仿XSS攻击)
- Cookie设置HttpOnly,Secure,Expire属性
- Cookie的httponly属性设置方法
- Cookie设置HttpOnly,Secure,Expire属性
- cookie 设置 httpOnly属性
- PHP设置Cookie的HTTPONLY属性
- PHP设置Cookie的HTTPONLY属性
- Cookie设置HttpOnly,Secure,Expire属性
- 设置cookie的httponly属性
- PHP设置Cookie的HTTPONLY属性方法
- Tomcat为Cookie设置HttpOnly属性
- PHP设置Cookie的HTTPONLY属性
- cookie的secure、httponly属性设置
- Cookie设置HttpOnly,Secure,Expire属性