Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(file-ext): prevent users from bypassing checks on file extensions #1157

Merged
merged 7 commits into from
Feb 22, 2024

Conversation

seaerchin
Copy link
Contributor

Problem

Previously, we accept the extension provided by our users (in the fileName) and saved that to github + serve it on the final site.

This led to problems where svg + html comments led to js being exploited and served to end users. More generally, this also meant that we could serve arbitrary extensions to end users as long as their data-type was valid (in ALLOWED_EXTENSIONS)

Solution

In order to solve this issue, we construct the filename using the inferred filetype for binary data formats. For string formats (eg: svg), we rely on a 2 fold strategy:

  1. first, we check first enclosing element is svg
  2. however, that check alone is insufficient as malicious js could be hiding in html elements - hence, we will also use DOMPurify to sanitise the contents of the provided string data.

@seaerchin seaerchin requested a review from a team February 21, 2024 09:30
@seaerchin seaerchin merged commit 5c56c74 into develop Feb 22, 2024
12 checks passed
@seaerchin seaerchin deleted the fix/bypass-file-restrictions branch February 22, 2024 07:42
@alexanderleegs alexanderleegs mentioned this pull request Feb 22, 2024
6 tasks
alexanderleegs added a commit that referenced this pull request Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants