Inconsistent Behavior of Go’s CGI and FastCGI Transport May Lead to Cross-Site Scripting
Go's CGI and FastCGI transports always set Content-Type to text/html when none is specified, unlike the HTTP server which auto-detects it. An attacker could upload a valid PNG containing JavaScript in a comment field, and when served via CGI/FastCGI, the browser would execute the script as HTML, leading to cross-site scripting.
redteam-pentesting.de
Published on redteam-pentesting.de
neueresZurück zur Übersichtälteres
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
Impact
When other users request the attacker's data, the embedded JavaScript executes and the attacker can interact with the application in the user's name, display arbitrary content, and observe interactions; exploitation requires the application to be served via CGI or FastCGI.
What the attacker needed
Application served via CGI or FastCGI; attacker can upload a file; victim requests the uploaded file
The fix
The CGI and FastCGI implementations were fixed in Go 1.14.8 and 1.15.1 to infer the Content-Type from the response data as documented.
How it was found
- Create a valid PNG file with a JavaScript payload in its comment field.
- Upload the PNG to a web application that validates it as an image and later serves it without setting Content-Type.
- Ensure the application runs via CGI or FastCGI (e.g., behind nginx).
- Request the uploaded file; the server responds with Content-Type: text/html.
- The browser interprets the PNG as HTML and executes the embedded JavaScript.
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.
When a web server sends a file to your browser, it includes a Content-Type header that tells the browser how to treat the file (e.g., as an image or as HTML). Go's standard library normally guesses the type from the file's first bytes, but its CGI and FastCGI modes always say 'text/html'. If a user uploads a picture that also contains JavaScript, and the site serves it through CGI/FastCGI, the browser will run the script as if it were a webpage, letting an attacker steal data or act as the user.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.