Unauthenticated SSRF in 3rd party module "cerdic/csstidy"
The mail extension bundles a third-party CSS optimiser with a publicly accessible test page that fetches a user-supplied URL, allowing an unauthenticated attacker to make the server send requests to arbitrary hosts. The same page can also save the fetched content as a CSS file in a temporary directory, which the reporter says is not exploitable alone but could be chained with a local file inclusion flaw.
- Triaged in 6 hours
- Fixed in 19 days
- Paid in 35 days
- Disclosed after 3 months
Summary by the program
Advisory at https://github.com/nextcloud/security-advisories/security/advisories/GHSA-24pm-rjfv-23mh
The report
Summary:
The mail extension in nextcloud includes a module called "cerdic/csstidy" which basically ships with a publicly accessible test/example interface to play with the CSS formatter and optimiser (/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php). This module allows contacting any remote server via http, which makes it vulnerable to SSRF. We've tried reaching out to the csstidy developers directly but couldn't reach them yet, so we're reaching out to you so they can fix this before csstidy pushes out a fix.
It's also possible to download remote data as a CSS file into a temporary directory in /apps/mail/vendor/cerdic/css-tidy/temp/. At the moment, this doesn't look to be exploitable on its own, and probably requires another vulnerability to exploit, e.g. a Local File Inclusion vulnerability could be turned into a Remote File Inclusion by first creating a CSS file containing PHP code (downloaded from a remote server via the csstidy vulnerability), and then including the local file via the LFI bug.
Steps To Reproduce:
- Install the mail extension
- Visit: http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php (no authentication is required)
- Either use the interface to set "CSS from URL" on the bottom or set the "url" parameter manually, for example: http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/test
- To download remote data as CSS file, either use the interface or try this: http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/apps/richdocuments/docs/custom.css&custom=1&template=4
Supporting Material/References:
- Problematic line in csstidy: https://github.com/Cerdic/CSSTidy/blob/master/css_optimiser.php#L376
Impact
Usually, SSRFs are not considered a high-impact vulnerability, and I would likely agree on most PHP projects, but (a) this vulnerability can be exploited by an unauthenticated attacker and (b) nextcloud is also designed to be used at a home network which opens the possibility of not only attacking other local services, but also the router of the home network. The ability to receive and write CSS files can also be used by the attacker to find out what other services are running on devices in the network or what kind of router is used etc., before running additional attacks.
Context
Nextcloud ships a mail extension, and that extension bundles a third-party PHP library called cerdic/csstidy. CSSTidy is a CSS parser, formatter and optimiser. Besides the library itself, the package ships a browser-facing test and example interface, css_optimiser.php, which lets a visitor paste CSS, load CSS from a URL, and run it through the optimiser.
In the mail app the file is reachable at a predictable path under the vendor directory:
/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php
Because the file sits inside the app's web root, it is served directly by the web server, outside any of Nextcloud's own routing and access control. The feature it exposes is a developer playground, but on a production instance it behaves as a public endpoint that fetches URLs on the server's behalf.
Setup
The only precondition is that the mail extension is installed. No account, session or role is needed: the researcher states explicitly that no authentication is required to reach the interface. The reproduction uses a host named example.com as the Nextcloud instance and localhost as the internal target, so no special tooling is involved beyond a browser or an HTTP client.
Finding it
The researcher identified that the bundled cerdic/csstidy package ships a publicly accessible test/example interface for playing with the CSS formatter and optimiser. The interface offers a "CSS from URL" option, which means the server-side PHP code performs an outbound HTTP request to a URL supplied by the visitor. A server-side fetch of an attacker-chosen URL is the definition of SSRF, and here it is reachable without logging in.
The researcher also noted a second behaviour: remote data can be downloaded as a CSS file into a temporary directory at /apps/mail/vendor/cerdic/css-tidy/temp/. On its own the researcher judged this not to be exploitable, and considered it something that would probably need another vulnerability to become useful.
The problematic line in csstidy is referenced as:
https://github.com/Cerdic/CSSTidy/blob/master/css_optimiser.php#L376
The researcher had tried to contact the csstidy developers directly but could not reach them, and reported to Nextcloud so that the upstream project could fix it before csstidy published a fix.
Exploitation
Step 1: install the mail extension
Install the mail extension on the Nextcloud instance. This places the vendored csstidy package, including css_optimiser.php, under /apps/mail/vendor/cerdic/css-tidy/.
Step 2: open the optimiser interface unauthenticated
Visit the interface directly:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php
No authentication is required. The page is the csstidy example interface, which is intended for developers to experiment with the CSS formatter and optimiser.
Step 3: make the server fetch an arbitrary URL
Either use the interface and set "CSS from URL" at the bottom of the page, or set the url parameter manually:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/test
The url parameter carries the address the server will request. Because the request originates from the Nextcloud host, localhost resolves to the server itself, and any other host the server can reach (other services on the local network, the home router) is equally addressable.
Step 4: write remote data to the temp directory
To download remote data as a CSS file, either use the interface or request:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/apps/richdocuments/docs/custom.css&custom=1&template=4
Here url points at a CSS file served by another app on the same instance, and the request adds the custom=1 and template=4 parameters. The downloaded data lands as a CSS file in:
/apps/mail/vendor/cerdic/css-tidy/temp/
Root cause
The mistake is packaging: a development and demonstration script from a third-party library was shipped inside a web-accessible directory of the mail app. The script accepts a URL from the request and performs a server-side fetch of it, with no authentication in front of it and, as far as the report shows, no restriction on which hosts may be contacted. Nextcloud's own authentication and routing do not apply, because the file is served directly from the vendor path rather than through the application framework. The report does not describe any allowlist, network filtering or other control that would have limited the fetch.
Impact
The researcher is candid that SSRF is usually not considered high impact, and would agree on most PHP projects, but gives two reasons why this instance is different. First, the vulnerability can be exploited by an unauthenticated attacker. Second, Nextcloud is also designed to be used on a home network, which opens the possibility of not only attacking other local services but also the router of the home network.
The ability to receive and write CSS files can also be used to find out what other services are running on devices in the network, or what kind of router is used, before running additional attacks. The file-write behaviour on its own is described as not currently exploitable and probably requiring another vulnerability: for example, a Local File Inclusion bug could be turned into a Remote File Inclusion by first creating a CSS file containing PHP code, downloaded from a remote server through the csstidy vulnerability, and then including that local file via the LFI bug.
Fix
The report itself does not describe the patch. The program points to its published advisory for the resolution:
https://github.com/nextcloud/security-advisories/security/advisories/GHSA-24pm-rjfv-23mh
What the report makes clear is where the fix belongs: the vulnerable code is in csstidy's css_optimiser.php, and the researcher reported to Nextcloud specifically so the upstream project could fix it before csstidy shipped a fix of its own.
Variants to test
- Other vendored libraries with example or test scripts. Look for paths such as
vendor/<package>/containing files named like examples, demos, tests or optimisers. A positive result is a script that responds without a session and performs a server-side action such as a fetch. - URL-accepting parameters on any reachable PHP file. Try a parameter such as
urlpointing at an internal address. A positive result is a response whose content or timing reflects the internal target. - File-writing modes on the same interface. Try the
customandtemplateparameters alongsideurl. A positive result is a new file appearing under the package'stempdirectory. - Chaining with a file inclusion bug. If you have an LFI, first write a file containing PHP code through the fetch-and-save behaviour, then include it locally. A positive result is execution of the written code.
Hunting notes
This bug hides in dependency directories that are served directly by the web server. During recon, the signal is a path under an application's vendor folder that returns a page rather than a 403 or 404, especially one that looks like a developer tool. Parameters named url, src, file or similar on such pages are worth a request pointing at localhost.
Here that context is Nextcloud on a home network, where the server can reach other local services and the router.
What happened, in plain words
Nextcloud is a piece of software you install on a computer (often a home server) to run your own file storage, calendar, contacts and email. It works like a private version of Google Drive or Gmail that you host yourself. One of its optional add-ons is a mail app, which lets you read and send email from inside Nextcloud.
That mail app includes a small helper library written by someone else, called cerdic/csstidy. CSSTidy is a tool that takes CSS (the language that describes how a web page looks: colours, fonts, spacing) and tidies it up, reformats it and makes it smaller. Libraries like this are common: instead of writing every piece of code yourself, you reuse code other people have already written. This is called a third-party dependency.
CSSTidy, as it happens, also ships with a little web page meant for developers to try the tool out in a browser. That page is called css_optimiser.php. It lets a visitor paste some CSS, or point it at a web address, and see the tidied result. Because the mail app bundles the whole CSSTidy package, that developer playground ended up inside Nextcloud, at a web address anyone can guess.
The problem: that playground page can be told to fetch a web address, and the fetching is done by the Nextcloud server itself, not by your browser. So an attacker can make the server visit addresses the attacker cannot reach directly, such as other machines on the same home network or the home router. This kind of bug is called Server-Side Request Forgery, or SSRF. The researcher who found it reported it to Nextcloud.
Context
Let us unpack the pieces one at a time.
Nextcloud and the mail extension. Nextcloud is a web application: you install it on a server, and people use it through a browser. It has a core, plus optional apps you can switch on. The mail app is one of those optional apps. When you install it, its files are placed in a folder on the server, typically under /apps/mail/.
Third-party libraries and the vendor folder. Developers rarely write everything from scratch. They pull in libraries written by other people, and those libraries are usually stored in a folder called vendor (short for "vendors", the suppliers of code). So /apps/mail/vendor/ is where the mail app keeps the outside code it depends on. Inside that, cerdic/css-tidy/ is the CSSTidy library.
CSS and what CSSTidy does. CSS is the styling language of the web. A CSS file is a list of rules like "make headings blue" or "give this box a border". CSSTidy reads CSS, cleans it up and outputs a tidier, smaller version. It is a parser, formatter and optimiser: parser means it reads and understands the structure, formatter means it rewrites it neatly, optimiser means it makes it more compact.
The developer playground. Besides the library code itself, the CSSTidy package includes a browser-facing test and example page, css_optimiser.php. It is meant for developers to experiment with: paste CSS, or load CSS from a URL, and run it through the optimiser. In the mail app, this file sits at a predictable path under the vendor directory:
/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php
This is a plain file path on the server's disk. The apps/mail/ part is the mail app, vendor/ is the third-party code folder, cerdic/css-tidy/ is the CSSTidy package, and css_optimiser.php is the playground page.
Why the location matters. A web server (the program that answers browser requests, such as Apache or nginx) is usually configured to serve files that sit in a particular folder, called the web root. Anything inside that folder can be requested directly by its path. Nextcloud's own pages go through its application framework, which checks who you are and what you are allowed to do. But a file sitting inside the web root, like this one, is served directly by the web server, outside any of Nextcloud's own routing and access control. The feature it exposes is a developer playground, but on a production instance it behaves as a public endpoint that fetches URLs on the server's behalf.
What an endpoint is. An endpoint is simply a web address that does something when you request it, rather than just showing a static page. The optimiser page is an endpoint: you send it a request, and it performs an action.
Setup
The only precondition is that the mail extension is installed. No account, session or role is needed: the researcher states explicitly that no authentication is required to reach the interface.
Authentication means proving who you are, usually by logging in with a username and password. A session is the server's memory of "this browser is logged in as this person", usually kept in a cookie (a small piece of data the browser stores and sends back with each request). A role is a permission level, such as administrator or ordinary user. None of these are needed here, which is what makes the bug serious: anyone on the internet who can reach the server can use the page.
The reproduction uses a host named example.com as the Nextcloud instance and localhost as the internal target, so no special tooling is involved beyond a browser or an HTTP client. example.com is a placeholder domain name used in documentation to mean "your own server's address". localhost is a special name that always means "this very machine": when the Nextcloud server asks for localhost, it is asking for itself.
Finding it
The researcher identified that the bundled cerdic/csstidy package ships a publicly accessible test/example interface for playing with the CSS formatter and optimiser. The interface offers a "CSS from URL" option, which means the server-side PHP code performs an outbound HTTP request to a URL supplied by the visitor.
Let us break that down. PHP is a programming language commonly used for websites; Nextcloud is written in it. Server-side means the code runs on the server, not in your browser. An outbound HTTP request is the server acting like a browser: it goes out to another address and asks for a page. HTTP is the protocol browsers and servers use to exchange web pages.
So the page has a feature that says: give me a web address, and I will go and fetch it for you. If an attacker chooses that address, the server will fetch whatever the attacker wants, from wherever the server can reach. A server-side fetch of an attacker-chosen URL is the definition of SSRF, and here it is reachable without logging in.
What SSRF means, in everyday terms. Imagine a building with a receptionist who will fetch anything you ask for from any room in the building. Visitors are only supposed to reach the lobby, but if you can ask the receptionist to go into the back offices and bring something back, you have effectively bypassed the door. SSRF is that: you use the server as your errand runner to reach places you could not reach yourself.
The researcher also noted a second behaviour: remote data can be downloaded as a CSS file into a temporary directory at /apps/mail/vendor/cerdic/css-tidy/temp/. A temporary directory is a scratch folder where a program stores files it needs only briefly. On its own the researcher judged this not to be exploitable, and considered it something that would probably need another vulnerability to become useful.
The problematic line in csstidy is referenced as:
https://github.com/Cerdic/CSSTidy/blob/master/css_optimiser.php#L376
This is a link to the CSSTidy source code on GitHub, a website where developers publish and share code. The #L376 part means "line 376 of that file": the specific line where the fetching happens. Pointing at the exact line helps the maintainers find and fix the problem quickly.
The researcher had tried to contact the csstidy developers directly but could not reach them, and reported to Nextcloud so that the upstream project could fix it before csstidy published a fix. Upstream here means the original project that makes the library, as opposed to Nextcloud, which merely bundles it. Reporting to Nextcloud first gives the upstream project time to prepare a fix before the problem becomes public.
Exploitation
Step 1: install the mail extension
Install the mail extension on the Nextcloud instance. This places the vendored csstidy package, including css_optimiser.php, under /apps/mail/vendor/cerdic/css-tidy/.
Why this step: the bug only exists if the mail app, and therefore the bundled CSSTidy package, is present. Installing the app is what puts the vulnerable file on disk in a web-reachable place. This is not something an attacker does; it is what a normal administrator does when setting up email. The point is that the administrator has no idea they are also publishing a developer playground.
Step 2: open the optimiser interface unauthenticated
Visit the interface directly:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php
Line by line:
http://is the protocol, the language browsers and servers speak to exchange pages.example.comis the address of the Nextcloud server (a placeholder for the real one)./apps/mail/vendor/cerdic/css-tidy/css_optimiser.phpis the path to the file on that server: the mail app, its vendor folder, the CSSTidy package, and the playground page.
No authentication is required. The page is the csstidy example interface, which is intended for developers to experiment with the CSS formatter and optimiser. Why this step: before exploiting anything, you confirm the page is reachable at all and that it loads without a login prompt. If it asked for a password, the bug would be much less serious.
Step 3: make the server fetch an arbitrary URL
Either use the interface and set "CSS from URL" at the bottom of the page, or set the url parameter manually:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/test
Line by line:
- Everything up to
css_optimiser.phpis the same page as before. ?marks the start of the query string: extra information sent along with the request.url=is the name of a parameter, a named value the page reads. The page expects a web address here.http://localhost/testis the value being passed: the address the server should fetch.localhostmeans the server itself, and/testis a path on it.
The url parameter carries the address the server will request. Because the request originates from the Nextcloud host, localhost resolves to the server itself, and any other host the server can reach (other services on the local network, the home router) is equally addressable.
Why this step: this is the core of the attack. By putting an address in url, the attacker makes the server visit it. A proxy is a middleman that fetches pages on your behalf; here the server is acting as an unintended proxy.
Step 4: write remote data to the temp directory
To download remote data as a CSS file, either use the interface or request:
http://example.com/apps/mail/vendor/cerdic/css-tidy/css_optimiser.php?url=http://localhost/apps/richdocuments/docs/custom.css&custom=1&template=4
Line by line:
- The page path is the same as before.
url=http://localhost/apps/richdocuments/docs/custom.csstells the server to fetch a CSS file from another app on the same instance.richdocumentsis the name of another Nextcloud app, andcustom.cssis a stylesheet it serves.&separates parameters in a query string.
Here url points at a CSS file served by another app on the same instance, and the request adds the custom=1 and template=4 parameters. The downloaded data lands as a CSS file in:
/apps/mail/vendor/cerdic/css-tidy/temp/
This is a folder path on the server: the mail app, its vendor folder, the CSSTidy package, and a temp scratch folder inside it.
Why this step: fetching a page and showing it is one thing; writing a file to disk is another. Writing files gives an attacker a foothold. The researcher is careful to say this is not exploitable on its own, but it can be combined with another bug later.
Root cause
The mistake is packaging: a development and demonstration script from a third-party library was shipped inside a web-accessible directory of the mail app. The script accepts a URL from the request and performs a server-side fetch of it, with no authentication in front of it and, as far as the report shows, no restriction on which hosts may be contacted. Nextcloud's own authentication and routing do not apply, because the file is served directly from the vendor path rather than through the application framework. The report does not describe any allowlist, network filtering or other control that would have limited the fetch.
An allowlist would be a list of approved addresses the server is permitted to contact. Network filtering would be rules at the network level blocking certain destinations. Neither is mentioned. The essential point is that the developer playground was never meant to be on a live server; it was meant for a developer's own machine. Shipping it inside the app turned a harmless demo into a public door.
Impact
The researcher is candid that SSRF is usually not considered high impact, and would agree on most PHP projects, but gives two reasons why this instance is different. First, the vulnerability can be exploited by an unauthenticated attacker. Second, Nextcloud is also designed to be used on a home network, which opens the possibility of not only attacking other local services but also the router of the home network.
A router is the device that connects a home network to the internet and directs traffic between devices inside the home. If the Nextcloud server can be made to send requests to the router, an attacker can probe it from inside, where it may be less protected than from outside.
The ability to receive and write CSS files can also be used to find out what other services are running on devices in the network, or what kind of router is used, before running additional attacks. This is called reconnaissance: gathering information before an attack. The file-write behaviour on its own is described as not currently exploitable and probably requiring another vulnerability: for example, a Local File Inclusion bug could be turned into a Remote File Inclusion by first creating a CSS file containing PHP code, downloaded from a remote server through the csstidy vulnerability, and then including that local file via the LFI bug.
Let us unpack that chain. Local File Inclusion (LFI) is a bug where a web page can be tricked into loading a file from the server's own disk. Remote File Inclusion (RFI) is the same idea, but loading a file from a remote address. Normally an LFI only lets an attacker read files already on the server. But if the attacker can first write a file to the server (which the csstidy file-write behaviour allows), and that file contains PHP code, then the LFI can be used to load and run that file. The attacker has turned a read-only bug into code execution. This is why the researcher calls the file-write a chain primitive: a building block for a bigger attack, not a complete attack by itself.
Fix
The report itself does not describe the patch. The program points to its published advisory for the resolution:
https://github.com/nextcloud/security-advisories/security/advisories/GHSA-24pm-rjfv-23mh
This is a link to Nextcloud's security advisory page on GitHub. An advisory is a public notice describing a security problem and how it was fixed. The GHSA- part is GitHub's identifier for the advisory.
What the report makes clear is where the fix belongs: the vulnerable code is in csstidy's css_optimiser.php, and the researcher reported to Nextcloud specifically so the upstream project could fix it before csstidy shipped a fix of its own. In plain terms: do not ship the demo page, or make sure nobody can reach it on a live server.
Variants to test
These are ideas for finding similar bugs elsewhere. They are written for someone learning to look for this class of problem.
- Other vendored libraries with example or test scripts. Look for paths such as
vendor/<package>/containing files named like examples, demos, tests or optimisers. A positive result is a script that responds without a session and performs a server-side action such as a fetch. In other words: many libraries ship demo pages, and demo pages are often forgotten about. - URL-accepting parameters on any reachable PHP file. Try a parameter such as
urlpointing at an internal address. A positive result is a response whose content or timing reflects the internal target. Timing matters because even if you cannot see the content, a slow response can tell you something is there. - File-writing modes on the same interface. Try the
customandtemplateparameters alongsideurl. A positive result is a new file appearing under the package'stempdirectory. This is the file-write behaviour from step 4. - Chaining with a file inclusion bug. If you have an LFI, first write a file containing PHP code through the fetch-and-save behaviour, then include it locally. A positive result is execution of the written code. This is the chain described in the impact section.
Hunting notes
This bug hides in dependency directories that are served directly by the web server. During recon, the signal is a path under an application's vendor folder that returns a page rather than a 403 or 404, especially one that looks like a developer tool. A 403 means "forbidden" and a 404 means "not found"; a page that loads normally where you expected one of those is worth a closer look. Parameters named url, src, file or similar on such pages are worth a request pointing at localhost.
Here that context is Nextcloud on a home network, where the server can reach other local services and the router. In other words: be precise about what you can prove, and honest about what you cannot.
Glossary
- Advisory: a public notice describing a security problem and how it was fixed.
- Allowlist: a list of things (here, addresses) that are explicitly permitted.
- Authentication: proving who you are, usually by logging in.
- Bounty: a payment made to a researcher who reports a valid security bug.
- Cookie: a small piece of data a browser stores and sends back to a site, often used to remember a login.
- CSS: the language that describes how a web page looks (colours, fonts, layout).
- CSSTidy: a third-party library that parses, formats and optimises CSS.
- CVSS: a standard scoring system for the severity of a security vulnerability.
- Dependency: code written by someone else that a project reuses.
- Endpoint: a web address that performs an action when requested, rather than just showing a static page.
- HTTP: the protocol browsers and servers use to exchange web pages.
- LFI (Local File Inclusion): a bug where a page can be tricked into loading a file from the server's own disk.
- localhost: a special name that always means "this very machine".
- Outbound request: a request the server makes to another address, rather than one it receives.
- Parameter: a named value sent along with a web request, usually after a
?in the address. - PHP: a programming language commonly used for websites.
- Query string: the part of a web address after
?, carrying extra information. - Reconnaissance: gathering information about a target before attacking it.
- RFI (Remote File Inclusion): a bug where a page can be tricked into loading a file from a remote address.
- Role: a permission level, such as administrator or ordinary user.
- Router: the device that connects a home network to the internet and directs traffic between devices.
- Server-side: code that runs on the server, not in your browser.
- Session: the server's memory of who is logged in, usually kept in a cookie.
- SSRF (Server-Side Request Forgery): a bug where an attacker can make a server fetch an address of the attacker's choosing.
- Third-party: made by someone other than the main project.
- Upstream: the original project that makes a library, as opposed to a project that bundles it.
- Vendor folder: a folder where a project stores third-party libraries.
- Web root: the folder on a server whose contents the web server serves directly.