Skip to content

fix(files): fix vulnerabilities in file uploads/deletes#1130

Merged
waleedlatif1 merged 3 commits intostagingfrom
fix/vulnerabilities
Aug 25, 2025
Merged

fix(files): fix vulnerabilities in file uploads/deletes#1130
waleedlatif1 merged 3 commits intostagingfrom
fix/vulnerabilities

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Path Traversal Vulnerability (Delete) - [BUG] Arbitrary File Deletion #959

  • Added path sanitization to extractFilename() function that strips all ../ sequences to prevent directory traversal attacks while preserving legitimate file operations

  • File Upload XSS Vulnerability - [BUG] Insecure File Upload #958

    • Implemented file extension allowlist that only permits safe file types and blocks dangerous files like HTML, SVG, and JavaScript
    • Added secure file serving with safe content-type overrides and Content-Disposition headers

Type of Change

  • Other: Security

Testing

Added unit tests, manually tested in the file upload and delete with the file block.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 25, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 25, 2025 6:27pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 25, 2025 6:27pm

@vercel vercel bot temporarily deployed to Preview – docs August 25, 2025 18:22 Inactive
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR addresses two critical security vulnerabilities in the file upload and deletion system:

Path Traversal Vulnerability (Issue #959): The extractFilename() function in apps/sim/app/api/files/utils.ts has been hardened with comprehensive path sanitization that strips all ../ sequences using multiple regex patterns. This prevents attackers from using directory traversal attacks to delete arbitrary system files while preserving legitimate cloud storage paths like s3/ and blob/.

File Upload XSS Vulnerability (Issue #958): A multi-layered security approach has been implemented:

  • File extension allowlist in the upload route that only permits safe file types (PDF, DOC, TXT, images, etc.) and blocks dangerous files like HTML, SVG, and JavaScript
  • Enhanced file serving security with content-type overrides that force dangerous file types to be served as attachments with application/octet-stream
  • Security headers including Content-Security-Policy and X-Content-Type-Options to prevent script execution
  • Authentication requirements for file uploads

The changes also remove SVG files from the UI file picker (user-input.tsx) to prevent users from easily selecting potentially dangerous files. Comprehensive test coverage has been added across utils.test.ts and route.test.ts to validate all security measures and ensure backward compatibility with existing cloud storage functionality.

Confidence score: 4/5

  • This PR addresses critical security vulnerabilities with well-implemented defense-in-depth measures
  • Score reflects the complexity of security changes that require careful validation in production environments
  • Pay close attention to apps/sim/app/api/files/utils.ts and apps/sim/app/api/files/upload/route.ts for core security implementations

5 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 45372ae into staging Aug 25, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/vulnerabilities branch August 25, 2025 18:26
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…1130)

* fix(vulnerability): fix arbitrary file deletion vuln

* fix(uploads): fix vuln during upload

* cleanup
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.

1 participant