security: fix path-injection, SSRF & rate-limiting in namespace-notes (PIN-26)#78
Open
jhamon wants to merge 1 commit into
Open
security: fix path-injection, SSRF & rate-limiting in namespace-notes (PIN-26)#78jhamon wants to merge 1 commit into
jhamon wants to merge 1 commit into
Conversation
…space-notes Addresses 13 CodeQL code-scanning alerts (PIN-26): - js/path-injection (10): add pathSafety helper (sanitizeSegment + safeJoin) that validates each user-supplied path segment and confirms the resolved path stays within the uploads base dir. Applied across serverStorage.ts (saveFile, getFilePath, deleteWorkspaceFiles, deleteFileFromWorkspace, listFilesInNamespace) and documentController.serveDocument. - js/request-forgery (2): validate + URL-encode namespaceId/documentId before interpolating them into outbound fetch URLs in client files/route.ts. - js/missing-rate-limiting (1): add express-rate-limit to the filesystem routes in documentRoutes.ts. Server and client both typecheck clean; path-traversal vectors verified blocked. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Resolves the 13 CodeQL code-scanning alerts in
namespace-notes(PIN-26, child of PIN-16 / PIN-6 security fast-track).js/path-injectionpathSafetyhelper validates each user-supplied path segment and confirms the resolved path stays inside theuploadsbase dirjs/request-forgery(SSRF)encodeURIComponentnamespaceId/documentIdbefore building outbound fetch URLsjs/missing-rate-limitingexpress-rate-limiton the filesystem routesDetails
Path injection — added
server/src/utils/storage/pathSafety.ts:sanitizeSegment()rejects empty values, path separators (/,\),./.., and null bytes.safeJoin()validates every segment and then asserts the fully-resolved path is contained within the trusted base directory (the authoritative traversal guard).serverStorage.ts(saveFile,getFilePath,deleteWorkspaceFiles,deleteFileFromWorkspace,listFilesInNamespace) anddocumentController.serveDocument.SSRF —
client/src/app/api/files/route.ts: user ids are validated against^[A-Za-z0-9_-]+$and URL-encoded before interpolation, so they cannot alter the request path/host.Rate limiting —
documentRoutes.ts: a 60 req/min/IP limiter guards all routes that touch local storage.Verification
npx tsc(server) — exit 0.npx tsc --noEmit(client) — exit 0...,ns/../..,..\..\x, empty,.) verified rejected; legit dotted filenames (report.final.pdf) pass.🤖 Generated with Claude Code