Angular 2 - 在 Angular 2 中使用 csrf 令牌有意义吗?
Angular 2 - It makes sense to use csrf token in Angular 2?
我提出这个问题是因为在客户端服务器应用程序中,服务器发送 html,每个请求的表单中隐藏了不同的令牌。此令牌是通过密钥在服务器上构建的。
但是Angular 2 所有表格都已经在客户端上了。对于包含令牌的表单,他需要一个密钥在客户端中,对我来说这已经是一个安全漏洞。
所以我问这个问题,在 Angular 2 中使用 csrf 令牌是否有意义?如果答案是肯定的,这怎么可能?
Angular 2 包括称为 double-submit cookie pattern. From the Angular documentation、
的 CSRF/XSRF 缓解策略
The Angular http client has built-in support for this technique. The default CookieXSRFStrategy
looks for a cookie called XSRF-TOKEN and sets an HTTP request header named X-XSRF-TOKEN
with the value of that cookie on every request. The server must set the XSRF-TOKEN
cookie, and validate the response header for each state modifying request.
因此,如果您使用 http
服务,则无需在 Angular 端执行任何额外操作即可获得 CSRF 保护。服务器需要检查 header 和 cookie 值是否相同。
我提出这个问题是因为在客户端服务器应用程序中,服务器发送 html,每个请求的表单中隐藏了不同的令牌。此令牌是通过密钥在服务器上构建的。
但是Angular 2 所有表格都已经在客户端上了。对于包含令牌的表单,他需要一个密钥在客户端中,对我来说这已经是一个安全漏洞。
所以我问这个问题,在 Angular 2 中使用 csrf 令牌是否有意义?如果答案是肯定的,这怎么可能?
Angular 2 包括称为 double-submit cookie pattern. From the Angular documentation、
的 CSRF/XSRF 缓解策略The Angular http client has built-in support for this technique. The default
CookieXSRFStrategy
looks for a cookie called XSRF-TOKEN and sets an HTTP request header namedX-XSRF-TOKEN
with the value of that cookie on every request. The server must set theXSRF-TOKEN
cookie, and validate the response header for each state modifying request.
因此,如果您使用 http
服务,则无需在 Angular 端执行任何额外操作即可获得 CSRF 保护。服务器需要检查 header 和 cookie 值是否相同。