相关疑难解决方法(0)

使用相同站点cookie属性防止CSRF

我正在网上冲浪,发现文章使用相同网站的cookie属性预防CSRF.

在链接维护上我们需要添加Set-Cookie标头.

Set-Cookie:key = value; 仅Http; SameSite =严格

现在我的问题是,我想在我的ASP.NET站点中设置所有Cookie和身份验证Cookie.我尝试使用IIS中的标头来设置它,但有人说这是错误的实现方式.

我也在下面尝试过.

HttpCookie newAuthenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName
                    , FormsAuthentication.Encrypt(newAuthenticationTicket))
                {
                    HttpOnly = true
                };
newAuthenticationCookie.Values.Add("SameSite", "strict");
Run Code Online (Sandbox Code Playgroud)

但它似乎没有帮助我.

请建议我更好的方法来做到这一点.

谢谢.

asp.net iis cookies csrf

24
推荐指数
6
解决办法
2万
查看次数

Angular 不随请求发送 cookie

我正在从服务器设置一个仅 http 的 cookie,并且可以看到 cookie 已设置,但是当我向服务器发送请求时,不包含 cookie。

在服务器端 CORS 设置为:

  1. 允许来源:http://localhost:4200
  2. 允许标头:X-Requested-With、Accept、Observe、Content-Type 和 Authorization
  3. 允许方法:GET、POST、HEADER、PUT、DELETE 和 OPTIONS
  4. 允许凭据: true

我可以看到cookie已设置,但设置cookie后向服务器发出的请求不包含cookie。

我如何从服务器请求的示例是:

getUserInfo(): Observable<User> {
    const httpOptions = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json'
        }),
        withCredentials: true
    };

}
Run Code Online (Sandbox Code Playgroud)

如您所见,我已将 withCredentials 设置为 true,但我的 cookie 仍未发送。

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Host: localhost:8080
Origin: http://localhost:4200
Referer: http://localhost:4200/login
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36
Run Code Online (Sandbox Code Playgroud)

我还需要做什么才能发送 cookie?

cookies angular

7
推荐指数
1
解决办法
2569
查看次数

标签 统计

cookies ×2

angular ×1

asp.net ×1

csrf ×1

iis ×1