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

Validation of file types #573

Merged
merged 5 commits into from
Nov 13, 2023

Conversation

Nnachevvv
Copy link
Member

@Nnachevvv Nnachevvv commented Nov 3, 2023

Closes #515

This PR provides mechanism to validate the file type uploaded to the backend. I added two types of validation , since using only the extension is not secure enough. Now we will support the following extension and mime types:

  const allowedExtensions = /txt|json|jpeg|jpg|png|xml|xlsx|xls|docx/
  const mimeAllowlist = [
    'text/plain',
    'application/json',
    'application/pdf',
    'image/png',
    'image/jpeg',
    'application/xml',
    'text/xml',
    'application/msword',
    'application/vnd.ms-excel',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  ]

Motivation and context

Testing

Tried to upload one valid and invalid file:
Screenshot 2023-11-03 at 21 40 24
Failed with:
Screenshot 2023-11-03 at 21 40 45

Allowed mime type and not allowed extension:
Screenshot 2023-11-03 at 21 49 54

Screenshot 2023-11-03 at 21 50 04

Copy link

github-actions bot commented Nov 3, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.

@igoychev igoychev requested a review from slavcho November 7, 2023 14:39
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Nov 13, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Nov 13, 2023
Comment on lines 24 to 34
const mimeAllowlist = [
'text/plain',
'application/json',
'image/png',
'image/jpeg',
'application/xml',
'text/xml',
'application/msword',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add a pdf as allowed too

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@Nnachevvv Nnachevvv requested a review from igoychev November 13, 2023 07:59
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Nov 13, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Nov 13, 2023
Copy link
Contributor

@igoychev igoychev left a comment

Choose a reason for hiding this comment

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

Looks great!

@igoychev igoychev merged commit 3941038 into podkrepi-bg:master Nov 13, 2023
11 of 12 checks passed
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.

Validate file types on upload
2 participants