fix(upload): verify file signatures and reject image bombs for vehicle uploads - #226
Open
vjuliaife wants to merge 1 commit 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
Vehicle image uploads accepted the caller-provided Content-Type header and wrote bytes directly to storage without running the KYC-grade file signature checks. A file labeled as an image could contain another format, be a header-only MIME spoof, or declare pathological pixel dimensions (decompression bomb).
Changes
lib/security/kyc-file-validation.ts: added per-format magic-byte dimension decoders for JPEG (SOF marker walk), PNG (IHDR chunk), and WebP (VP8/VP8L/VP8X chunks). Declared image formats are now checked against shared, exported bounds (MAX_IMAGE_DIMENSION_PX,MAX_IMAGE_PIXELS) and rejected when dimensions cannot be decoded (malformed/truncated) or exceed the bounds (decompression bomb).app/api/upload/route.ts: the vehicle upload branch now calls the shared file validator before writing bytes to Blob storage, mirroring the existing KYC branch, and logs avehicle.image.upload.rejectedaudit event on rejection, consistent with the existingkyc.document.upload.rejectedpattern.__tests__/lib/security/kyc-file-validation.test.ts: updated existing fixtures to include real, decodable image dimensions, and added coverage for truncated images, oversized dimensions, and decompression-bomb pixel counts, plus confirmation that PDF uploads are unaffected by the new checks.Issues
Resolves #190
Verification
cargo buildwas not run.cargo testwas not run.