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

feat: validate and sanitize media files #249

Merged
merged 2 commits into from
Aug 5, 2021

Conversation

prestonlimlianjie
Copy link
Contributor

@prestonlimlianjie prestonlimlianjie commented Aug 4, 2021

This PR adds a feature to:

  • validate the file extension types of media file uploads (["pdf","png","jpg","gif","tif","bmp","ico", "svg"])
  • if the file extension type is svg, we sanitize its content before uploading it to GitHub

This PR can be reviewed independently of the CMS frontend PR. It partially solves https://github.com/isomerpages/isomer-product/issues/27.

Key points to take note of

file-type can detect most of the whitelisted file extensions, except for svg

We use the file-type library to determine the file extension of the uploaded file. However, the library cannot determine if the file is of type svg - the author gave the following reason:

Detecting it requires a full-blown parser. Check out is-svg for something that mostly works.

As such, we use the is-svg library to help us detect svg files.

Added dependencies

  • is-svg
  • dompurify
  • file-type
  • jsdom - required by dompurify if not used in a DOM context (i.e. node backend)

Added development dependencies

none

Copy link
Contributor

@alexanderleegs alexanderleegs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@prestonlimlianjie prestonlimlianjie merged commit ec4ee31 into develop Aug 5, 2021
lamkeewei added a commit that referenced this pull request Aug 23, 2021
* develop: (24 commits)
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  fix: upgrade dependencies (#242)
  ...
lamkeewei added a commit that referenced this pull request Aug 23, 2021
…token-middleware

* feat/identity/database-models: (25 commits)
  feat: add github_id column to user model
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  ...
lamkeewei added a commit that referenced this pull request Aug 23, 2021
…/email-login

* feat/identity/site-token-middleware: (25 commits)
  feat: add github_id column to user model
  Refactor/collection pages refactor (#215)
  build(deps): bump dompurify from 2.3.0 to 2.3.1 (#264)
  Introduce standard issue templates (#58)
  build(deps): bump cookie-parser from 1.4.4 to 1.4.5 (#261)
  build(deps): bump path-parse from 1.0.6 to 1.0.7 (#255)
  build(deps-dev): bump eslint-plugin-prettier from 3.3.1 to 3.4.0 (#229)
  build(deps-dev): bump lint-staged from 11.0.0 to 11.1.2 (#251)
  build(deps): bump morgan from 1.9.1 to 1.10.0 (#228)
  build(deps-dev): bump eslint-plugin-import from 2.22.1 to 2.23.4 (#223)
  build(deps): bump moment-timezone from 0.5.31 to 0.5.33 (#221)
  fix: upgrade bluebird from 3.7.0 to 3.7.2 (#239)
  fix: upgrade http-errors from 1.6.3 to 1.8.0 (#238)
  fix: upgrade js-base64 from 2.5.1 to 2.6.4 (#237)
  build(deps): bump dotenv from 8.1.0 to 10.0.0 (#219)
  fix: upgrade query-string from 6.8.3 to 6.14.1 (#235)
  [develop] fix: update logout (#252)
  feat: validate and sanitize media files (#249)
  Fix: update path to netlify.toml (#248)
  fix: add helmet for security (#243)
  ...
@prestonlimlianjie prestonlimlianjie deleted the feat/validate-and-sanitize-media-files branch September 7, 2021 06:52
harishv7 pushed a commit that referenced this pull request Feb 17, 2023
* feat: validate media file extension types

* feat: detect and sanitize SVG
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