feat: support opening local files - #10
Conversation
sleepinginsummer
left a comment
There was a problem hiding this comment.
建议合并前处理以下两个问题:
- [P1] 本地文件能力缺少 API 访问保护
src/server.rs 当前使用 CorsLayer::permissive(),而 /open 接受调用方提供的绝对路径和 cwd。当扩展开启 file URL 权限后,任意网页都可以请求 localhost API,探测本地文件是否存在、打开文件,并结合现有 /exec 接口读取页面内容。仅绑定 127.0.0.1 不能阻止浏览器跨域请求。建议在本 PR 中为 API 增加随机 token,并校验 Origin,再开放本地文件能力。
- [P1] 多浏览器场景可能关联到错误标签页
normalize_open_result 通过 find_session_key_by_tab_id 在全部 session 中仅按 tab_id 查找。Chrome 的 tab_id 只在单个浏览器实例内唯一;多个浏览器出现相同 ID 时可能命中错误 session,造成 readiness 误判和默认 session 切换错误。建议优先从 executor_session_key 提取 browser_id/profile_id,用完整 session key 定位,并补充两个浏览器具有相同 tab_id 的测试。
本地验证:cargo test --all-targets --all-features 的 17 个测试均通过。
|
已按建议完成两项修改:
|
sleepinginsummer
left a comment
There was a problem hiding this comment.
复查最新提交 a10f798 后,之前的 API 鉴权和多浏览器 tab_id 问题已经修复,测试也已补充。还有两个问题建议合并前处理:
- [P1] WebSocket 入口仍可被网页伪装成扩展
HTTP API 已增加 token 和 Origin 校验,但扩展使用的 WebSocket 服务仍未校验 Origin 或身份。普通网页可以直接连接 localhost WebSocket,发送 ext_ready 注册伪造 session,并接收后续 CLI 指令;本 PR 打开本地文件时还会把规范化后的本地路径发送到该连接。建议 WebSocket 握手同样校验扩展来源,或使用独立认证 token,并增加拒绝非扩展 Origin/无 token 连接的测试。
- [P2] old CLI -> new daemon 兼容性被破坏
新中间件要求所有 API 请求携带 x-agent-browser-token,旧版 CLI 不会发送该请求头,因此调用新版 daemon 会统一返回 401。这与 PR 描述中的 old CLI -> new daemon 兼容性不一致。安全修复应保留,但需要明确取消该兼容承诺并更新文档/版本策略,或者提供受控的升级兼容方案。
本地验证:cargo test --all-targets --all-features 23 个测试通过,cargo clippy --all-targets --all-features 通过。
|
已继续处理复查意见:
|
sleepinginsummer
left a comment
There was a problem hiding this comment.
最新提交已解决 API 鉴权、WebSocket Origin 校验和多浏览器 session 关联问题;跨平台 CI 全部通过。
Summary
opensupport for local filesystem paths and absolutefile://URLsstatus/doctorBehavior
opennow accepts:http://andhttps://URLsfile://URLs./,../, and~/pathsLocal paths are resolved from the invoking CLI's working directory, canonicalized through symlinks, checked to be regular files, and converted to correctly encoded file URLs. Directories, missing files, foreign-platform paths, unsupported schemes, stale extensions, and disabled file-URL access return stable
error_codevalues.The extension is bumped to 2.1. File tabs are included only when Chrome's “Allow access to file URLs” permission is enabled. Active opens become the daemon's default session; background opens do not.
Compatibility
targetand the legacyurlfieldx-agent-browser-tokenauthentication~/.agent-browser-cli/api-tokenand send it in thex-agent-browser-tokenheaderVerification
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-targets --all-features— 25 tests passedcargo build --releaseopenscansnapshotclickexec