Skip to content

fix: validate uploaded files using magic bytes#76

Open
charu2210 wants to merge 1 commit into
quantumstack-labs:mainfrom
charu2210:fix-file-signature-validation
Open

fix: validate uploaded files using magic bytes#76
charu2210 wants to merge 1 commit into
quantumstack-labs:mainfrom
charu2210:fix-file-signature-validation

Conversation

@charu2210

@charu2210 charu2210 commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Implemented file signature (magic byte) validation for uploaded files to prevent spoofed uploads that bypass extension or MIME-type checks.

Changes Made

  • Added validateFileSignature middleware using file-type
  • Validates actual file content instead of relying only on extensions/MIME types
  • Rejects malformed or spoofed files with clear error messages
  • Removes invalid uploaded files from disk before returning an error
  • Integrated validation into the /answer-sheet upload route

Testing

  • Renamed a .txt file to .pdf → correctly detected as invalid and rejected
  • Verified that genuine PDF files are detected correctly through file signature analysis

Expected Outcome

  • Fake files (e.g. .txt renamed to .pdf) are rejected
  • Valid PDFs and supported images are accepted
  • Upload validation is more secure and reliable

Fixes #63

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.

[Security]: File upload validation can be bypassed using spoofed extensions and MIME types

1 participant