Skip to content

fix(files): let the operator open symlinked folders outside the project - #1018

Merged
agegr merged 4 commits into
mainfrom
claude/issue-748-symlinked-dirs
Sep 30, 2026
Merged

agegr merged 4 commits into
mainfrom
claude/issue-748-symlinked-dirs

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Fixes #748

Problem

A project folder that gathers other folders through symbolic links shows each link as a folder, but expanding one shows nothing. /api/files authorizes the resolved path, so everything beneath a link whose target is outside the project is refused with 403, and the file explorer ignored that error. Links that stay inside the project already worked.

While testing this I found that GET /api/files could read a file next to a link's target, outside the project, through a .. carried in an encoded slash (link%2F..%2Fx): authorization collapses .. before resolving links, the filesystem after.

Changes

  • The directory listing reports where a link leads when that is outside the allowed roots (outsideLinkTarget). The explorer marks such folders and, when expanded, shows the target with an Allow browsing button instead of an empty folder.
  • POST /api/files/<link>?type=allow-link with { target } allows that target until the server restarts. This is the same access /api/cwd/validate gives any directory you select. It requires the link to sit inside the project after resolving links, the target to still be the one that was shown (409 otherwise), and a JSON content type.
  • The security boundary is unchanged: a symlink in a repository never makes files outside the project readable without an explicit click.
  • Any other folder that fails to load now shows the error instead of opening blank.
  • GET /api/files refuses decoded .. segments (separate commit, so it can be taken on its own).
  • AGENTS.md documents both rules.

Possible follow-ups if wanted: remember approvals across restarts, or an "allow all links in this folder" action.

Testing

  • New unit, route and render tests: outside, inside, nested, dangling and file links; .. traversal (returns 200 without the check, 403 with it); a link repointed after it was listed (409); the content-type check; the rendered notice and error.
  • tsc --noEmit and eslint clean.
  • Manually checked with a folder of symlinks in next dev: outside links show the icon, Allow lists the folder and files open, inside links open directly, a repointed link asks to refresh.

🤖 Generated with Claude Code

agegr and others added 4 commits September 30, 2026 21:36
…ct (#748)

A project that gathers other folders through symbolic links listed each
link as a folder, but expanding one opened onto nothing. /api/files
authorizes the resolved path (isExistingPathWithinRoots), so everything
beneath a link whose target is outside the allowed roots is refused with
403, and the explorer swallowed that error. Links that stay inside the
project already worked.

The boundary stays as it is: a symlink committed to a cloned repository
must not make ~/.ssh or / readable through the web UI on its own. The
listing now reports where such a link leads (outsideLinkTarget), and the
explorer shows that target with an "Allow browsing" button instead of an
empty folder. The click posts ?type=allow-link, which adds the target to
the in-memory allowed roots until the server restarts - the same grant
/api/cwd/validate already gives any directory the operator selects. The
request carries the target the operator was shown and is refused if the
link now points elsewhere, the link must sit in a directory that is
inside the roots after resolving links, and like other root-widening
writes it requires a JSON content type. Any other folder load failure is
now shown under the folder instead of being ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GET /api/files authorizes a path lexically and then through realpath,
and both collapse `..` before resolving links. The filesystem does it
the other way round: root/link/../x is looked up beside the link's
target. A `..` cannot arrive as its own URL segment, but an encoded
slash inside one (`link%2F..%2Fx`) reaches the catch-all intact, so
with a link to /elsewhere/project in an allowed root and any hub/x
present, the route served /elsewhere/x.

The explorer never builds such paths (encodeFilePathForApi splits on
"/", and URL parsing removes the literal segments), so the route now
refuses any decoded `..` segment outright.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…argets (#748)

The `..` refusal only guarded GET /api/files, but the gap is in
isExistingPathWithinRoots(): Node's realpathSync collapses `..` before it
follows links, so `/api/file-index?cwd=<project>/link/..` listed the folder
beside the link's target. Every route authorizing a cwd or file from a
query or body had the same exposure. The check now refuses `..` segments
itself; the route keeps its own check for session-referenced files, which
skip the existing-path check. A backslash splits only Windows paths, so a
POSIX file named `a\..\b` is no longer refused.

A link to `/`, `~` or a parent of the project now carries
`outsideLinkEncloses`; the explorer warns and asks before allowing it,
since a cloned repository can contain one. The English notice reads
"Links to {target}, outside this project".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit 687af27 into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/issue-748-symlinked-dirs branch October 1, 2026 13:28
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
6 处冲突没有一处需要二选一,两个功能都保留:

- app/api/files/[...path]/route.ts(1 处)
  并用一个 type 变量分派:allow-link 交给上游的 allowLinkedDirectory,
  其余交给我们的 handleFileMutation;上游的 const type 提到 try 顶部,
  我们的 mutationType 变量随之去掉
- components/FileExplorer.tsx(5 处)
  1) 模块级:我们的 ContextMenuTarget/RenameState/CreateState + mutateFileEntry
     与上游的 responseError 并列
  2) 上游的 OutsideLinkIcon + 我们的 CreateEntryInput,TreeNode 保持 export
     (上游测试直接 import 它)
  3) 列表行状态:我们的 isRenaming/isCreatingHere 与上游的
     allowedLinkTarget/allowingLink/pendingLinkTarget 并列
  4) 名称区:我们的重命名输入框与上游的"链接指向外部"图标并存
  5) "空目录"占位:两个排除条件合并为
     !loadError && !(creating && creating.parentDir === node.fullPath)

