hackmdio / codimd

CodiMD - Realtime collaborative markdown notes on all platforms.
https://hackmd.io/c/codimd-documentation
GNU Affero General Public License v3.0
9.1k stars 1.05k forks source link

fix: sanitize pdf url to prevent XSS on inline PDFs #1832

Closed EastSun5566 closed 6 months ago

EastSun5566 commented 6 months ago

Hi team,

Consider the following example, which can trigger an alert popup when inline PDFs are unsupported (like on mobile devices):

# XSS 6

<span class="pdf raw" data-pdfurl="'><iframe srcdoc='ww<script src=&quot;https://www.google.com/complete/search?client=chrome&q=123&jsonp=alert(document.domain)//&quot;></script>'></iframe><p data-x='"></span>

The issue arises because PDFObject uses innerHTML to insert concatenated fallbackHTML, which could lead to XSS vulnerabilities. For more information, refer to https://github.com/pipwerks/PDFObject/issues/296

This can be seen in the code at the following locations:

https://github.com/pipwerks/PDFObject/blob/2c0bbd90d4de64598ff6df9e1af32de2d58a6eb9/pdfobject.js#L275 https://github.com/pipwerks/PDFObject/blob/2c0bbd90d4de64598ff6df9e1af32de2d58a6eb9/pdfobject.js#L323-L329

I think we should sanitize the URL before passing it to PDFObject.embed. This approach should fix the problem.