Cross-site request forgery
You have probably heard someone say, “Don’t click that link, it might give you a virus!” What could go wrong just from following a link?
Consider a real incident from 2007. David opened a message in Gmail and followed a link. A few days later, he discovered that someone had stolen his domain name. After considerable effort he recovered it and learned that the theft could be traced back to that click.

- David had already signed in to Gmail. His browser held the cookies associated with his session, so Gmail recognized subsequent requests from that browser.
- While that session was active, David followed a link to another site. In the incident described here, a change he had never authorized caused Gmail to forward his mail to an address controlled by someone else.
- The loss of control over his mail also compromised account recovery at the domain registrar. His domain was transferred to the other party.
CSRF stands for cross-site request forgery. A third-party site causes a browser to make a request that uses the visitor’s existing login session at another site. The receiving site can mistake that request for an action the user intended.
A typical CSRF incident involves the following sequence of events:
- A visitor signs in to site A. The browser retains the session cookie.
- The visitor is drawn to site B.
- The browser receives a request originating at B but addressed to A. Depending on the cookie settings, the browser can include credentials for A.
- A recognizes the visitor’s credentials and mistakes possession of those credentials for evidence that the visitor intended the action.
- A carries out the action under the visitor’s account.
- The visitor may remain unaware that someone else caused the action.
Characteristics of CSRF
- The request generally originates on another website. The receiving site cannot control what that site initiates.
- CSRF abuses credentials the victim already holds to submit an action in their name. Its immediate effect is an unauthorized action.
- The other party need never learn the victim’s login credentials. The browser supplies them.
- Browsers can initiate cross-site requests in several ways, including through image URLs, hyperlinks, CORS requests, and form submissions.
Reposted from
- Lion. (14 May, 2020.). 前端安全(同源策略、XSS攻击、CSRF攻击). 稀土掘金. Retrieved January 29, 2024, from https://juejin.cn/post/6844904158697357319