Skip to content
XSS Disclosed report Intermediate CVE-2022-39338

[user_oidc] Stored XSS via Authorization Endpoint - Safari-Only

The user_oidc app built a meta refresh tag from the OIDC provider's authorization_endpoint without encoding it, for Safari user agents only. An attacker who controls the discovery endpoint could inject markup that runs script in the Nextcloud origin, though the endpoint's restrictive CSP blocked execution in the tested case.

lauritz Follow

Originally disclosed on HackerOne

  • Triaged in 2 hours
  • Fixed in 40 days
  • Paid in 2 months
  • Disclosed after 4 months

Summary:

The OpenID Connect User Backend allows users to login to Nextcloud using SSO.

A workaround that was apparently implemented for the Safari browser enables stored Cross-Site-Scripting (XSS). The vulnerability only affects user agents that include "Safari" within their user agent string and is further limited by a restrictive Content-Security-Policy that is applied on the affected endpoint.

Vulnerable Code

/var/www/html/custom_apps/user_oidc/lib/Controller/LoginController.php

PHP
		// Workaround to avoid empty session on special conditions in Safari
		// https://github.com/nextcloud/user_oidc/pull/358
		if ($this->request->isUserAgent(['/Safari/']) && !$this->request->isUserAgent(['/Chrome/'])) {
			return new Http\DataDisplayResponse('<meta http-equiv="refresh" content="0; url=' . $url . '" />');
		}

Exploit/Steps To Reproduce

  1. Setup Nextcloud using the docker image:
CONSOLE
$ docker run -p 8081:80 nextcloud:latest
  1. Enable user_oidc module via http://localhost:8081/settings/apps/integration/user_oidc
  2. Configure plugin via http://localhost:8081/settings/admin/user_oidc - add a provider with arbitrary identifier, client_id and client_secret. Include the following URL as discovery endpoint: https://lhq.at/poc_jkhfdasgfdaskjlfadskhfdas.php.
xss1.png
xss1.png From the original on HackerOne

The mocked discovery endpoint responds as follows:

HTTP
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[...]

{
  "issuer":"http:\/\/idp.local:3000",
  "authorization_endpoint":"'\" http-equiv=><svg\/onload=alert(document.domain)>",
[...]
} 
  1. Launch a login flow using a Safari browser: http://localhost:8081/login.

Nextcloud responds as follows without sufficiently encoding or filtering the authorization_endpoint:

HTTP
HTTP/1.1 200 OK
Date: Wed, 31 Aug 2022 12:47:57 GMT
Server: Apache/2.4.54 (Debian)
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Robots-Tag: none
X-XSS-Protection: 1; mode=block
X-Powered-By: PHP/8.0.21
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Security-Policy: default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'
X-Request-Id: yUWr3aQshJ5OHyMuzG1j
Feature-Policy: autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'
Content-Disposition: inline; filename=""
Vary: Accept-Encoding
Content-Length: 492
Connection: close
Content-Type: text/html; charset=UTF-8

<meta http-equiv="refresh" content="0; url='" http-equiv=><svg/onload=alert(document.domain)>?client_id=test.local&response_type=code&scope=openid+email+profile&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2Fapps%2Fuser_oidc%2Fcode&claims=%7B%22id_token%22%3A%7B%22email%22%3Anull%2C%22name%22%3Anull%2C%22quota%22%3Anull%7D%2C%22userinfo%22%3A%7B%22email%22%3Anull%2C%22name%22%3Anull%2C%22quota%22%3Anull%7D%7D&state=FB8IZL2JE55LJ1Y5HJAINPY6OTDQ16P1&nonce=356M5O3J1PKMRKJNBKE40RUGJA06O40E" />

The execution of JavaScript is prevented by the Content-Security-Policy header:

xss2.png
xss2.png From the original on HackerOne

Impact

Stored XSS. The impact is limited due to the restrictive CSP that is applied on this endpoint.

The original report as published on HackerOne, by lauritz. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

The authorization_endpoint value from the identity provider's discovery document was concatenated into an HTML meta refresh tag without HTML encoding, in a Safari-specific code path.

Impact

Stored XSS in the Nextcloud origin for Safari users, but the impact is limited because the restrictive CSP on the endpoint prevented JavaScript execution in the reported test.

What the attacker needed

Control of the OIDC discovery endpoint; victim uses a Safari user agent; CSP must not block the injected script

How it was found

  1. Run a Nextcloud instance, for example with the official Docker image.
  2. Enable the user_oidc app and add an identity provider whose discovery endpoint is attacker-controlled.
  3. Make the discovery document return a malicious authorization_endpoint value.
  4. Start the login flow from a Safari browser.
  5. Observe the unencoded value reflected into the meta refresh response, with script execution blocked by CSP.

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.

Nextcloud can log people in through an external identity provider, and it reads that provider's settings from a URL. The app pasted one of those settings straight into a web page without cleaning it, so text from the provider could become part of the page. A strict browser rule (Content-Security-Policy) stopped the injected script from running in the test.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by lauritz

View all

7 more disclosed reports, best first.

More from Nextcloud

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.