This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
Stored Cross Site Scripting (Authenticated) via Unrestricted file upload. #9
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.
📊 Metadata *
Bounty URL: https://huntr.dev/bounties/6-other-monicahq/monica
⚙️ Description *
SVG files are supported by monica, this means that monica is vulnerable to one of the oldest XSS attacks in the book. I added a ‘sanitiser’ to clear SVG files from any executable code e.g. the
onload=
attribute.💻 Technical Description *
I added an
if (extension == ‘svg’)
(pseudocode) to check whether the uploaded file is a *.svg file if so, it calls$this->sanitiseSVG()
. Then, I create aDOMDocument
object to parse the file as XML and make my life 100% easier. Finally, I loop through all SVG elements and check whether the element is in the whitelist (from https://github.com/alnorris/SVG-Sanitizer/blob/master/SvgSanitizer.php ) - I used a whitelist here in case the SVG specification changes to add additional scripting features - if the element isn’t in the whitelist, I remove it; if it is, I then loop through all of it’s attributes using a similar whitelist (again, from the above link) and remove if necessary. Unfortunately, this fix only applies to newly uploaded images, so old images, or images sent from an older version, could still have an effect.🐛 Proof of Concept (PoC) *
Anywhere you can upload images (contact’s profile tab for this example), upload a *.svg file with an
onload=
attribute or something similar, e.g.gives this response:
🔥 Proof of Fix (PoF) *
The same SVG file used above no longer causes the alert.
👍 User Acceptance Testing (UAT)
N/A