Skip to content
XSS Write-up Intermediate

Using form hijacking to bypass CSP

A CSP configuration that omitted the form-action directive allowed an attacker with an HTML injection vulnerability to hijack forms and send credentials to an external server. The report also describes a real-world example where a Mastodon fork failed to filter HTML, enabling password theft via form hijacking.

portswigger.net

Published on portswigger.net

Form hijacking isn't really a widely known technique; the idea is you have a HTML injection vulnerability that is protected by CSP. Then you use the HTML injection to inject your own form action by using the formaction attribute or injecting your own form to send data to the attackers server.

The author, on portswigger.net

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

The CSP policy did not include the form-action directive, and default-src does not cover form actions, so injected HTML could redirect form submissions to an attacker-controlled server.

Impact

An attacker could steal credentials by hijacking forms, especially if a password manager autofills them, but this requires an HTML injection vulnerability and the impact is limited to sites with a CSP that lacks form-action.

What the attacker needed

HTML injection vulnerability; CSP without form-action directive; Victim visits malicious page

The fix

The CSP should include a form-action directive, ideally set to 'none' or 'self', to prevent forms from submitting to external locations.

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.

A Content Security Policy (CSP) is a set of rules a website sends to your browser to limit what scripts and other resources can run. If the CSP does not include a rule called form-action, an attacker who can inject HTML into a page can change where a form sends its data, potentially stealing your password. This article explains that mistake and how to fix it.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.