Repository navigation
Conversation
sponge225
force-pushed
the
fix/localfs-case-alias
branch
2 times, most recently
from
October 14, 2026 12:20
3f119ab to
bf1725c
Compare
sponge225
force-pushed
the
fix/localfs-case-alias
branch
from
October 14, 2026 12:24
bf1725c to
80ef6ca
Compare
This branch has not been deployed
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.
Description
在大小写不敏感的文件系统上,localfs 可能把大小写不同的路径解析到同一个磁盘对象。上层权限系统按原始 URI 判断权限,而底层文件系统按自身规则解析文件名,两层语义不一致时可能造成越权读写。
例如,目录中已经存在
a.md,用户没有访问该 URI 的权限,但可以提交另一个 URIA.md。在默认 macOS 文件系统上:A.md执行权限判断;A.md直接交给操作系统;a.md;a.md。本 PR 在 localfs 的统一路径解析入口中增加精确名称检查:当操作系统认为请求路径命中了已有对象时,逐级读取父目录中的真实目录项,要求每个已有路径组件与请求名称完全一致;如果只通过大小写别名命中,则返回
InvalidPath,不再继续执行读取、写入、删除或移动等操作。该检查依据实际文件系统行为生效。在大小写敏感的文件系统上,如果
A.md不存在,仍然允许创建独立的A.md,不会改变a.md与A.md可以同时存在的原有行为。写操作会先通过 PathLock 读取锁文件。为了避免 PathLock 将底层明确的
InvalidPath包装成普通 I/O 错误并返回500 INTERNAL,本 PR 仅在读取锁 token 的路径上保留该错误类型,并在 Python binding 中映射为AGFSInvalidPathError。因此别名读写现在都会返回400 INVALID_URI;其他锁 I/O、无效 token 和内部错误仍保持原有的500分类。Human Involvement
Related Issue
无关联 Issue。
Type of Change
Changes Made
LocalFileSystem::resolve_path()中统一执行已有路径组件的精确名称检查,使所有经过该入口的 localfs 操作获得一致保护。symlink_metadata()判断请求名称是否被文件系统解析到已有对象,再通过read_dir()与真实目录项做精确比较;避免自行模拟不同文件系统的大小写规则。NotFound和NotADirectory视为后续路径尚不存在,使新文件创建及 PathLock 内部探测路径保持原有行为。InvalidPath错误类型,仅在读取锁 token 遇到底层core::Error::InvalidPath时保留该语义;其他错误仍按原逻辑处理。ragfs-python中将 PathLock 的InvalidPath映射为AGFSInvalidPathError,复用现有 HTTP 错误映射并返回400 INVALID_URI。Testing
执行结果:
另外已通过:
使用当前分支重新构建并安装
ragfs-python,启动本地 OpenViking Server 后验证完整 HTTP 链路:a.md:返回200,内容正确。A.md:返回400 INVALID_URI。A.md:返回400 INVALID_URI,磁盘中的a.md内容没有变化。a.md:返回200,磁盘内容正常更新。Checklist
文档未修改:本 PR 不增加或变更公共 API、配置项和使用方式,只修正 localfs 对已有路径的解析行为及对应的错误分类。
Screenshots (if applicable)
不适用。
Additional Notes
本 PR 采用最小修复,不引入挂载级全局锁,因此不会改变 localfs 原有的并发模型。它修复的是可稳定复现的大小写别名访问;检查与实际系统调用之间原本存在的通用文件系统竞态不在本次改动范围内,也没有因本 PR 扩大。
PathLock 的错误分类调整仅覆盖本问题实际触发的“读取锁 token 时底层返回
InvalidPath”场景。CAS、扫描、删除等其他 PathLock 路径未扩展处理范围。目录权限兼容性:精确名称检查通常通过
read_dir(parent)获取磁盘上的真实目录项名称;在 POSIX 系统上,若父目录仅允许路径遍历但禁止目录枚举(例如权限为0111),localfs 不会直接跳过安全校验,而是通过平台能力获取实际名称(macOSgetattrlist、LinuxO_PATH+/proc/self/fd)。因此原本合法的精确路径读取保持可用,同时大小写别名仍会被拒绝;如果平台无法安全确认真实名称,则维持拒绝行为。