Python's official documentation contains textbook example of insecure code (XSS)
The official Python documentation for the CGI module shows example code that prints user-supplied form values directly into HTML without escaping. An attacker could inject script into a page built from that example, causing cross-site scripting.
seclists.org
Published on seclists.org
The insecure code from the Python developers might have large impact on Python web development as a whole.
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 example code outputs form values into HTML without escaping them, so any HTML or script in the input is rendered by the browser.
Impact
Code copied from this example could expose web applications to XSS; the author notes CGI is deprecated and removed in newer Python versions, but legacy CGI code may remain.
What the attacker needed
Code copied from the example; attacker controls form input
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.
Cross-site scripting (XSS) happens when a website puts user input into a page without cleaning it, so an attacker can make the page run their own script. Here, the Python documentation's sample code takes a name and address from a form and prints them straight into the HTML, so a malicious value would run as script in a visitor's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.