MCPcopy Create free account
hub / github.com/Noumena-Network/code / isScratchpadPath

Function isScratchpadPath

src/utils/permissions/filesystem.ts:420–434  ·  view source on GitHub ↗
(absolutePath: string)

Source from the content-addressed store, hash-verified

418
419// Check if file is within the scratchpad directory
420function isScratchpadPath(absolutePath: string): boolean {
421 if (!isScratchpadEnabled()) {
422 return false
423 }
424 const scratchpadDir = getScratchpadDir()
425 // SECURITY: Normalize the path to resolve .. segments before checking
426 // This prevents path traversal bypasses like:
427 // echo "malicious" > /tmp/ncode-0/proj/session/scratchpad/../../../etc/passwd
428 // Without normalization, the path would pass the startsWith check but write to /etc/passwd
429 const normalizedPath = normalize(absolutePath)
430 return (
431 normalizedPath === scratchpadDir ||
432 normalizedPath.startsWith(scratchpadDir + sep)
433 )
434}
435
436/**
437 * Check if a file path is dangerous to auto-edit without explicit permission.

Callers 2

Calls 3

isScratchpadEnabledFunction · 0.85
getScratchpadDirFunction · 0.85
normalizeFunction · 0.50

Tested by

no test coverage detected