File Upload lead to Stored XSS bypass csp in btcpayserver/btcpayserver

Valid

Reported on

Feb 9th 2023


Description

Stored cross-site scripting (also known as second-order or persistent XSS) arises when an application receives data from an untrusted source and includes that data within its later HTTP responses in an unsafe way.

1-Login to your application and create a Store called “Test” make all the other details as default

  1. Navigate to “ Store Settings—>General” Tab
  2. Under the “Branding” Section there is a “ Choose File” To select a Logo for our Store.
  3. Select “Choose File” Option to Select an Image, Select any “.png” image you want.
  4. Intercept the Post-Request for “Choose File” Option using Burpsuite
  5. First delete the Content of uploaded “ png file “ then change the extension from “.png” to “.php” i.e( filename= "profile-picture.php") and in the Content add the below payload

##Payload: ```%PDF-1.3 %���� 1 0 obj <</Pages 2 0 R /Type /Catalog>> endobj 2 0 obj <</Count 1 /Kids [3 0 R] /Type /Pages>> endobj 3 0 obj <</AA <</O <</JS ( try { app.alert("bypass CSP XSS") } catch (e) { app.alert(e.message); } ) /S /JavaScript>>>> /Annots [] /Contents 4 0 R /MediaBox [0 0 612 792] /Parent 2 0 R /Resources <</Font <</F1 <</BaseFont /Helvetica /Subtype /Type1 /Type /Font>>>>>> /Type /Page>> endobj 4 0 obj <</Length 21>> stream

BT /F1 24 Tf ET

endstream endobj xref 0 5 0000000000 65535 f 0000000015 00000 n 0000000062 00000 n 0000000117 00000 n 0000000424 00000 n trailer

<</Root 1 0 R /Size 5>> startxref 493 %%EOF

7.  send the request and open the image you can see the xss 






# Impact




XSS can cause a variety of problems for the end user that range in severity from an annoyance to complete account compromise. The most severe XSS attacks involve disclosure of the user's session cookie, allowing an attacker to hijack the user's session and take over the account.

References

We are processing your report and will contact the btcpayserver team within 24 hours. a month ago
We have contacted a member of the btcpayserver team and are waiting to hear back a month ago
Nicolas Dorier
a month ago

This should already have been reported, and fixed 3 days ago. And I can't reproduce since then. Please try to upload a file on https://mainnet.demo.btcpayserver.org/ and give me the link to it.

If you can show a javascript alert, I will mark this valid.

Nicolas Dorier
a month ago

I tried to browse the link in the video show casing the CSP https://mainnet.demo.btcpayserver.org/LocalStorage/46233dda-aef4-43fb-b081-6f98ecd62b4f-cspxss.php but it is not found. I don't think I mispelled

Nayef Hamouda
a month ago

Researcher


You can try this url, I re-uploaded it

https://mainnet.demo.btcpayserver.org/LocalStorage/20ae0aba-2b3b-4b6e-952a-544d4ef6c51a-exploit.php

This is also another poc that proves that I am able to print javascript codes

https://www.youtube.com/watch?v=HE34men1sKc

Nicolas Dorier validated this vulnerability a month ago

How the fuck is it possible? We pushed a fix with "script-src: ;" yestersday, but this doesn't stop this one...

Nayef Hamouda has been awarded the disclosure bounty
The fix bounty is now up for grabs
The researcher's credibility has increased: +7
Nicolas Dorier
a month ago

Do you have a suggestion to prevent this? We can't really detect the type of file that is uploaded just reading from the content of the file. There will always have a way to avoid the detection...

Nayef Hamouda
a month ago

Researcher


You can prevent uploading files except in certain formats Or you can check the body of the file uploaded by the user

Nicolas Dorier
a month ago

https://github.com/btcpayserver/btcpayserver/pull/4635

Nayef Hamouda
a month ago

Researcher


Can I get a CVE for this report?

Nicolas Dorier
a month ago

yes

Nayef Hamouda
a month ago

Researcher


When can i get my cve number

Nicolas Dorier
a month ago

when I made a release, tomorrow probably

Nicolas Dorier marked this as fixed in 1.7.12 with commit f2f3b2 a month ago
The fix bounty has been dropped
This vulnerability has been assigned a CVE
Nicolas Dorier published this vulnerability a month ago
Nicolas Dorier
a month ago

https://mainnet.demo.btcpayserver.org/LocalStorage/20ae0aba-2b3b-4b6e-952a-544d4ef6c51a-exploit.php

Isn't executable anymore, and pdf can't be uploaded anymore either.

to join this conversation