(absolutePath: string)
| 418 | |
| 419 | // Check if file is within the scratchpad directory |
| 420 | function 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. |
no test coverage detected