为什么 GET 请求没有 csrf

why no csrf for GET requests

我了解到 GET 请求不需要 CSRF,因为它们被认为是安全的。

但是我能想到的一种情况是这样的攻击:

<img src="https://otherdomain.com/logout" />

如果没有 CSRF,这将很糟糕。当然,可以要求注销路由要求 post,但我经常看到它作为一个简单的 href 实现。

此外,为什么 GET 是安全的?他们仍然在响应中泄露数据...

这是一种只写攻击。来自 OWASP page on CSRF:

CSRF attacks target functionality that causes a state change on the server, such as changing the victim's email address or password, or purchasing something. Forcing the victim to retrieve data doesn't benefit an attacker because the attacker doesn't receive the response, the victim does. As such, CSRF attacks target state-changing requests.

只要 GET 请求不改变状态,它们对黑客就没有价值。

我想您提供的注销示例可能会给用户带来不便,但对黑客没有实际危害,也没有实际好处。