Stored XSS on Share-popup of a directory's Gallery-view
A parameter in the sharing endpoint changed from an integer to a string and was not sanitised, allowing stored cross-site scripting. An authenticated attacker could share a folder with a malicious name and execute script when the victim opened the sharing window in the Gallery view.
Originally disclosed on HackerOne
- Triaged in under an hour
- Fixed in 18 days
- Paid in 9 hours
- Disclosed after 32 days
Summary by the program
Due to a recent migration of the Gallery app to the new sharing endpoint a parameter changed from an integer to a string value. This value wasn't sanitized before and was thus now vulnerable to a Cross-Site-Scripting attack.
To exploit this vulnerability an authenticated attacker has to share a folder with someone else, get them to open the shared folder in the Gallery app and open the sharing window there.
Since Nextcloud employes a strict Content-Security-Policy this vulnerability is only exploitable in browsers not supporting Content-Security-Policy. You can check at caniuse.com whether your browser supports CSP.
A detailed advisory can be found at https://nextcloud.com/security/advisory/?id=nc-sa-2016-001.
Thanks a lot, @fransrosen for pointing out this regression!
The report
Hi, Nice with the program launch! Congrats!
I noticed that there was a Share-icon when toggling to the Gallery-view of a directory under "Nextcloud Files":

If your directory has a malicious name such as a HTML-payload: <img src=x onerror=alert(1)>, this HTML will run when clicking on the Share-icon:

I see that you have a proper CSP in place, but remember that Internet Explorer is not there yet:

Also, since any user could create files, a user could potentially execute this for an admin (if that admin is not using a CSP-supported browser that is).
Let me know if you need more information.
Regards, Frans
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 a parameter in the sharing endpoint changed from an integer to a string and was not sanitised before being rendered.
Impact
An authenticated attacker could execute script in the victim's browser, potentially even an admin, but only if the victim uses a browser without Content-Security-Policy support.
What the attacker needed
Authenticated attacker; victim opens shared folder in Gallery; victim uses browser without CSP
How it was found
- Share a folder with another user.
- Get the victim to open the shared folder in the Gallery app.
- Open the sharing window in the Gallery view.
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.
When you share a folder, its name is shown in a pop-up. The app failed to clean the folder name, so a name containing code could run as a script in the victim's browser. This only works in browsers that do not enforce a security rule called Content-Security-Policy.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.