Sign inTry it

CSRF token

A CSRF token is a secret, unpredictable value that a site embeds in a page or sends in a header. The site checks it on requests that change data. A request forged from another site cannot read the token, so the site can reject it even though the browser sent the user's cookies.

Updated

How it works

  1. The user's browser holds a session cookie for the site.
  2. The site's page includes a token, in a hidden form field, a meta tag or a response header.
  3. When the page sends a change request, it includes the token.
  4. The server compares the token with the value it expects. A missing or wrong token gets the request rejected.

Why it matters for AI agents

Writes on many sites need a current token. A request without one can fail even when the cookies are valid. An agent that makes writes must therefore obtain the token from the same session that sends the request.

The three credentials compared

CredentialWhat it provesSent by
Session cookieYou are logged in to this siteYour browser, automatically
CSRF tokenThe request came from this site's own pagePage code, in a field or header
Bearer tokenThe caller holds a credential for an APIYour code, in the Authorization header

Wield and CSRF tokens

A recipe can read a token from the site's page before its steps run. The recipe format calls this auth.derive. The value is a secret, so Wield replaces it with [redacted] in results, logs and error messages. Any write still waits for your Allow.

FAQ

What is the difference between a CSRF token and an auth token?

A CSRF token proves that a request came from the site's own page. It does not identify the user. An auth token, such as a bearer token, identifies the caller to an API. The two do different jobs, and a site can require one, the other, or both.

Why do POST requests need a CSRF token?

A POST usually changes data: it creates, updates or deletes something. Browsers attach the user's cookies to requests for the site, including requests that another site starts. The token makes such a forged request fail, because the other site cannot read the token.

Sources

  1. CSRF (MDN)developer.mozilla.org
  2. Cross Site Request Forgery (OWASP)owasp.org