Clean up invalid mozreview urls on attachment page
The attachment edit page did not escape a user-supplied review URL when placing it in an href attribute, so a crafted text/plain attachment could inject script. An attacker could cause script to run in the context of the attachment page.
Originally disclosed on Mozilla
- Fixed in 17 hours
- Paid in 4 days
- Disclosed after 17 hours
See https://bugzilla-dev.allizom.org/attachment.cgi?id=8592183&action=edit - an alert message saying XSS will appear. Code has been injected here by adding a text/plain attachment with the following contents:
> https://reviewboard.mozilla.org/r/12345/?"><script>alert("XSS")</script><"
The bug can be seen in https://github.com/mozilla-bteam/bmo/blob/e655f5133b4dd5c5d6f253069767db75c64eb349/extensions/MozReview/template/en/default/hook/attachment/edit-view.html.tmpl#L15 - while the review URL is being filtered in the title attribute, for the href attribute no escaping is being performed. So malicious data will be able to inject arbitrary HTML code here as long as it still matches the regular expression used to validate review URLs.
What the report shows
The target is the attachment page of Bugzilla, specifically the MozReview extension that renders review URLs attached to a bug. A crafted review URL could break out of an HTML attribute and inject script into the attachment edit view.
The steps were straightforward:
- Add a
text/plainattachment whose contents are the following line:
https://reviewboard.mozilla.org/r/12345/?"><script>alert("XSS")</script><"
-
Open the attachment edit page. The researcher points to
https://bugzilla-dev.allizom.org/attachment.cgi?id=8592183&action=editas the place where the alert appears. -
The injected markup executes because the review URL is placed into an
hrefattribute without escaping.
The report links to the template responsible, extensions/MozReview/template/en/default/hook/attachment/edit-view.html.tmpl at line 15 in the mozilla-bteam/bmo repository. The researcher notes that the review URL is filtered in the title attribute but that no escaping is performed for the href attribute. As a result, malicious data can inject arbitrary HTML as long as it still matches the regular expression used to validate review URLs.
The platform records the severity as high. The report does not give a bounty amount, a CVSS score or a weakness classification, and it does not describe the fix.
Root cause
The template renders the review URL into two attributes. The title attribute is filtered, but the href attribute is written out raw. The only gate on the value is a regular expression that validates the shape of a review URL, and that check is not sufficient to make the value safe for HTML attribute context: a value that still matches the pattern can contain characters such as ", > and < that terminate the attribute and start new markup. This is a classic context mismatch: validation of the URL format is treated as if it were output encoding for HTML.
Impact
The report demonstrates script execution in the attachment edit view, triggered by opening the page that renders the crafted attachment. The payload is stored in the attachment contents, so the script runs when that page is viewed. The report does not analyse what an attacker could do with the executed script, such as acting as the victim or reading data from the page, so the practical consequences beyond the alert are not established here.
How this kind of bug works
HTML is parsed by context. Text placed between tags, inside an attribute value, inside a URL attribute, inside a script block and inside a style block are all different contexts with different escaping rules. When an application takes user-controlled data and concatenates it into a template, the safety of the result depends on which context the data lands in and whether the escaping matches that context.
URL attributes such as href and src are a frequent weak point for two reasons. First, developers often validate the value as a URL (scheme, host, path shape) and assume a valid URL is a safe string, but a valid URL can still contain quotes and angle brackets. Second, templating engines may apply automatic escaping to some sinks and not others, so a value escaped in one attribute can be raw in the next. A single unescaped quote is enough to close the attribute, and a following > closes the tag, after which arbitrary markup, including a script element or an event handler attribute, is parsed normally.
The defences are output encoding applied per context (HTML attribute encoding for attribute values, URL encoding for URL components), a Content Security Policy that blocks inline script, and avoiding string concatenation of untrusted data into templates in the first place. Server-side validation of URL format is useful but is not a substitute for encoding.
How to test for it
Look for features that echo user-supplied URLs back into pages: attachment metadata, link previews, profile fields, referrer displays, redirect parameters shown in error pages, and any place a stored URL is rendered as a clickable link.
- Identify every field that ends up in an
href,src,actionor similar attribute, and note any validation applied to it (scheme allowlists, regex checks, length limits). - Submit a value that is a syntactically valid URL for the validator but contains attribute-breaking characters, for example a quote followed by a tag, appended to a legitimate-looking URL path or query string.
- Load the page that renders the value and inspect the resulting HTML source, not just the rendered page. A positive result is your characters appearing unencoded inside the attribute, with the attribute closed early and your markup parsed as a sibling element or attribute.
- Confirm execution with a benign payload such as an alert, and check whether the value is stored (visible to another user or session) or reflected only.
Common false positives: the value appears in the page but is HTML-encoded (", <), so it stays inside the attribute; the payload is blocked by a Content Security Policy even though the markup is injected; the value is placed in a context where quotes are harmless, such as a text node; or the validator rejects the payload before it is stored, in which case try variations that keep the URL shape intact.
How it is fixed
Apply context-aware output encoding to every attribute the value is written into, including href, not only title. In template engines, use the escaping helper appropriate for HTML attributes and avoid marking the value as safe. Where a URL must be embedded, encode it as a URL component and then HTML-encode the result. Keep the URL validation as defence in depth, and add a Content Security Policy that disallows inline script to limit the damage of any missed sink.
Hunting notes
This class of bug hides where stored user data meets hand-written templates: extensions and plugins that add their own template hooks, older code paths that predate a templating engine's auto-escaping, and places where one attribute is escaped and a neighbouring one is not. Recon signals include template files with manual string interpolation, mixed use of raw and escaped output helpers in the same file, and features that display URLs supplied by users. To make the report land, show the exact stored value, the page that renders it, the relevant template or code line if you can find it, and a minimal proof such as an alert; state clearly whether the payload is stored and who would trigger it.
What happened, in plain words
Bugzilla is Mozilla's bug tracking system: a website where developers and testers record bugs, discuss them and attach files that help explain a problem. Mozilla also runs an extension called MozReview, which links Bugzilla bugs to code reviews on a separate review site. When you open an attachment's edit page in Bugzilla, the MozReview extension shows the review URL associated with that attachment as a clickable link.
The link was built in an unsafe way. If an attacker put a specially crafted line of text into an attachment, the attachment edit page would treat part of that text as HTML code and run it as a script in the browser of anyone who opened the page. The script in the proof was a harmless pop-up.
The steps were simple:
- Add an attachment of type
text/plain(a plain text file) whose contents are this single line:
https://reviewboard.mozilla.org/r/12345/?"><script>alert("XSS")</script><"
-
Open the attachment edit page. The researcher gives
https://bugzilla-dev.allizom.org/attachment.cgi?id=8592183&action=editas the page where the alert appears. -
The injected markup runs because the review URL is placed into an
hrefattribute without escaping.
Why does that line work? A web page is written in HTML, a language made of tags such as <a href="..."> for a link. The href attribute holds the address the link points to, and it is wrapped in double quotes. The browser reads everything up to the next double quote as the address. The payload starts with a normal-looking review URL, then contains " which closes the attribute early, then > which closes the tag, then a <script> tag with alert("XSS") inside it, and finally <" to keep the leftover text tidy. The browser now sees a complete script element and runs it.
The report points to the template responsible, extensions/MozReview/template/en/default/hook/attachment/edit-view.html.tmpl at line 15 in the mozilla-bteam/bmo repository. A template is a file that mixes fixed page layout with placeholders that get filled in with data. The researcher notes that the review URL is filtered in the title attribute (the tooltip text shown when you hover over a link) but that no escaping is done for the href attribute. Escaping means converting characters that have a special meaning in HTML, such as ", < and >, into harmless codes so the browser shows them as text instead of treating them as code. Because the href value was written out raw, malicious data could inject arbitrary HTML as long as it still matched the regular expression used to validate review URLs. A regular expression is a pattern used to check the shape of a string, for example that it starts with a known review site address.
The platform records the severity as high. The report does not give a bounty amount, a CVSS score or a weakness classification, and it does not describe the fix.
In general, how this kind of bug works
This is called cross-site scripting, or XSS: a website takes data from one user and puts it into a page in a way that makes another user's browser run it as code. When the bad data is saved on the server, as here in an attachment, it is called stored XSS, because the script is served from the stored data. A request is simply a message your browser sends to a server asking for a page or sending data; a cookie is a small piece of data a site stores in your browser, often to keep you logged in. Script running in a page can act with the visitor's logged-in session, which is why XSS matters.
HTML is read in context. Text between tags, text inside an attribute value, and text inside a script block are all treated differently. When a program glues user data into a template, safety depends on where the data lands and whether the escaping matches that spot.
URL attributes such as href and src are a common weak point for two reasons. First, developers often check that a value looks like a valid URL and assume a valid URL is a safe string, but a valid URL can still contain quotes and angle brackets. Second, templating engines may escape some places automatically and not others, so a value escaped in one attribute can be raw in the next. One unescaped quote is enough to close the attribute, and a following > closes the tag, after which any markup is read normally.
The defences are output encoding applied per context (HTML attribute encoding for attribute values, URL encoding for URL parts), a Content Security Policy that blocks inline script, and avoiding string concatenation of untrusted data into templates. Server-side validation of URL format is useful but is not a substitute for encoding.
In general, how to test for it
Look for features that echo URLs you supply back into pages: attachment metadata, link previews, profile fields, redirect parameters shown in error pages, and any place a stored URL is shown as a clickable link.
- Find every field that ends up in an
href,src,actionor similar attribute, and note any validation applied to it (allowed schemes, regex checks, length limits). - Submit a value that passes the validator as a URL but contains attribute-breaking characters, for example a quote followed by a tag, appended to a legitimate-looking URL.
- Load the page that renders the value and inspect the HTML source, not just the rendered page. A positive result is your characters appearing unencoded inside the attribute, with the attribute closed early and your markup read as a separate element.
- Confirm execution with a harmless payload such as an alert, and check whether the value is stored (visible to another user) or only reflected back to you.
Common false positives: the value appears but is HTML-encoded (", <) so it stays inside the attribute; a Content Security Policy blocks the script even though markup was injected; the value lands where quotes are harmless, such as plain text; or the validator rejects the payload before it is stored, in which case try variations that keep the URL shape intact.
In general, how it is fixed
Apply context-aware output encoding to every attribute the value is written into, including href, not only title. In template engines, use the escaping helper appropriate for HTML attributes and avoid marking the value as safe. Where a URL must be embedded, encode it as a URL component and then HTML-encode the result. Keep URL validation as an extra layer, and add a Content Security Policy that disallows inline script to limit the damage of any missed spot.
Glossary
- Bugzilla: Mozilla's web-based bug tracking system.
- MozReview: a Bugzilla extension that links bugs to code reviews on a separate review site.
- Attachment: a file or text added to a bug report.
- HTML: the language web pages are written in, made of tags and attributes.
- Tag: a markup element such as
<a>or<script>. - Attribute: a setting inside a tag, such as
hrefortitle. href: the attribute holding a link's address.title: the attribute holding tooltip text for an element.- Template: a file mixing fixed layout with placeholders filled in with data.
- Escaping / output encoding: converting special characters into harmless codes so they are shown as text, not run as code.
- Regular expression: a pattern used to check the shape of a string.
- Cross-site scripting (XSS): making a site deliver attacker-controlled code to a visitor's browser.
- Stored XSS: XSS where the malicious data is saved on the server and served to every visitor.
- Request: a message a browser sends to a server asking for a page or sending data.
- Cookie: a small piece of data a site stores in the browser, often to keep a user logged in.
- Session: the logged-in state a site keeps for a user across requests.
- Content Security Policy (CSP): a browser rule set from the server that restricts what scripts a page may run.
- Payload: the crafted input used to trigger a bug.
- False positive: a result that looks like a bug but is not exploitable.