Skip to content

feat(upload): implement secure file upload with validation and multi-provider support#507

Merged
Qoder-Undefined merged 1 commit into
MERIDIAN-CITY:mainfrom
dDevAhmed:feature/issue-451-secure-file-upload
Jun 21, 2026
Merged

feat(upload): implement secure file upload with validation and multi-provider support#507
Qoder-Undefined merged 1 commit into
MERIDIAN-CITY:mainfrom
dDevAhmed:feature/issue-451-secure-file-upload

Conversation

@dDevAhmed

Copy link
Copy Markdown
Contributor
  • Add strict MIME-type validation via NestJS FileTypeValidator (header level)
  • Add magic-byte validation in UploadService to prevent MIME-spoofing attacks
  • Sanitize filenames: strip path traversal, double extensions, and special chars
  • LocalStorageProvider: safe dir creation (0o755), path-traversal guard on write
  • S3StorageProvider: real @aws-sdk/client-s3 PutObjectCommand integration, supports explicit credentials or SDK default credential chain
  • Add upload.config.ts using registerAs() pattern (consistent with jwt.config.ts)
  • Add shared sanitizeFilename() utility (DRY across both providers)
  • Add unit tests: 39 tests across 5 suites covering happy paths and edge cases (spoofed MIME, path traversal, double extension, missing config, SDK errors)

Closes #451

…provider support

- Add strict MIME-type validation via NestJS FileTypeValidator (header level)
- Add magic-byte validation in UploadService to prevent MIME-spoofing attacks
- Sanitize filenames: strip path traversal, double extensions, and special chars
- LocalStorageProvider: safe dir creation (0o755), path-traversal guard on write
- S3StorageProvider: real @aws-sdk/client-s3 PutObjectCommand integration,
  supports explicit credentials or SDK default credential chain
- Add upload.config.ts using registerAs() pattern (consistent with jwt.config.ts)
- Add shared sanitizeFilename() utility (DRY across both providers)
- Add unit tests: 39 tests across 5 suites covering happy paths and edge cases
  (spoofed MIME, path traversal, double extension, missing config, SDK errors)

Closes MERIDIAN-CITY#451

@Qoder-Undefined Qoder-Undefined left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM nicely done @dDevAhmed thank you for your contribution

@Qoder-Undefined Qoder-Undefined merged commit 7faa717 into MERIDIAN-CITY:main Jun 21, 2026
1 check 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.

Add File Upload Validation and Security in Upload Module

2 participants