How Unsafe GET Requests Enabled CSRF in Early Web AppsHow Unsafe GET Requests Enabled CSRF in Early Web Apps
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
Before REST Ruled the Web: How APIs Used to Break Everything In the early days of building web services, developers frequently treated HTTP as a ๐˜€๐—ถ๐—บ๐—ฝ๐—น๐—ฒ ๐˜๐˜‚๐—ป๐—ป๐—ฒ๐—น for sending requests, using only ๐—š๐—˜๐—ง and ๐—ฃ๐—ข๐—ฆ๐—ง for almost everything. Before REST and strict adherence to HTTP semantic standards (often associated with older RPC-style APIs, SOAP alternatives, or early web apps), this chaotic pattern was extremely common.
So it looked like this:
GET /deleteUser/5 โ† deleting with GET
Even for delete operation, "GET" request was being utilized.
๐—ช๐—ต๐˜† ๐˜„๐—ฒ๐—ฟ๐—ฒ ๐˜๐—ต๐—ฒ๐˜† ๐—ป๐—ผ๐˜ ๐˜‚๐˜€๐—ถ๐—ป๐—ด ๐——๐—˜๐—Ÿ๐—˜๐—ง๐—˜?
Developers werenโ€™t using DELETE (or PUT) for two major reasons:
โ€ข ๐—›๐—ง๐— ๐—Ÿ ๐—™๐—ผ๐—ฟ๐—บ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—Ÿ๐—ถ๐—ป๐—ธ๐˜€ ๐—ข๐—ป๐—น๐˜† ๐—ฆ๐˜‚๐—ฝ๐—ฝ๐—ผ๐—ฟ๐˜๐—ฒ๐—ฑ ๐—š๐—˜๐—ง ๐—ฎ๐—ป๐—ฑ ๐—ฃ๐—ข๐—ฆ๐—ง: For over two decades, standard HTML elements and tags only understood two methods: GET and POST. If you wanted to trigger an action from a standard HTML link or button without writing complex JavaScript, your only options were GET or POST.
โ€ข ๐—Ÿ๐—ฎ๐—ฐ๐—ธ ๐—ผ๐—ณ ๐—”๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฎ๐—น ๐—ฆ๐˜๐—ฎ๐—ป๐—ฑ๐—ฎ๐—ฟ๐—ฑ๐˜€ (๐—ฃ๐—ฟ๐—ฒ-๐—ฅ๐—˜๐—ฆ๐—ง): Before Roy Fielding formalized ๐—ฅ๐—˜๐—ฆ๐—ง in his 2000 dissertation, there was no universal agreement on how HTTP verbs should map to CRUD operations. Developers treated HTTP as a generic transport protocolโ€”like a remote procedure call (RPC), where the URL path described the action (/getUser, /deleteUser), and the HTTP method was just an afterthought.
๐—ฆ๐˜๐—ฒ๐—ฝ ๐Ÿญ: ๐—ฌ๐—ผ๐˜‚ ๐—ฎ๐—ฟ๐—ฒ ๐—ฎ๐—น๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐˜† ๐—น๐—ผ๐—ด๐—ด๐—ฒ๐—ฑ ๐—ถ๐—ป๐˜๐—ผ ๐˜๐—ต๐—ฒ ๐˜๐—ฎ๐—ฟ๐—ด๐—ฒ๐˜ ๐—ฎ๐—ฝ๐—ฝ
Imagine yoursite.com is a banking dashboard or a user management app. Earlier in the day, you logged in with your username and password.
โ€ข Because you successfully logged in, your browser stored a ๐˜€๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป ๐—ฐ๐—ผ๐—ผ๐—ธ๐—ถ๐—ฒ or an ๐—ฎ๐˜‚๐˜๐—ต ๐˜๐—ผ๐—ธ๐—ฒ๐—ป issued by yoursite.com.
โ€ข Your browser is now programmed to automatically attach this cookie/token to ๐˜ฆ๐˜ท๐˜ฆ๐˜ณ๐˜บ ๐˜ด๐˜ช๐˜ฏ๐˜จ๐˜ญ๐˜ฆ ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต it sends to yoursite.com, proving to the server that you are authenticated.
๐—ฆ๐˜๐—ฒ๐—ฝ ๐Ÿฎ: ๐—ฌ๐—ผ๐˜‚ ๐˜ƒ๐—ถ๐˜€๐—ถ๐˜ ๐˜๐—ต๐—ฒ ๐—บ๐—ฎ๐—น๐—ถ๐—ฐ๐—ถ๐—ผ๐˜‚๐˜€ ๐˜€๐—ถ๐˜๐—ฒ
While you are still logged into yoursite.com, you accidentally visit a completely unrelated, malicious website (for example, free-movies-online.com).
๐—ฆ๐˜๐—ฒ๐—ฝ ๐Ÿฏ: ๐—ง๐—ต๐—ฒ ๐—ต๐—ถ๐—ฑ๐—ฑ๐—ฒ๐—ป ๐˜๐—ฟ๐—ฎ๐—ฝ ๐—น๐—ผ๐—ฎ๐—ฑ๐˜€
The malicious website contains this invisible HTML snippet:
HTML
๐—ฆ๐˜๐—ฒ๐—ฝ ๐Ÿฐ: ๐—ง๐—ต๐—ฒ ๐—ฏ๐—ฟ๐—ผ๐˜„๐˜€๐—ฒ๐—ฟ ๐—ฎ๐—ฐ๐˜๐˜€ ๐—ผ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฏ๐—ฒ๐—ต๐—ฎ๐—น๐—ณ
1.Your browser starts downloading all the assets for the malicious page.
It hits the tag and sees a URL pointing to yoursite.com/admin/deleteUser.php?id=42.
Because your browser is stupidly obedient, it says: "๐˜–๐˜ฉ, ๐˜ต๐˜ฉ๐˜ฆ ๐˜ฑ๐˜ข๐˜จ๐˜ฆ ๐˜ธ๐˜ข๐˜ฏ๐˜ต๐˜ด ๐˜ต๐˜ฐ ๐˜ญ๐˜ฐ๐˜ข๐˜ฅ ๐˜ข๐˜ฏ ๐˜ช๐˜ฎ๐˜ข๐˜จ๐˜ฆ ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ ๐˜บ๐˜ฐ๐˜ถ๐˜ณ๐˜ด๐˜ช๐˜ต๐˜ฆ.๐˜ค๐˜ฐ๐˜ฎ. ๐˜“๐˜ฆ๐˜ต ๐˜ฎ๐˜ฆ ๐˜ง๐˜ฆ๐˜ต๐˜ค๐˜ฉ ๐˜ช๐˜ต ๐˜ถ๐˜ด๐˜ช๐˜ฏ๐˜จ ๐˜ข ๐˜Ž๐˜Œ๐˜› ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต."
๐—ช๐—ต๐—ฒ๐—ป ๐˜๐—ต๐—ฒ ๐—ฏ๐—ฟ๐—ผ๐˜„๐˜€๐—ฒ๐—ฟ ๐˜€๐—ฒ๐—ฒ๐˜€ ๐—ฎ ๐—ฟ๐—ฒ๐—พ๐˜‚๐—ฒ๐˜€๐˜ ๐—ด๐—ผ๐—ถ๐—ป๐—ด ๐˜๐—ผ ๐˜†๐—ผ๐˜‚๐—ฟ๐˜€๐—ถ๐˜๐—ฒ.๐—ฐ๐—ผ๐—บ, ๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ๐˜€:
โ€œDo I have any cookies for yoursite.com?โ€
โ€œYes โ†’ attach them.โ€
It does ๐—ป๐—ผ๐˜ carefully check:
โ€ข โ€œWas this request started by a page on yoursite.com?โ€
โ€ข โ€œOr was it started by some random other website?โ€
In the classic cookie model, the browser mainly cares about the ๐—ฑ๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฑ๐—ผ๐—บ๐—ฎ๐—ถ๐—ป, not who initiated the request.
Crucially, because your browser has an active session cookie for yoursite.com, ๐—ถ๐˜ ๐—ฎ๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ฐ๐—ฎ๐—น๐—น๐˜† ๐—ฎ๐˜๐˜๐—ฎ๐—ฐ๐—ต๐—ฒ๐˜€ ๐˜†๐—ผ๐˜‚๐—ฟ ๐˜ƒ๐—ฎ๐—น๐—ถ๐—ฑ ๐˜€๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป ๐—ฐ๐—ผ๐—ผ๐—ธ๐—ถ๐—ฒ ๐˜๐—ผ ๐˜๐—ต๐—ถ๐˜€ ๐—ฏ๐—ฎ๐—ฐ๐—ธ๐—ด๐—ฟ๐—ผ๐˜‚๐—ป๐—ฑ ๐—ฟ๐—ฒ๐—พ๐˜‚๐—ฒ๐˜€๐˜.
๐—ฆ๐˜๐—ฒ๐—ฝ ๐Ÿฑ: ๐—ง๐—ต๐—ฒ ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ ๐—ด๐—ฒ๐˜๐˜€ ๐˜๐—ฟ๐—ถ๐—ฐ๐—ธ๐—ฒ๐—ฑ
The server at yoursite.com receives the request:
โ€ข It looks at the URL: deleteUser.php?id=42
โ€ข It looks at the attached cookies: "๐˜ˆ๐˜ฉ, ๐˜ต๐˜ฉ๐˜ช๐˜ด ๐˜ณ๐˜ฆ๐˜ฒ๐˜ถ๐˜ฆ๐˜ด๐˜ต ๐˜ค๐˜ข๐˜ฎ๐˜ฆ ๐˜ง๐˜ณ๐˜ฐ๐˜ฎ ๐˜”๐˜ถ๐˜ฉ๐˜ข๐˜ฎ๐˜ฎ๐˜ข๐˜ฅ ๐˜š๐˜ข๐˜ญ๐˜ฎ๐˜ข๐˜ฏ ๐˜ˆ๐˜ญ๐˜ช, ๐˜ข๐˜ฏ๐˜ฅ ๐˜ฉ๐˜ฆ ๐˜ช๐˜ด ๐˜ข ๐˜ญ๐˜ฐ๐˜จ๐˜จ๐˜ฆ๐˜ฅ-๐˜ช๐˜ฏ ๐˜ข๐˜ฅ๐˜ฎ๐˜ช๐˜ฏ!"
โ€ข The server assumes ๐˜†๐—ผ๐˜‚ clicked a button intentionally, processes the deletion of user 42, and returns a 1-pixel image (or nothing).
๐—ช๐—ต๐˜† ๐˜๐—ต๐—ฒ ๐—ฎ๐˜๐˜๐—ฎ๐—ฐ๐—ธ๐—ฒ๐—ฟ ๐—ฑ๐—ถ๐—ฑ๐—ป'๐˜ ๐—ป๐—ฒ๐—ฒ๐—ฑ ๐—ฎ ๐—ฝ๐—ฎ๐˜€๐˜€๐˜„๐—ผ๐—ฟ๐—ฑ:
The attacker ๐—ป๐—ฒ๐˜ƒ๐—ฒ๐—ฟ ๐—ต๐—ฎ๐—ฑ ๐˜๐—ผ ๐—ด๐˜‚๐—ฒ๐˜€๐˜€ ๐—ผ๐—ฟ ๐˜€๐˜๐—ฒ๐—ฎ๐—น ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฝ๐—ฎ๐˜€๐˜€๐˜„๐—ผ๐—ฟ๐—ฑ. They didn't even know what your password was. They simply built a trap that forced ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ผ๐˜„๐—ป ๐—ฏ๐—ฟ๐—ผ๐˜„๐˜€๐—ฒ๐—ฟ to use your active, trusted login session against you behind your back.
๐—›๐—ผ๐˜„ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—ฟ๐—ป ๐—ฎ๐—ฝ๐—ฝ๐˜€ ๐—ฝ๐—ฟ๐—ฒ๐˜ƒ๐—ฒ๐—ป๐˜ ๐˜๐—ต๐—ถ๐˜€:
๐—ก๐—ฒ๐˜ƒ๐—ฒ๐—ฟ ๐˜‚๐˜€๐—ฒ ๐—š๐—˜๐—ง ๐—ณ๐—ผ๐—ฟ ๐˜€๐˜๐—ฎ๐˜๐—ฒ-๐—ฐ๐—ต๐—ฎ๐—ป๐—ด๐—ถ๐—ป๐—ด ๐—ฎ๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€: Deleting, updating, or creating data must always use POST, PUT, or DELETE. ๐—–๐—ฆ๐—ฅ๐—™ ๐—ง๐—ผ๐—ธ๐—ฒ๐—ป๐˜€: Modern frameworks include a secret, random token in legitimate HTML forms. When a form is submitted, the server checks if the token matches. A malicious third-party site cannot read or guess this random token, so their hidden or background fetch will fail.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started