Day 9: How I Bypassed Double CSRF Token Validation Using Only an IMG Tag
The application's CSRF protection only checked that the token in the cookie matched the token in the request parameter, without verifying either against the session. An attacker could bypass this by injecting a matching cookie via CRLF injection and submitting a form, allowing unauthorised email changes.
Published on smartpicks4u.medium.com
This lab is similar to the previous one I wrote about. If you read my last story, you know the struggle.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the server compared the CSRF token from the cookie with the one from the request parameter but never validated either against the user's session, so any matching pair was accepted.
Impact
An attacker could change a victim's email address without their consent, potentially leading to account takeover, though the exploit required the victim to visit a malicious page.
What the attacker needed
Victim logged in; victim visits attacker page; CRLF injection in search parameter
The fix
The server should validate the CSRF token against the user's session rather than just comparing two client-supplied values.
How it was found
- Log in and capture the email change request to observe the CSRF tokens.
- Change the request parameter token and see the request fail.
- Change the cookie token to match the modified parameter token and observe success.
- Craft a PoC that injects a matching CSRF cookie via CRLF injection in the search parameter and auto-submits the email change form.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
CSRF (Cross-Site Request Forgery) is when a malicious site tricks a logged-in user's browser into sending a request the user didn't intend, like changing their email. Here, the site tried to stop this by requiring two matching tokens, but it only checked they were equal, not that they were valid. The attacker could set both to the same made-up value and the site accepted it.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.