302 HTTP Response Codes Are Not Always Server-Side Redirects
An endpoint returned a 302 status with a reflected redirect target in the response body, and dropped the Location header whenever the input contained control characters. Because the malformed 302 response was rendered by the browser, a javascript: URL in the reflected parameter executed as script in the page origin.
medium.com
Published on medium.com
You read the title and think, “Is that even possible?” Read this to confirm that a response can return a 302 status without a server-side redirect.
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 application reflected the redirect parameter into the HTML body of a 302 response and, on detecting control characters, removed the Location header instead of rejecting the request, leaving a malformed redirect whose body the browser rendered.
What the attacker needed
Victim visits a crafted link; endpoint reflects redirect value in body
The fix
The endpoint should reject input containing control characters rather than silently dropping the Location header, and should not reflect the redirect target into the response body.
How it was found
- Send a request to the redirect endpoint with a normal URL and observe the 302 with a Location header and a reflected body.
- Add control characters to the redirect value and observe that the Location header is dropped while the body still reflects the value.
- Replace the value with a javascript: URL plus control characters so the reflected link and meta refresh carry the script.
- Load the resulting response in a browser and see the script execute in the page origin.
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 302 is a status code a server sends to tell the browser 'this page has moved, go here instead'. The browser only follows that instruction if the response also includes a Location header naming the destination. Here the server left out that header when the input looked suspicious, so the browser just showed the page body, which contained the attacker's text, and that text could run as code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.