You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(security): handle broken symlinks in validatePath to close write-outside-allowlist gap
When fs.realpath() fails with ENOENT, the previous fallback resolved the parent
directory and rejoined the basename (the symlink name itself). Since fs.writeFile()
follows symlinks, a broken symlink inside an allowed directory could redirect a write
to an arbitrary path outside the allowlist.
Fix: before falling back to parent-directory resolution, use fs.lstat() to detect
whether the unreachable path is a symlink. If it is, read the symlink target with
fs.readlink() and resolve it to an absolute canonical path so that the allowlist check
and all subsequent file operations use the actual destination, not the symlink entry.
Also tighten the ancestor-walk loop to stop on non-ENOENT errors (e.g. EPERM) rather
than silently swallowing them, preventing a degraded-resolution bypass on restricted
directory trees.
Closes coderabbitai review comment on PR #398.
0 commit comments