Cross-Site Scripting with a Twist
A PHP script echoed the PHP_SELF server variable without escaping, so a crafted URL path could inject script into the page. An attacker could use this to run JavaScript in a victim's browser.
medium.com
Published on medium.com
PHP is a well-known programming language, even though it has been on the market since 1994, it is still widely used for developing web applications.
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
An attacker could inject script that runs in a victim's browser, though the text gives no concrete attack scenario beyond reflection.
What the attacker needed
Victim visits a crafted URL
The fix
The value should be escaped with htmlspecialchars before being printed, as the non-vulnerable example shows.
How it was found
- Open the test PHP script that echoes PHP_SELF.
- Add extra data after the parameter in the browser's URL bar.
- Observe that the added data is reflected in the page output.
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.
PHP_SELF is a value PHP fills in with the path of the current script. If a page prints it straight into the HTML without cleaning it, an attacker can put extra characters in the URL that the browser treats as code. That lets the attacker run their own JavaScript in the victim's browser, which is called cross-site scripting.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.