Skip to content

🛡️ Sentinel: [CRITICAL/HIGH] Fix Unrestricted File Upload via Presigned URLs#152

Open
xb1g wants to merge 1 commit into
mainfrom
sentinel/fix-presigned-url-upload-vuln-11200405290574331979
Open

🛡️ Sentinel: [CRITICAL/HIGH] Fix Unrestricted File Upload via Presigned URLs#152
xb1g wants to merge 1 commit into
mainfrom
sentinel/fix-presigned-url-upload-vuln-11200405290574331979

Conversation

@xb1g

@xb1g xb1g commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

🚨 Severity: HIGH
💡 Vulnerability: The presigned URL generation endpoint (app/api/upload/presigned/route.ts) accepted arbitrary client-provided fileType and fileName strings 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 validateFile central utility function from lib/constants/upload.ts to 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 a 400 Bad Request. Run pnpm test and pnpm lint to ensure no regressions.


PR created automatically by Jules for task 11200405290574331979 started by @xb1g

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pseed Ready Ready Preview, Comment Mar 27, 2026 3:46am

Request Review

Copilot AI review requested due to automatic review settings May 11, 2026 17:28
@xb1g xb1g force-pushed the sentinel/fix-presigned-url-upload-vuln-11200405290574331979 branch from 788a332 to 6223d75 Compare May 11, 2026 17:28
@vercel

vercel Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

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:

  • Make your repository public or
  • Upgrade to Pro. A Pro subscription is required to deploy from a private organization repository.

To read more about collaboration on Vercel, click here.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 (submission vs map-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.

Comment on lines 56 to 61
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 },
);
}
Comment thread .jules/sentinel.md
**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.
@xb1g xb1g force-pushed the sentinel/fix-presigned-url-upload-vuln-11200405290574331979 branch 2 times, most recently from 5545856 to 637361f Compare May 11, 2026 17:39
@xb1g xb1g force-pushed the main branch 2 times, most recently from 6fd30ac to c8ab390 Compare May 11, 2026 18:12
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 11, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
web 637361f May 11 2026, 06:36 PM

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.

2 participants