Security fixes: path traversal, filename injection, input validation, error leakage#204
Draft
Copilot wants to merge 25 commits intodevelopmentfrom
Draft
Security fixes: path traversal, filename injection, input validation, error leakage#204Copilot wants to merge 25 commits intodevelopmentfrom
Copilot wants to merge 25 commits intodevelopmentfrom
Conversation
Prisma bricked itself (again)
Resolves #200 (I hope this works)
…alidation, error leakage Co-authored-by: SvenFinn <[email protected]>
Copilot
AI
changed the title
[WIP] Review project for feedback and improvements
Security fixes: path traversal, filename injection, input validation, error leakage
Mar 19, 2026
SvenFinn
reviewed
Mar 27, 2026
Comment on lines
-10
to
+31
| const basePath = `/app/files`; | ||
| const basePath = nodePath.resolve(`/app/files`); | ||
|
|
||
| /** | ||
| * Resolves a user-supplied path relative to basePath and verifies it stays | ||
| * within basePath. Returns null if the resolved path would escape basePath. | ||
| */ | ||
| function resolveSafePath(userInput: string): string | null { | ||
| const resolved = nodePath.resolve(basePath, userInput); | ||
| if (resolved !== basePath && !resolved.startsWith(basePath + nodePath.sep)) { | ||
| return null; | ||
| } | ||
| return resolved; | ||
| } | ||
|
|
||
| /** | ||
| * Sanitizes a filename by removing path separators, null bytes, and other | ||
| * characters that could be used for path traversal or injection attacks. | ||
| */ | ||
| function sanitizeFileName(name: string): string { | ||
| return nodePath.basename(name).replace(/[\0]/g, '_'); | ||
| } |
Owner
There was a problem hiding this comment.
This sanitization should propably be applied to screens/evaluations also, and be separated into its own lib, maybe also containing the response types for these routes
Owner
There was a problem hiding this comment.
Ooh, also, do there exist any libs that do this already? So I don't need to maintain it myself?
| import { isStartList } from 'dc-ranges-types'; | ||
|
|
||
| const app: Express = express(); | ||
| app.use(express.json()); |
Owner
There was a problem hiding this comment.
Why is this here?
What does it do?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several security and correctness issues found across the API servers during project review.
screens/images— Path Traversal & Filename Injectionpath.includes("..")guards withresolveSafePath()usingpath.resolve()+ prefix check againstbasePath. The old check is bypassable via encoded sequences, symlinks, or null bytes.sanitizeFileName()usingpath.basename()+ null-byte stripping on uploaded filenames. A filename like../../etc/cron.d/evilwould previously write outside the upload root.screens/screenManager— Input Validation & Error LeakagePUT /api/screens/:screenIdnow validatesreq.bodywithisDbScreen()before spreading into the Prisma upsert — consistent with howPOST /api/screensalready handles this./api/screens/resolvewas sending`Internal server error: ${error}`to clients. Now logs server-side and returns a generic message.res.end()calls afterres.send()in/nextand/previoushandlers.ranges/merge— Body Parsing & Crash on Malformed Inputexpress.json()middleware. The server had no body parser, soparseInt(req.body)inPOST /api/ranges/known/:rangeMacalways returnedNaN— the endpoint was effectively broken.parseInt(req.body)→parseInt(req.body?.rangeId).JSON.parse(handshakeRanges)in try-catch; malformed JSON in the WebSocket handshake query previously threw an uncaught exception.Original prompt
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.