🛡️ Sentinel: [CRITICAL/HIGH] Fix Unrestricted File Upload via Presigned URLs#152
🛡️ Sentinel: [CRITICAL/HIGH] Fix Unrestricted File Upload via Presigned URLs#152xb1g wants to merge 1 commit into
Conversation
Added strict file validation (type, size, extension) to the `app/api/upload/presigned/route.ts` endpoint using the central `validateFile` utility to prevent unrestricted file uploads. Co-authored-by: xb1g <70068561+xb1g@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
788a332 to
6223d75
Compare
|
Unable to deploy a commit from a private repository on your GitHub organization to the wachaa1319's projects team on Vercel, which is currently on the Hobby plan. In order to deploy, you can:
To read more about collaboration on Vercel, click here. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the presigned upload URL API (/api/upload/presigned) by applying the same centralized server-side file validation rules used by the direct upload endpoints, preventing clients from bypassing MIME/extension/size checks when requesting presigned URLs.
Changes:
- Added centralized
validateFile(...)enforcement (MIME allowlist + dangerous extension blacklist + size limit) before generating presigned Backblaze B2 upload URLs. - Selected allowed MIME sets based on
uploadType(submissionvsmap-content) to align with other upload flows. - Documented the incident and prevention guidance in
.jules/sentinel.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/api/upload/presigned/route.ts | Validates fileName, fileType, and fileSize via shared upload validation utilities before issuing presigned URLs. |
| .jules/sentinel.md | Adds a security log entry describing the presigned upload validation gap and the prevention approach. |
| if (!fileSize || typeof fileSize !== "number" || fileSize <= 0) { | ||
| return NextResponse.json({ error: "Valid fileSize is required" }, { status: 400 }); | ||
| return NextResponse.json( | ||
| { error: "Valid fileSize is required" }, | ||
| { status: 400 }, | ||
| ); | ||
| } |
| **Vulnerability:** User-controlled SVG strings (`avatar.svg_data`) were being injected directly into the DOM using `dangerouslySetInnerHTML`. An attacker could inject an SVG containing embedded malicious `<script>` tags or `onload` event handlers, leading to Stored Cross-Site Scripting (XSS). | ||
| **Learning:** Rendering raw SVGs inline is inherently dangerous. SVGs are essentially XML documents capable of embedding JavaScript. | ||
| **Prevention:** When you need to display user-provided SVGs and you don't need to manipulate their internal paths via CSS/JS, do not use `dangerouslySetInnerHTML`. Instead, render the SVG securely by encoding it as a data URI (`data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`) and using it as the `src` attribute of a standard `<img>` tag. This forces the browser to treat the SVG strictly as an image, entirely disabling any embedded script execution. No newline at end of file | ||
| **Prevention:** When you need to display user-provided SVGs and you don't need to manipulate their internal paths via CSS/JS, do not use `dangerouslySetInnerHTML`. Instead, render the SVG securely by encoding it as a data URI (`data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`) and using it as the `src` attribute of a standard `<img>` tag. This forces the browser to treat the SVG strictly as an image, entirely disabling any embedded script execution. |
5545856 to
637361f
Compare
6fd30ac to
c8ab390
Compare
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
web | 637361f | May 11 2026, 06:36 PM |
🚨 Severity: HIGH
💡 Vulnerability: The presigned URL generation endpoint (
app/api/upload/presigned/route.ts) accepted arbitrary client-providedfileTypeandfileNamestrings without validating them against allowed MIME types or dangerous file extensions.🎯 Impact: An attacker could bypass the strict validation applied in direct upload endpoints and upload malicious files (e.g., executables, scripts, or HTML/SVGs) into cloud storage simply by providing an unvalidated file extension or fake MIME type.
🔧 Fix: Implemented the
validateFilecentral utility function fromlib/constants/upload.tsto strictly validate the file size, MIME type, and extension against whitelists (ALLOWED_GENERAL_TYPES/ALLOWED_DOCUMENT_TYPES) before generating the presigned URL.✅ Verification: Verify by attempting to generate a presigned URL for a disallowed file extension (e.g.
.exe) or MIME type. The endpoint will now return a400 Bad Request. Runpnpm testandpnpm lintto ensure no regressions.PR created automatically by Jules for task 11200405290574331979 started by @xb1g