Persistent XSS: Editor link
The editor link setting accepted a javascript: scheme with a newline inserted between 'javascript' and ':', bypassing the check in phutil_tag. An attacker could set this value on a victim's account (via temporary account takeover or login CSRF) so that clicking the Edit link executes arbitrary JavaScript.
- Fixed in 33 hours
- Paid in 33 hours
- Disclosed after 31 days
The editor link used for external applications allows scheme other than http: or https:. Although the phutil_tag function checks whether the scheme is javascript: to prevent XSS attacks (see GitHub), it is straightforward to bypass this check by adding a whitespace character in between javascript and :. For instance, clicking a link with the following value for the href attribute will execute arbitary JavaScript code:
javascript
:alert('xss')
(note the newline character between javascript and :).
Replication steps:
- Go to
settings/panel/display/ - Press "Save" with network panel of console active
- Copy the POST request as cURL
- Use
curlto set theeditorparameter tojavascript%0A%3Aalert%281%29(this is not possible to do in the browser as it strips these characters from input fields) - Go to a repository, and click "Edit", you should now see an alert box pop up
Attack scenarios
Although the JavaScript code will only be executed on the user's own account, several attack scenarios are possible:
- A temporary account take-over would allow the attacker to set the editor link to include JavaScript code. Even when the victim manages to recover his account, clicking on the "Edit" link will give the attacker again control over the account.
- Several login-csrf were found in Phabricator, so an attacker could have abused this (or abuse it if a similar issue arises) to login the victim into his account. The attacker could use the XSS to trick the victim into entering his own credentials
Proposed fix
In the phutil_tag function, first filter all non-alphanumerical characters of $href and then check whether it starts with javascript:.
Context
Phabricator is a suite of web-based development tools, and the report concerns its user settings, specifically the editor link used for external applications. That setting lets a user configure a link that Phabricator renders so the user can jump out to an external editor. Because the value ends up in an href attribute, the scheme it contains matters: a link that starts with javascript: would run script in the page when clicked.
The report shows that the editor link accepted schemes other than http: and https:, and that the existing scheme check could be bypassed, producing persistent cross-site scripting.
Setup
The researcher sent a crafted request outside the browser, because the browser strips the characters needed for the payload from input fields. The browser itself strips the characters needed for the payload from input fields, so the value has to be submitted with curl instead. No special role or privilege is described.
Finding it
The starting point is the phutil_tag function, which checks whether a scheme is javascript: in order to prevent XSS attacks. The researcher linked to the relevant code in libphutil. The check is straightforward to bypass by placing a whitespace character between javascript and :. Clicking a link whose href has the following value executes arbitrary JavaScript:
javascript
:alert('xss')
Note the newline character between javascript and :. The scheme comparison does not match the value, but the browser still treats the attribute as a JavaScript URL.
Exploitation
Step 1: Open the display settings
Go to settings/panel/display/, the panel that holds the editor link setting.
Step 2: Capture the save request
Press "Save" with the network panel of the console active, then copy the resulting POST request as cURL. This gives a request that can be replayed with modified parameters.
Step 3: Set the editor parameter with curl
Use curl to set the editor parameter to the following value:
javascript%0A%3Aalert%281%29
This is the URL-encoded form of javascript, a newline, :alert(1). The report notes that this is not possible to do in the browser, because the browser strips these characters from input fields.
Step 4: Trigger the payload
Go to a repository and click "Edit". An alert box pops up, confirming that the stored value is rendered as a link and that the JavaScript executes.
Root cause
The editor link is rendered into an href attribute, and the only defence is the scheme check inside phutil_tag. That check compares the scheme against javascript: but does not normalise the value first, so a whitespace character between the scheme name and the colon slips past it while the browser still interprets the attribute as a JavaScript URL. The value is saved in the editor setting, which makes the issue persistent rather than reflected.
Impact
The JavaScript executes on the user's own account, which limits the direct blast radius. The report sets out two scenarios in which that is still useful to an attacker:
- A temporary account take-over would let the attacker set the editor link to include JavaScript code. Even when the victim recovers the account, clicking the "Edit" link gives the attacker control over the account again.
- Several login CSRF issues were found in Phabricator, so an attacker could have abused one, or a similar future issue, to log the victim into the attacker's account. The attacker could then use the XSS to trick the victim into entering their own credentials.
Fix
The proposed fix is in the phutil_tag function: first filter all non-alphanumerical characters from $href, then check whether it starts with javascript:. Removing the non-alphanumerical characters before the comparison means whitespace and similar characters can no longer sit between the scheme name and the colon when the check runs.
Variants to test
- Try other whitespace and control characters between the scheme name and the colon, not just the newline used here, and see whether the stored link still executes when clicked.
- Try other schemes that browsers may treat as script or as dangerous navigation, and check whether the allow-list really only permits
http:andhttps:. - Try the same bypass wherever a user-supplied URL is rendered into an
href, such as profile links, external application links and similar settings fields. - Submit values through the API or a direct request rather than the browser form, since the browser strips the characters that make the bypass work.
A positive result is a stored value that survives the save, is rendered back into the page, and executes or navigates unexpectedly when clicked.
Hunting notes
This kind of bug hides in settings fields that store a URL and later render it as a link, especially where a scheme check exists but is applied to the raw string. During recon, look for features that let users configure external links, editors or integrations, and inspect how the value is validated on save and how it is emitted on render. The researcher demonstrated impact by showing the alert on the "Edit" link and by tying the persistence to account take-over and login CSRF scenarios.
What happened, in plain words
Phabricator is a suite of web-based development tools. One of its settings holds the editor link used for external applications. Phabricator stores a link to that editor and shows it on the page so the user can click it and jump out to the editor.
Because that link is placed into a web page as a clickable link, the text of the link matters. A normal link starts with http: or https:, which tells the browser to fetch a web page. But browsers also understand a special kind of link that starts with javascript:. When you click such a link, the browser does not fetch anything: it runs the text after the colon as a small program, called JavaScript, inside the page you are looking at. That is exactly what cross-site scripting (XSS) is: getting your own code to run inside someone else's web page, with the same trust the page has.
Phabricator tried to stop this. A helper function called phutil_tag, which builds HTML tags safely, checked whether a link started with javascript: and refused it if so. The researcher found that the check could be fooled by putting a line break (a newline character) between the word javascript and the colon. The check compared the raw text and did not match, but the browser still treated the link as JavaScript and ran it when clicked.
Worse, the value was saved on the server. That makes it persistent: it stays there and runs again every time the page is loaded and the link is clicked, not just once.
Background you need
A few ideas come up again and again below, so here they are from scratch.
- HTML attribute: a web page is written in a language called HTML. Elements can carry extra information in attributes, written as
name="value". A link element (<a>) has anhrefattribute that holds the address the link points to. Whatever ends up inhrefis what the browser acts on when the link is clicked. - URL scheme: the first part of an address, before the colon.
https://example.comhas the schemehttps:.javascript:alert(1)has the schemejavascript:. The scheme tells the browser what kind of address it is and therefore what to do with it. - JavaScript: the programming language that runs inside web pages in your browser. It can read and change the page, and it can act as the logged-in user.
- XSS (cross-site scripting): a bug where an attacker manages to get their JavaScript to run in another person's browser session on a website. The browser cannot tell the difference between the site's own code and the injected code, so the injected code can do anything the user could do.
- Persistent XSS: the malicious value is stored on the server (in a database, a setting, a comment) and served back to browsers later. It keeps working on every visit until it is removed. The opposite, reflected XSS, only bounces back once from a single request.
- URL encoding: some characters cannot travel safely inside a web request, so they are written as a percent sign followed by two hexadecimal digits. A newline becomes
%0A, a colon becomes%3A, and so on. The server decodes them back to the original characters when it reads the request. - POST request: when you submit a form, the browser usually sends a POST request, which carries the form's values in its body rather than in the address bar.
- curl: a command-line program for sending web requests by hand. It lets you send exactly the request you want, without a browser cleaning it up first.
- CSRF (cross-site request forgery): a bug where another website can make your browser send a request to a site you are logged into, without you meaning to. A login CSRF is a variant that logs you into the attacker's account instead of your own.
Setting up
The researcher needed the ability to send a request outside the browser. No special role or administrator privilege is mentioned. The reason for going outside the browser is important: browsers clean up what you type into form fields and strip characters such as newlines, so the payload cannot be typed in directly. Sending the request by hand with curl skips that cleanup.
Finding the flaw
The starting point is the phutil_tag function, which checks whether a scheme is javascript: in order to prevent XSS attacks. The researcher pointed to the relevant code in libphutil, the shared library Phabricator uses. The check is easy to get around by placing a whitespace character between javascript and :. Clicking a link whose href has the following value runs arbitrary JavaScript:
javascript
:alert('xss')
Line by line: the first line is the word javascript. The second line starts with a newline character (the line break between the two lines), then a colon, then alert('xss'), which is JavaScript that opens a pop-up box showing the text xss. The report notes the newline character between javascript and :. The scheme comparison does not match the value, but the browser still treats the attribute as a JavaScript URL.
Exploitation
Step 1: Open the display settings
Go to settings/panel/display/, the panel that holds the editor link setting. This is where a normal user would type the address of their external editor.
Step 2: Capture the save request
Press "Save" with the network panel of the browser's developer console active, then copy the resulting POST request as cURL. The network panel is a built-in browser tool that lists every request the page makes. Copying the request as cURL gives you a ready-made command that repeats exactly what the browser sent, which you can then edit and replay. This step is done so that the request can be modified in ways the form would not allow.
Step 3: Set the editor parameter with curl
Use curl to set the editor parameter to the following value:
javascript%0A%3Aalert%281%29
Line by line: this is the URL-encoded form of javascript, a newline, then :alert(1). %0A is the newline, %3A is the colon, %28 is (, %29 is ). The report notes that this cannot be done in the browser, because the browser strips these characters from input fields.
Step 4: Trigger the payload
Go to a repository and click "Edit". An alert box pops up, which confirms that the stored value is rendered as a link and that the JavaScript runs.
Root cause
The editor link is rendered into an href attribute, and the only defence is the scheme check inside phutil_tag. That check compares the scheme against javascript: but does not normalise the value first, so a whitespace character between the scheme name and the colon slips past it while the browser still reads the attribute as a JavaScript URL. The value is saved in the editor setting, which makes the issue persistent rather than reflected.
Impact
The JavaScript runs on the user's own account, which limits how far it reaches directly. The report sets out two scenarios in which it is still useful to an attacker:
- A temporary account take-over would let the attacker set the editor link to include JavaScript code. Even when the victim recovers the account, clicking the "Edit" link gives the attacker control over the account again.
- Several login CSRF issues were found in Phabricator, so an attacker could have abused one, or a similar future issue, to log the victim into the attacker's account. The attacker could then use the XSS to trick the victim into entering their own credentials.
Fix
The proposed fix is in the phutil_tag function: first filter all non-alphanumerical characters from $href, then check whether it starts with javascript:. Removing the non-alphanumerical characters before the comparison means whitespace and similar characters can no longer sit between the scheme name and the colon when the check runs.
Variants to test
- Try other whitespace and control characters between the scheme name and the colon, not just the newline used here, and see whether the stored link still runs when clicked.
- Try other schemes that browsers may treat as script or as dangerous navigation, and check whether the allow-list really only permits
http:andhttps:. - Try the same bypass wherever a user-supplied URL is rendered into an
href, such as profile links, external application links and similar settings fields. - Submit values through the API or a direct request rather than the browser form, since the browser strips the characters that make the bypass work.
A positive result is a stored value that survives the save, is rendered back into the page, and runs or navigates unexpectedly when clicked.
Hunting notes
This kind of bug hides in settings fields that store a URL and later render it as a link, especially where a scheme check exists but is applied to the raw string. During recon, look for features that let users configure external links, editors or integrations, and inspect how the value is validated on save and how it is emitted on render. The researcher showed impact by demonstrating the alert on the "Edit" link and by tying the persistence to account take-over and login CSRF scenarios.
Glossary
- Phabricator: a suite of web-based development tools for managing code, tasks and reviews.
- Editor link: a user setting that stores a link to an external editor program, shown on the page as a clickable link.
- HTML attribute: extra information attached to an HTML element, written as
name="value". href: the attribute of a link element that holds the address the link points to.- URL scheme: the first part of an address, before the colon, such as
https:orjavascript:. - JavaScript: the programming language that runs inside web pages in the browser.
- XSS (cross-site scripting): a bug where an attacker's JavaScript runs inside another person's browser session on a website.
- Persistent XSS: XSS where the malicious value is stored on the server and served back on later visits.
- Reflected XSS: XSS where the malicious value bounces back once from a single request and is not stored.
phutil_tag: a helper function in libphutil that builds HTML tags and checks link schemes.- libphutil: the shared library used by Phabricator.
- Whitespace character: a character that creates space, such as a space, tab or newline.
- Newline character: the invisible character that marks the end of a line of text.
- URL encoding: writing characters as a percent sign plus two hexadecimal digits so they can travel inside a request.
- POST request: a request that carries form values in its body, usually sent when a form is submitted.
- Network panel: a browser developer tool that lists the requests a page makes.
- Parameter: a named value sent with a request, such as
editor. - API: a way for programs to talk to a website directly, without going through its pages.
- CSRF (cross-site request forgery): a bug where another site can make your browser send a request to a site you are logged into.
- Login CSRF: a CSRF variant that logs you into the attacker's account instead of your own.
- Account take-over: an attacker gaining control of another person's account.
- Self-XSS: XSS that only runs on the account of the person who entered it, which limits its direct reach.
- Allow-list: a list of values that are permitted, with everything else rejected.
- Recon: the exploratory phase of looking around a target to find features worth testing.