fix: sanitize pdf url to prevent XSS on inline PDFs #1832
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi team,
Consider the following example, which can trigger an alert popup when inline PDFs are unsupported (like on mobile devices):
The issue arises because PDFObject uses
innerHTML
to insert concatenated fallbackHTML, which could lead to XSS vulnerabilities. For more information, refer to pipwerks/PDFObject#296This 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.