Blog

CSRF and Your Contact Form: What You Actually Need to Know

CSRF sounds scary, but a public contact form has a very different risk profile than an authenticated settings form. Here's what actually matters for each.

← Back to the blog
AI Powered

Explore this article with AI

Get an instant summary, key takeaways, action items, and answers to your questions about this article.

Choose your AI assistant
ChatGPT Perplexity
Quick answer

CSRF (Cross-Site Request Forgery) tricks a logged-in user's browser into submitting a request they didn't intend to make, using their existing session. A public contact form with no login has no session to hijack, so CSRF matters much less there than on authenticated forms like account settings, where the same trick could change a password or email address without the user's knowledge.

What CSRF actually is

Cross-Site Request Forgery is a trick, not a break-in. It doesn't steal your password or bypass your login — it abuses the fact that your browser automatically attaches your session cookies to any request sent to a site you're logged into, regardless of which page told your browser to send that request. If an attacker gets you to load a page (or an image tag, or an auto-submitting form) that fires a request at a site where you're already logged in, that request goes out carrying your session, looking completely legitimate to the server.

Why it matters less for a plain contact form

A public contact form doesn't require login. There's no session to ride along on, and no account-level action being performed. If someone forges a submission to your contact form from another page, the worst outcome is an unwanted message landing in your inbox — annoying, but functionally indistinguishable from spam. It's not nothing, but it's not the kind of security incident CSRF protection exists to prevent, and it's better addressed with the spam-protection tools you'd use anyway (CAPTCHA, honeypot fields, rate limiting).

Why it matters more once there's a session behind it

The picture changes completely once a form performs an authenticated action — updating an email address, changing a password, modifying billing details. Now a forged request isn't just noise; it's an attacker using a logged-in user's own session to make a change on their behalf, without them ever entering credentials or seeing what happened. This is the scenario CSRF protection is actually built for, and it's worth taking seriously anywhere a form sits behind a login and changes something that matters.

The standard mitigations

The practical takeaway: don't skip CSRF thinking entirely just because your public form is low-risk, but don't over-engineer a contact form either — save the token-based defense for the forms that actually sit behind a login and do something sensitive.

Frequently asked

Do I need CSRF protection on a simple public contact form?

Generally not for the classic CSRF risk, since there's no authenticated session to abuse — the worst a forged submission can do is send you an unwanted message, which is really a spam problem rather than a security breach. It's still reasonable to add basic origin checking, but token-based CSRF protection is more relevant once a form performs an authenticated, sensitive action.

What are the standard ways to mitigate CSRF?

The two common approaches are checking the request's Origin or Referer header against your own domain, and issuing a unique CSRF token when the form is rendered that must be submitted back and validated server-side. Origin checking is simpler and often sufficient for lower-risk forms; token validation is the stronger, standard defense for authenticated, sensitive actions.

Key facts

  • CSRF (Cross-Site Request Forgery) exploits a logged-in user's existing session by tricking their browser into submitting an unintended request to a site they're authenticated with.
  • A public contact form with no login has no session for CSRF to exploit, making it a much lower-risk target than authenticated forms like account settings.
  • Standard CSRF mitigations are Origin/Referer header checking and per-request CSRF tokens validated server-side.

Terms in this post

CSRF (Cross-Site Request Forgery)
An attack that tricks a logged-in user's browser into unknowingly submitting a request to a site they're authenticated with, riding on their existing session cookies rather than stealing credentials directly.

Get the next one in your inbox.

One email when we publish something worth reading. No spam — appropriately enough, we'd know.