集成修复(不是冲突,是上游测试暴露的真问题):我们的 agegr#899 给 TreeNode
加了 renaming/creating 两个必填 prop,而上游的
FileExplorer.linked-directory.test.mjs 直接渲染 TreeNode 且不传它们,
于是 creating !== null && creating.parentDir 抛 TypeError。改为
creating?.parentDir 并把两个 prop 标为可选——TreeNode 本来就应该能在
"没有重命名/没有新建"时渲染。

验证:tsc/lint 通过;app/api/files/*.test.mjs + FileExplorer*.test.mjs +
linked-directory + file-access + path-security 共 32 个测试全过(含上游新增
的 11 个链接目录测试);全量 npm test 仅剩 AGENTS.md 记录的 6 个已知失败;
e2e 14 项全绿。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…式中改思考等级)

解决 agegr#1018 之后这两个提交 0 冲突。

- agegr#1021 技能/插件分组标题本身就是开关
- agegr#1022 一次运行流式输出过程中即可修改思考等级(agegr#851)
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…ct (agegr#1018)

* fix(files): let the operator open symlinked folders outside the project (agegr#748)

A project that gathers other folders through symbolic links listed each
link as a folder, but expanding one opened onto nothing. /api/files
authorizes the resolved path (isExistingPathWithinRoots), so everything
beneath a link whose target is outside the allowed roots is refused with
403, and the explorer swallowed that error. Links that stay inside the
project already worked.

The boundary stays as it is: a symlink committed to a cloned repository
must not make ~/.ssh or / readable through the web UI on its own. The
listing now reports where such a link leads (outsideLinkTarget), and the
explorer shows that target with an "Allow browsing" button instead of an
empty folder. The click posts ?type=allow-link, which adds the target to
the in-memory allowed roots until the server restarts - the same grant
/api/cwd/validate already gives any directory the operator selects. The
request carries the target the operator was shown and is refused if the
link now points elsewhere, the link must sit in a directory that is
inside the roots after resolving links, and like other root-widening
writes it requires a JSON content type. Any other folder load failure is
now shown under the folder instead of being ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(files): refuse `..` that climbs out through a symlink (agegr#748)

GET /api/files authorizes a path lexically and then through realpath,
and both collapse `..` before resolving links. The filesystem does it
the other way round: root/link/../x is looked up beside the link's
target. A `..` cannot arrive as its own URL segment, but an encoded
slash inside one (`link%2F..%2Fx`) reaches the catch-all intact, so
with a link to /elsewhere/project in an allowed root and any hub/x
present, the route served /elsewhere/x.

The explorer never builds such paths (encodeFilePathForApi splits on
"/", and URL parsing removes the literal segments), so the route now
refuses any decoded `..` segment outright.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(files): refuse `..` at the path boundary and confirm broad link targets (agegr#748)

The `..` refusal only guarded GET /api/files, but the gap is in
isExistingPathWithinRoots(): Node's realpathSync collapses `..` before it
follows links, so `/api/file-index?cwd=<project>/link/..` listed the folder
beside the link's target. Every route authorizing a cwd or file from a
query or body had the same exposure. The check now refuses `..` segments
itself; the route keeps its own check for session-referenced files, which
skip the existing-path check. A backslash splits only Windows paths, so a
POSIX file named `a\..\b` is no longer refused.

A link to `/`, `~` or a parent of the project now carries
`outsideLinkEncloses`; the explorer warns and asks before allowing it,
since a cloned repository can contain one. The English notice reads
"Links to {target}, outside this project".

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…ct (agegr#1018)

* fix(files): let the operator open symlinked folders outside the project (agegr#748)

A project that gathers other folders through symbolic links listed each
link as a folder, but expanding one opened onto nothing. /api/files
authorizes the resolved path (isExistingPathWithinRoots), so everything
beneath a link whose target is outside the allowed roots is refused with
403, and the explorer swallowed that error. Links that stay inside the
project already worked.

The boundary stays as it is: a symlink committed to a cloned repository
must not make ~/.ssh or / readable through the web UI on its own. The
listing now reports where such a link leads (outsideLinkTarget), and the
explorer shows that target with an "Allow browsing" button instead of an
empty folder. The click posts ?type=allow-link, which adds the target to
the in-memory allowed roots until the server restarts - the same grant
/api/cwd/validate already gives any directory the operator selects. The
request carries the target the operator was shown and is refused if the
link now points elsewhere, the link must sit in a directory that is
inside the roots after resolving links, and like other root-widening
writes it requires a JSON content type. Any other folder load failure is
now shown under the folder instead of being ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(files): refuse `..` that climbs out through a symlink (agegr#748)

GET /api/files authorizes a path lexically and then through realpath,
and both collapse `..` before resolving links. The filesystem does it
the other way round: root/link/../x is looked up beside the link's
target. A `..` cannot arrive as its own URL segment, but an encoded
slash inside one (`link%2F..%2Fx`) reaches the catch-all intact, so
with a link to /elsewhere/project in an allowed root and any hub/x
present, the route served /elsewhere/x.

The explorer never builds such paths (encodeFilePathForApi splits on
"/", and URL parsing removes the literal segments), so the route now
refuses any decoded `..` segment outright.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(files): refuse `..` at the path boundary and confirm broad link targets (agegr#748)

The `..` refusal only guarded GET /api/files, but the gap is in
isExistingPathWithinRoots(): Node's realpathSync collapses `..` before it
follows links, so `/api/file-index?cwd=<project>/link/..` listed the folder
beside the link's target. Every route authorizing a cwd or file from a
query or body had the same exposure. The check now refuses `..` segments
itself; the route keeps its own check for session-referenced files, which
skip the existing-path check. A backslash splits only Windows paths, so a
POSIX file named `a\..\b` is no longer refused.

A link to `/`, `~` or a parent of the project now carries
`outsideLinkEncloses`; the explorer warns and asks before allowing it,
since a cloned repository can contain one. The English notice reads
"Links to {target}, outside this project".

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: File browser fails to support symbolic links in project folders

1 participant