Skip to content

🛡️ Sentinel: [CRITICAL] Fix missing file extension validation in presigned upload endpoint#150

Open
xb1g wants to merge 1 commit into
mainfrom
sentinel-fix-presigned-upload-validation-17489820446762992084
Open

🛡️ Sentinel: [CRITICAL] Fix missing file extension validation in presigned upload endpoint#150
xb1g wants to merge 1 commit into
mainfrom
sentinel-fix-presigned-upload-validation-17489820446762992084

Conversation

@xb1g

@xb1g xb1g commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

🚨 Severity: CRITICAL
💡 Vulnerability: The /api/upload/presigned endpoint generated Backblaze B2/S3 presigned URLs based strictly on the client-provided fileType MIME string, but did not validate the actual fileName extension against known dangerous files (e.g., .exe, .sh, .html). Because S3/B2 trust the client MIME type and Next.js CDN routing does not double-check files in transit, this could allow an attacker to upload an executable or XSS payload disguised as a valid MIME type.
🎯 Impact: An attacker could execute arbitrary scripts (XSS) via uploaded .html files, or trick users into downloading malicious executable binaries directly from the application's domain.
🔧 Fix: Removed manual, inline string checks for file type and size. Integrated the centralized validateFile utility from @/lib/constants/upload, mapping the request's uploadType to strict sets of permitted extensions and blocking all entries in DANGEROUS_EXTENSIONS.
✅ Verification: Ensure tests pass via pnpm test. Attempting to request a presigned URL with an .exe file name or spoofed MIME type will now correctly return a 400 Bad Request with "File type not allowed for security reasons".


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

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 26, 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 26, 2026 3:55am

Request Review

Copilot AI review requested due to automatic review settings May 11, 2026 17:28
@xb1g xb1g force-pushed the sentinel-fix-presigned-upload-validation-17489820446762992084 branch from d337d82 to 1e8d358 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 strengthens the /api/upload/presigned upload URL broker in the Next.js app by switching from ad-hoc checks to the shared validateFile utility, aiming to prevent dangerous uploads (e.g., executables / script payloads) via spoofed MIME types in presigned S3/B2 uploads.

Changes:

  • Replaced inline fileName / fileType / fileSize validation in app/api/upload/presigned/route.ts with shared validateFile + centralized allowlists/limits.
  • Added a new Sentinel entry documenting the presigned upload validation vulnerability and the intended prevention approach.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
app/api/upload/presigned/route.ts Routes presigned upload requests through centralized file validation rules before generating B2/S3 presigned URLs.
.jules/sentinel.md Documents the vulnerability and prevention guidance for presigned upload validation.

Comment on lines +31 to +38
// Use shared validation logic to enforce secure file types and extensions
const fileValidation = validateFile(
fileName || "",
fileSize || 0,
fileType || "",
allowedTypes,
MAX_FILE_SIZE
);
Comment on lines +31 to +37
// Use shared validation logic to enforce secure file types and extensions
const fileValidation = validateFile(
fileName || "",
fileSize || 0,
fileType || "",
allowedTypes,
MAX_FILE_SIZE
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.## 2024-05-24 - File Extension Validation in Presigned URLs
@xb1g xb1g force-pushed the sentinel-fix-presigned-upload-validation-17489820446762992084 branch 2 times, most recently from be0a653 to 8d7b089 Compare May 11, 2026 17:39
@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 8d7b089 May 11 2026, 06:33 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