Feature/secure file upload#2184
Open
AdityaPaneru wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds file upload security scanning using pompelmi + ClamAV before any
file is written to disk or committed to the database.
Closes #2169
Changes
New files
src/files/infrastructure/uploader/scan/file-scan.service.ts— sharedFileScanServiceusing pompelmiscanBufferwith ClamAVModified files
src/files/infrastructure/uploader/local/files.module.ts— switched tomemoryStorage, addedFileScanServiceto providerssrc/files/infrastructure/uploader/local/files.service.ts— scans buffer before writing to disk, only writes to disk if scan passessrc/files/infrastructure/uploader/s3-presigned/files.module.ts— switched tomemoryStorage, addedFileScanServiceto providerssrc/files/infrastructure/uploader/s3-presigned/files.service.ts—create()now points presigned URL to quarantine bucket, addedconfirmUpload()which scans and promotes to production bucketsrc/files/infrastructure/uploader/s3-presigned/files.controller.ts— addedPOST /files/confirmendpointsrc/files/infrastructure/uploader/s3-presigned/dto/file-confirm.dto.ts— new DTO for confirm endpointdocs/file-uploading.md— added scanning documentation with mermaid flow diagramsenv-example-relational— addedAWS_DEFAULT_S3_BUCKET_QUARANTINE,CLAMAV_HOST,CLAMAV_PORTHow it works
Local driver
memoryStorage422returned, nothing touches diskS3 presigned driver
POST /files/uploadreturns presigned URL pointing to quarantine bucketPOST /files/confirmdownloads from quarantine and scans the buffer422returnedWhat it catches
Prerequisites
ClamAV must be running:
Testing
yarn buildpasses with 0 errorsyarn lintpasses with 0 errors