Skip to content
CSRF Write-up Beginner

Breaking Hacker News's CSRF Protections

The CSRF token on Hacker News login and submission forms can be obtained by first fetching the form page, so an attacker can automate login and posting by including a fresh token in each request. This allows brute-force password cracking and automated posting despite the CSRF protection.

hankstoever.com

Published on hankstoever.com

This approach is almost useless, because the 'attacker' only requires one extra request to obtain a valid token. I'm going to demonstrate how this can be done on hacker news to sign in.

The author, on hankstoever.com

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 CSRF token is not tied to the user's session or origin, so any client can fetch a valid token and use it immediately.

Impact

An attacker could automate login attempts (brute-force password cracking) and posting to Hacker News, bypassing the CSRF protection.

What the attacker needed

Valid username and password; ability to send HTTP requests

The fix

The text suggests that CSRF protection is ineffective for this purpose and recommends removing it to allow easier API creation, but does not provide a technical fix.

How it was found

  1. Send a GET request to the login page to retrieve the HTML form.
  2. Extract the value of the fnid input field from the form.
  3. Send a POST request to the login endpoint with the username, password, and the extracted fnid.
  4. Check for a Set-Cookie header in the response to confirm successful login.
  5. Use the obtained cookie to access authenticated pages and extract new fnid tokens for further actions.

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 tokens are meant to stop other websites from submitting forms on your behalf. Here, the token is handed out freely to anyone who asks for the form first, so a script can grab it and then submit the form with valid credentials. This means the protection does not stop automated login attempts or posting.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.