Reflected XSS in directory listing pages (privilege escalation via token theft)
Description
Reposilite >= 3.5.16 is affected by reflected Cross-Site Scripting (XSS) in the Maven directory-index page, which reflects the request URI into HTML without encoding.
Details
When a browsed path resolves to a directory, Reposilite serves a generated listing page that interpolates the raw request URI into <title>, <h1>, and the single-quoted href of the <base> and "Parent Directory" <a> elements with no HTML escaping. The listing is served from the same origin as the Admin UI, so injected JavaScript can read the browser's local storage where the user's token (token-secret) is stored.
The content-embedded ctx.uri() is percent-encoded, so tag injection is blocked, but a single quote ' passes through and breaks the anchor's quoted href, letting an attacker attach autofocus and an onfocus= handler that fires on page load (no interaction beyond the victim opening the link).
Unlike artifact and javadoc responses which set Content-Security-Policy: sandbox (the fix for CVE-2024-36115), the directory-index response sets no CSP, so the same-origin restriction does not apply. The unescaped page was introduced in 3.5.16, after that fix.
The directory index only renders for an existing directory, so the attacker-named path must exist. Location.of strips < > " ' : but keeps /, = and letters, so it is plantable with a write/deploy token to a repository or, without a token, via an unauthenticated cached fetch on a store=true repository that proxies an attacker-influenceable upstream.
Steps to reproduce
Default settings, localhost:8080.
- With a write/deploy token, plant the directory by deploying any file under the crafted path: ``
curl -u user:token --upload-file x.txt \ "http://localhost:8080/releases/com/acme/autofocus/onfocus=document.title=PWNED/z/x.txt"`` - Open the crafted link: ``
http://localhost:8080/releases/com/acme'/autofocus/onfocus=document.title='PWNED/z`The Parent-Directory anchor is served as<a href='/releases/com/acme'/autofocus/onfocus=document.title='PWNED'>, which the browser parses as<a href="/releases/com/acme" autofocus onfocus="document.title='PWNED'">.autofocusfiresonfocuson load and the script runs in thelocalhost/%60 origin. A real payload reads localStorage.getItem('token-secret')and exfiltrates it.
<img width="892" height="188" alt="image" src="github.com/
Impact
Same-origin JavaScript can steal the victim's token from local storage. Against a manager token this is full instance compromise. Because the attacker only needs a low-privileged foothold (a CI/deploy token, or content on a proxied mirror) and then phishes a manager into opening the crafted link, this potentially escalates a scoped token to full administrative takeover.
Remediation
- Serve the directory-index response with
Content-Security-Policy: sandbox, the same header already used for artifact and javadoc content. - HTML-escape every value
createDirectoryIndexPageinterpolates (the request URI and file names). - Storing the token in plaintext local storage turns any same-origin XSS into account takeover; consider session tokens instead.