Skip to content

🛡️ Sentinel: [HIGH] Enforce file validation on presigned URL uploads#149

Open
xb1g wants to merge 1 commit into
mainfrom
sentinel/fix-presigned-url-file-validation-1725661310791907418
Open

🛡️ Sentinel: [HIGH] Enforce file validation on presigned URL uploads#149
xb1g wants to merge 1 commit into
mainfrom
sentinel/fix-presigned-url-file-validation-1725661310791907418

Conversation

@xb1g

@xb1g xb1g commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

🚨 Severity: HIGH
đź’ˇ Vulnerability: The presigned upload URL endpoint (app/api/upload/presigned/route.ts) accepted arbitrary fileName and fileType parameters from the client and verified only fileSize. An attacker could request an upload URL and successfully upload malicious files (e.g., executables .exe or web pages .html/.svg) into the system, bypassing client-side validation logic.
🎯 Impact: If exploited, attackers could use the application's storage buckets to host and distribute malicious executables, phishing pages, or XSS payloads via direct object URLs, putting other users at risk.
đź”§ Fix: Imported and integrated the centralized validateFile utility from @/lib/constants/upload. It now rigorously checks the provided fileName for dangerous extensions, verifies the fileType matches an explicitly allowed MIME type (ALLOWED_GENERAL_TYPES), and enforces the standardized size limit (MAX_GENERAL_SIZE) before returning an authorized upload URL.
âś… Verification: Attempting to request a presigned URL with a .exe extension or an invalid MIME type now correctly triggers a 400 Bad Request with an appropriate validation error message (e.g., "File type not allowed for security reasons"), preventing upload URL generation.


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

- Replaced weak size-only check in `app/api/upload/presigned/route.ts` with comprehensive server-side file validation.
- Validates the requested file name (blocking dangerous extensions like .exe, .html) and file type against the established `ALLOWED_GENERAL_TYPES` and `MAX_GENERAL_SIZE` constants prior to generating the B2 presigned URL.
- Prevents attackers from bypassing client restrictions and directly uploading malicious files to the storage bucket.

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 25, 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 25, 2026 4:10am

Request Review

@xb1g xb1g force-pushed the sentinel/fix-presigned-url-file-validation-1725661310791907418 branch from 05c62f0 to 8931ee6 Compare May 11, 2026 17:28
Copilot AI review requested due to automatic review settings 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

Hardens the presigned-upload API route by reusing the centralized upload validation rules so the backend (not just the client) enforces file constraints before issuing a Backblaze B2 presigned PUT URL.

Changes:

  • Integrates validateFile() into app/api/upload/presigned/route.ts to validate fileName, fileType, and fileSize against shared allowlists/limits.
  • Replaces the route’s local max-size check with shared constants (ALLOWED_GENERAL_TYPES, MAX_GENERAL_SIZE).
  • Documents the vulnerability and mitigation 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 Adds centralized server-side validation before generating presigned upload URLs.
.jules/sentinel.md Records the presigned-upload validation issue and prevention guidance.

Comment on lines +40 to +44
const fileValidation = validateFile(
fileName,
fileSize,
fileType,
ALLOWED_GENERAL_TYPES,
Comment on lines +40 to +44
const fileValidation = validateFile(
fileName,
fileSize,
fileType,
ALLOWED_GENERAL_TYPES,
@xb1g xb1g force-pushed the sentinel/fix-presigned-url-file-validation-1725661310791907418 branch 2 times, most recently from 239069e to b7600ad 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 b7600ad May 11 2026, 06:24 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