How does Angular handle XSS or CSRF?

前端 未结 3 1254
闹比i
闹比i 2020-12-08 07:45

How does Angular (2) handle XSS and CSRF. Does it even handle these attacks? If so, what do I have to do to use this protection? If not, do I have to handle all these attac

3条回答
  •  囚心锁ツ
    2020-12-08 08:24

    Angular2 provides built-in, enabled by default*, anti XSS and CSRF/XSRF protection.

    The DomSanitizationService takes care of removing the dangerous bits in order to prevent an XSS attack.

    The CookieXSRFStrategy class (within the XHRConnection class) takes care of preventing CSRF/XSRF attacks.

    *Note that the CSRF/XSRF protection is enabled by default on the client but only works if the backend sets a cookie named XSRF-TOKEN with a random value when the user authenticates. For more information read up about the Cookie-to-Header Token pattern.

    UPDATE: Official Angular2 security documentation: https://angular.io/docs/ts/latest/guide/security.html (Thanks to Martin Probst for the edit suggestion!).

提交回复
热议问题