Reflected XSS in error pages (NC-SA-2017-008)
Error messages in multiple Nextcloud components were not properly escaped, allowing HTML injection. An attacker could send a crafted link to a logged-in user to inject HTML, potentially enabling phishing or XSS, though the strict Content-Security-Policy blocks script execution in modern browsers.
- Triaged in under an hour
- Fixed in 41 days
- Paid in 24 days
- Disclosed after 48 days
Summary by the program
#Reflected XSS in error pages (NC-SA-2017-008)
Risk level: Low CVSS v3 Base Score: 3.5 (AV:N/AC:L/PR:L/UI:R/S:U/C:L/I:N/A:N) CWE: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
#Description Inadequate escaping of error messages leads to XSS vulnerabilities in multiple components.
Note that Nextcloud employs a strict Content-Security-Policy preventing exploitation of this XSS issue on modern web browsers.
#Affected Software
- Nextcloud Server < 11.0.3 (CVE-2017-0891)
- Nextcloud Server < 10.0.5 (CVE-2017-0891)
- Nextcloud Server < 9.0.58 (CVE-2017-0891)
#Action Taken Error messages are now properly escaped.
#Acknowledgements The Nextcloud team thanks the following people for their research and responsible disclosure of the above advisory:
- Manuel Mancera - Vulnerability discovery and disclosure.
The report
Hello,
I found a HTML injection vulnerability [1] flaw in the Nextcloud (and Owncloud) latest version. Through this vulnerability an attacker could manipulate the website. This vulnerability could affect to the logged users. An attacker could send a malicious link (that contains the manipulated URL) to a legitimate user that he is logged in and simulate the login screen to stole the password (phishing), or multiple attacks more, like XSS.
The Nextcloud/Owncloud application contains multiple security headers of HTTP, so, inject scripts or redirect to another websites is difficult, the problem is that not all the browser supports these headers (fortunatelly, the most used browsers yes).
Exist more options to attack, for example, redirect the content of an <object> or <script> to a saved and shared items of your directory. Also, the mimetypes are well configured and the most browsers will not execute a javascript file that doesn't have the javascript content-type.
Anyway, all the mitigations are well, but these aren't never-falling. So the solution to this vulnerability is sanitize the output before to deliver the HTML to the final user.
Also, another security flaw is showed, but the impact is less, it is a full path disclosure and it show the full path of the Nextcloud/Owncloud installation.
PoC (Proof of Concept):
https://nextcloud-site/index.php/apps/files/ajax/download.php?files=%00&dir=</p>HTMLCODE
I tested it in the last version.
If you need more information, ask to me.
Regards,
Context
Nextcloud Server is a self-hosted file sync and sharing application. Its web interface exposes a files app with an AJAX download endpoint under /index.php/apps/files/ajax/download.php, which takes a files parameter and a dir parameter. The researcher reports the flaw in both Nextcloud and Owncloud.
The bug is a reflected cross-site scripting (XSS) issue in error pages. The program's advisory describes it as inadequate escaping of error messages leading to XSS in multiple components, tracked as CWE-79 and CVE-2017-0891, with a CVSS v3 base score of 3.5 (AV:N/AC:L/PR:L/UI:R/S:U/C:L/I:N/A:N). The researcher also notes a second, lower-impact flaw: a full path disclosure that reveals the installation path.
Setup
The researcher tested against the latest version of Nextcloud (and Owncloud) at the time. No special account, role or tooling is described. The precondition for the attack is a logged-in victim: the researcher states the vulnerability could affect logged users, and the malicious link is sent to a legitimate user who is logged in.
Finding it
The researcher identified an HTML injection flaw in the application. The reasoning is that the application reflects attacker-controlled input into the HTML it delivers, so an attacker can manipulate the page. From there the researcher lists several possible abuses:
- Send a malicious link containing the manipulated URL to a logged-in user and simulate the login screen to steal the password (phishing).
- Other attacks, including XSS.
The researcher is explicit about the defences in place. Nextcloud and Owncloud send multiple HTTP security headers, which make injecting scripts or redirecting to another website difficult. The caveat given is that not all browsers support these headers, although the most used browsers do. The researcher also considers redirecting the content of an <object> or <script> to a saved and shared item in the user's directory, and notes that mimetypes are well configured so most browsers will not execute a JavaScript file that does not carry the JavaScript content-type.
The conclusion drawn is that the mitigations are good but not infallible, and that the correct fix is to sanitise the output before delivering the HTML to the final user.
Exploitation
Step 1: craft the malicious URL
The proof of concept is a single URL against the files download endpoint, with a null byte in the files parameter and an HTML fragment in the dir parameter:
https://nextcloud-site/index.php/apps/files/ajax/download.php?files=%00&dir=</p>HTMLCODE
The files parameter is set to %00, the URL-encoded null byte. The dir parameter carries the injected markup, here shown as </p>HTMLCODE, a closing paragraph tag followed by placeholder HTML. The researcher does not show the response body, so the exact reflection point and the surrounding markup are not documented.
Step 2: deliver the link to a logged-in user
The crafted URL is sent to a legitimate user who is logged in. Because the injected content is rendered in the application's own page, the attacker can present a fake login screen to capture the password, or use the injection for XSS. The researcher lists this among the possible abuses, with the security headers and browser support as limiting factors.
Root cause
Error messages are not properly escaped when they are written into the HTML page, so input reflected into an error page is interpreted as markup. The program's advisory states the fix directly: error messages are now properly escaped.
Why the existing defences did not stop it: Nextcloud employs a strict Content-Security-Policy, which the advisory says prevents exploitation of this XSS issue on modern web browsers. The researcher's own analysis points the same way, noting that the HTTP security headers make script injection and redirects difficult, but that not all browsers support these headers. The advisory says the CSP prevents exploitation of this XSS issue on modern web browsers.
Impact
The advisory rates the issue as low risk with a CVSS v3 base score of 3.5. The researcher describes two outcomes for a logged-in victim who follows the crafted link: a simulated login screen used to steal the password (phishing), and XSS. The researcher also mentions the possibility of redirecting the content of an <object> or <script> to a saved and shared item in the user's directory, while noting that mimetype handling makes script execution from a non-JavaScript content-type unlikely in most browsers. Exploitation of the XSS itself is constrained by the Content-Security-Policy on modern browsers.
Separately, the researcher reports a full path disclosure that reveals the full path of the Nextcloud/Owncloud installation, with lower impact.
Fix
Error messages are now properly escaped, per the advisory. The affected versions and their fixes are:
| Affected | Fixed in |
|---|---|
| Nextcloud Server < 11.0.3 | 11.0.3 |
| Nextcloud Server < 10.0.5 | 10.0.5 |
| Nextcloud Server < 9.0.58 | 9.0.58 |
All three are tracked as CVE-2017-0891. The researcher's own recommendation is to sanitise the output before delivering the HTML to the final user.
Variants to test
- Other error paths in the files app. The report shows one endpoint,
download.php, with a null byte infilesand markup indir. Try other parameters and other endpoints that generate error messages from user input. A positive result is your markup appearing unescaped in the error page. - Null byte handling. The
%00infilesis part of the PoC. Try null bytes and other malformed values in file-related parameters to see whether they reach error rendering. A positive result is an error page that reflects the value without encoding. - Path disclosure. Look for error responses that include the server's installation path. A positive result is a response containing the full filesystem path of the application.
- Header-dependent exploitation. Where a CSP or other security headers are present, check how the page behaves in browsers that do not enforce them, since the researcher's argument rests on that gap. A positive result is script execution or a redirect in a browser without the header support.
Hunting notes
This kind of bug hides in error handling: messages built from request parameters and rendered into HTML. The signals during recon are endpoints that take file paths or directory names and produce error pages, and responses that echo your input back. The researcher described possible abuses, a malicious link sent to a logged-in user leading to a fake login screen or XSS, while being explicit about the mitigations (security headers, mimetype handling) that limit it. The program accepted it as a low-severity issue with a 450 USD bounty and disclosed it on 15 May 2017, crediting Manuel Mancera (sinkmanu) for discovery and disclosure.
What happened, in plain words
Nextcloud is a piece of software you install on your own server to store and share files, a bit like running your own private version of a cloud drive. It has a web interface: you open it in a browser, log in, and see your files. The researcher reported the problem in both Nextcloud and a similar product called Owncloud.
The researcher found an HTML injection flaw: the application puts attacker-controlled input back into the page without cleaning it first. That means an attacker can put their own HTML into a link, and when a logged-in user clicks that link, the attacker's HTML becomes part of the Nextcloud page. The attacker could then draw a fake login form on top of the real page and trick the user into typing their password there. This class of bug is called HTML injection, and when the injected content can run scripts it is called cross-site scripting, or XSS.
Nextcloud had defences in place that made the worst version of this hard to pull off, and the program rated the issue as low risk. The researcher also noticed a second, smaller problem: an error message that revealed the full folder path where Nextcloud was installed on the server.
The background you need
A few ideas come up again and again below, so here they are from zero.
- Web page, HTML and escaping. A web page is a text document written in HTML. The browser reads the tags in it, like
<p>for a paragraph, and draws the result. If a program takes text a user supplied and drops it into the HTML without changing it, the browser cannot tell the difference between the program's own tags and the user's text. It will treat the user's text as instructions. "Escaping" means converting dangerous characters into harmless lookalikes so the browser shows them as plain text instead of acting on them. Think of a form where you write your name: if the form prints your name on a badge without checking it, and you write "Manager" on it, the badge now says Manager. Escaping is the clerk crossing out anything that looks like a job title. - URL and query parameters. A URL is the address of a page. Everything after a
?is a list of parameters, written asname=valuepairs joined by&. They are how a link carries information to the server, for example which folder to show.%00is how a URL writes a null byte, a character with the numeric value zero that normally marks the end of a piece of text in some programming languages. - Endpoint. An endpoint is a specific address inside a web application that does one job, like "download a file". The application decides what to do by looking at the path in the URL.
- HTTP headers. When a browser asks for a page, the server replies with the page plus a set of headers, which are short labelled notes about the reply. Some headers are security instructions, telling the browser things like "do not run scripts that were not part of this page". The browser is supposed to obey them.
- Content-Security-Policy (CSP). This is one of those security headers. It is a list of rules the browser must follow about what the page is allowed to load and run. A strict policy can stop injected scripts from executing even when they are present in the page.
- Mimetype. Every file has a type, such as image, text or JavaScript. The server announces the type in a header, and browsers use it to decide whether to display a file or run it. If a file is labelled as an image, most browsers will not run it as code.
- Cross-site scripting (XSS). A bug where an attacker gets their own code into a page that other people trust. "Reflected" means the malicious input is bounced straight back in the response to the same request, rather than being stored on the server for later.
- Phishing. Tricking someone into entering their password into a page that looks genuine but is controlled by the attacker.
- Full path disclosure. An error message that reveals the exact folder location of the software on the server, for example
/var/www/nextcloud. On its own it is minor, but it helps an attacker plan further steps. - CVSS. A scoring system for the severity of a security bug. The base score runs from 0 to 10, and the letters in brackets break the score down into components such as how the attack is carried out and what it can affect.
The setup
The researcher tested against the latest version of Nextcloud and Owncloud available at the time. No special account, role or tool is mentioned. The one condition for the attack is that the victim is logged in: the researcher says the flaw could affect logged-in users, and the malicious link is sent to a legitimate user who is already signed in.
Finding it
The researcher identified an HTML injection flaw: the application takes input the attacker controls and puts it back into the HTML page it sends, so the attacker can change what the page shows. From that starting point the researcher lists what an attacker could do with it:
- Send a malicious link containing the manipulated URL to a logged-in user, draw a fake login screen, and steal the password. This is phishing.
- Carry out other attacks, including XSS.
The researcher is careful about the defences already in place. Nextcloud and Owncloud send several HTTP security headers, which make injecting scripts or redirecting the browser to another website difficult. The catch is that not every browser supports those headers, although the most widely used ones do. The researcher also considers pointing the content of an <object> or <script> tag at a saved and shared file in the user's own folder, and notes that mimetypes are configured well, so most browsers will not run a JavaScript file that is not labelled with the JavaScript content type.
The conclusion is that the mitigations are good but not perfect, and that the right fix is to sanitise the output before the HTML is delivered to the user. Sanitising here means the same as escaping: clean the text so it cannot act as markup.
Exploitation
Step 1: build the malicious URL
The proof of concept is a single URL aimed at the files download endpoint. It puts a null byte in the files parameter and an HTML fragment in the dir parameter:
https://nextcloud-site/index.php/apps/files/ajax/download.php?files=%00&dir=</p>HTMLCODE
Line by line:
https://nextcloud-siteis the address of the Nextcloud installation. It is a placeholder for a real server./index.php/apps/files/ajax/download.phpis the endpoint: the part of Nextcloud that serves a file for download. "ajax" here just means the page's own scripts call it in the background rather than you navigating to it.?starts the list of parameters.files=%00sets thefilesparameter to a null byte. The researcher does not explain why this particular value was chosen; it is part of the proof of concept.&separates the two parameters.dir=</p>HTMLCODEsets thedirparameter, which normally names a folder, to a closing paragraph tag followed by the placeholder textHTMLCODE. That is the injected markup: if it appears in the page unescaped, the browser will treat it as HTML rather than as a folder name.
The researcher does not show the response body, so the exact spot in the page where the input comes back, and the markup around it, are not documented. What the report establishes is that the input reaches the generated error page without being properly escaped.
Step 2: get the link to a logged-in user
The crafted URL is sent to a legitimate user who is signed in. Because the injected content is drawn inside Nextcloud's own page, the attacker can show a fake login screen there and capture the password, or use the injection for XSS. The researcher lists this among the possible abuses, with the security headers and browser support as the things that limit it.
Why it worked
Error messages are not properly escaped when they are written into the HTML page. So input that is reflected into an error page is read by the browser as markup instead of as text. The program's advisory states the fix plainly: error messages are now properly escaped.
Why the existing defences did not settle the matter: Nextcloud uses a strict Content-Security-Policy, and the advisory says this prevents exploitation of the XSS on modern browsers. The researcher's own analysis agrees in spirit, noting that the HTTP security headers make script injection and redirects difficult, but that not all browsers support those headers. The advisory says the CSP prevents exploitation of the XSS on modern browsers.
What an attacker could do
The advisory rates the issue as low risk, with a CVSS v3 base score of 3.5. For a logged-in victim who follows the crafted link, the researcher describes two outcomes: a simulated login screen used to steal the password (phishing), and XSS. The researcher also mentions redirecting the content of an <object> or <script> to a saved and shared file in the user's folder, while noting that mimetype handling makes running a script from a non-JavaScript content type unlikely in most browsers. Exploiting the XSS itself is limited by the Content-Security-Policy on modern browsers.
Separately, the researcher reports a full path disclosure that reveals the full path of the Nextcloud or Owncloud installation, with lower impact.
The fix
Error messages are now properly escaped, according to the advisory. The affected versions and the versions that fix them are:
| Affected | Fixed in |
|---|---|
| Nextcloud Server < 11.0.3 | 11.0.3 |
| Nextcloud Server < 10.0.5 | 10.0.5 |
| Nextcloud Server < 9.0.58 | 9.0.58 |
All three are tracked as CVE-2017-0891. The researcher's own recommendation is to sanitise the output before delivering the HTML to the final user.
Where else to look
If you want to hunt for something similar, these are the directions the report points to.
- Other error paths in the files app. The report shows one endpoint,
download.php, with a null byte infilesand markup indir. Try other parameters and other endpoints that build error messages from what the user sent. You have a hit when your markup appears unescaped in the error page. - Null byte handling. The
%00infilesis part of the proof of concept. Try null bytes and other malformed values in file-related parameters and see whether they reach the error rendering. You have a hit when an error page echoes the value back without encoding it. - Path disclosure. Look for error responses that include the server's installation path. You have a hit when a response contains the full filesystem path of the application.
- Header-dependent exploitation. Where a CSP or other security headers are present, check how the page behaves in browsers that do not enforce them, since the researcher's argument rests on that gap. You have a hit when a script runs or a redirect happens in a browser without support for the header.
Notes for a beginner
This kind of bug hides in error handling: messages built from request parameters and then rendered into HTML. During recon, the signals are endpoints that take file paths or folder names and produce error pages, and responses that echo your input back to you. The researcher described possible abuses, a malicious link sent to a logged-in user leading to a fake login screen or XSS, while being open about the mitigations (security headers, mimetype handling) that limit it. The program accepted it as a low-severity issue with a 450 USD bounty and disclosed it on 15 May 2017, crediting Manuel Mancera (sinkmanu) for discovery and disclosure.
Glossary
- AJAX: a way for a web page to talk to the server in the background, without reloading the whole page.
- Content-Security-Policy (CSP): a security header that tells the browser which scripts and resources a page may run or load.
- Cross-site scripting (XSS): a bug where an attacker gets their own code into a page other people trust.
- CVE: a public identifier for a known security vulnerability, so people can refer to the same bug unambiguously.
- CVSS: a scoring system that rates the severity of a vulnerability from 0 to 10, with a breakdown of the components behind the score.
- CWE-79: the catalogue entry for cross-site scripting, a standard way of naming the weakness class.
- Endpoint: a specific address inside a web application that performs one job.
- Escaping: converting characters that have special meaning in HTML into harmless text so the browser displays them instead of acting on them.
- Full path disclosure: an error message that reveals the exact folder location of the software on the server.
- HTML injection: getting your own HTML into a page so the browser renders it as part of that page.
- HTTP header: a short labelled note sent with a web request or response, some of which carry security instructions.
- Mimetype: the type of a file, such as image or JavaScript, which browsers use to decide whether to display or run it.
- Null byte: a character with the numeric value zero, written
%00in a URL, which some programs treat as the end of a piece of text. - Query parameter: a
name=valuepair after the?in a URL that passes information to the server. - Reflected XSS: XSS where the malicious input is sent straight back in the response to the same request, rather than stored on the server.
- Self-hosted: software you install and run on your own server rather than using a provider's service.
- URL: the address of a page or resource on the web.