Relative Path File Injection: The Next Evolution in RPO
A technique called Relative Path File Injection (RPFI) allows an attacker to inject malicious content (such as a PDF or shell script) into a page that has a relative download link. When a victim appends a trailing slash to the URL and clicks the download link, the browser downloads the current page (with the injected content) as the file, which then executes when opened.
Published on blog.ionatomics.org
I’ve been working through finding new ways to solve some of the Impossible Challenges Labs that Portswigger posts. During my exploration, I discovered a sibling to the well-known Relative Path Overwrite (RPO) technique, which I have named Relative Path File Injection (RPFI).
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 web server or application does not properly handle URLs with a trailing slash, causing relative paths to resolve incorrectly and the current page to be served instead of the intended file.
Impact
An attacker could execute JavaScript in the context of a locally opened PDF, or run shell commands if the downloaded file is a shell script, but the effectiveness is limited because the execution occurs outside the original site's context.
What the attacker needed
Site with path confusion vulnerability; relative download link with download attribute; ability to inject persistent content; victim clicks crafted URL and download link
The fix
Use a base tag to make all relative paths use a common base URL, or use root-relative paths that begin with a forward slash, and use modern document types.
How it was found
- Find a site with a relative download link and a path confusion vulnerability.
- Inject malicious content (e.g., PDF or shell script) into the page via persistent injection or cache poisoning.
- Craft a URL with a trailing forward slash.
- Get the victim to click the download link on that URL.
- The victim downloads the current page as a file with the correct extension.
- The victim opens the file, executing the injected code.
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.
This is a way to trick someone into downloading a malicious file from a trusted website. The attacker first puts harmful code into a page that has a download link. Then, by adding a slash to the end of the web address, the download link points to the page itself instead of the intended file. When the user clicks download, they get the page (with the harmful code) saved as a file, which runs when opened.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.