Repository navigation
fix: 凭据密钥外置、构建下载校验与文件 key 隔离加固 - #3
Merged
Merged
Conversation
…oads Keep non-streaming keepalive off unless it is explicitly enabled, so slow 429 and authentication failures still return their real status. Allow Linux AES-GCM credential encryption only with an external key, scope file list and metadata to the current API key, and verify published SHA256 values before extracting build dependencies. Co-authored-by: xueyiwei868-ux <xueyiwei868-ux@users.noreply.github.com>
…se-f57f fix: preserve HTTP errors, externalize credential keys, and pin downloads
安全审查修复,四处改动: 1. FileMetadata 把受限 key 的范围判断挪到刷新之前。原先先刷新再判范围, 越权探测会触发属主账户刷新,且资源不存在时刷新错误按原样返回, 错误类型可以区分"存在但不归你"与"不存在"。现在越权与不存在的 资源都在刷新之前返回 ErrResourceNotFound,刷新后再核对一次归属, 资源中途改绑到范围外账户同样返回不存在。 2. selectionIndicesLocked 在资源属主不在当前 key 范围时,先于 账户不匹配的错误返回 ErrResourceNotFound。原先 ResourceID 与 AccountID 不匹配时错误消息带出属主账户 ID,绕过文件隔离的 防枚举目标。 3. 凭据密钥文件的工作目录检查在 cwd 为文件系统根(systemd 默认 /) 时跳过。原先任何绝对路径都被判定位于工作目录内,CREDENTIALS_KEY_FILE 在裸机部署下全部被拒。 4. apiKeyAccounts 在 API_KEY_ACCOUNTS 未覆盖全部已配置 key 时打 slog 警告。未列出的 key 不受账户范围约束,可访问全部账户与文件, 漏配时提示操作员,不回显 key 内容。 已知残留:AcquireFor 在判范围前仍会刷新属主账户,存在时延侧信道; 文件 ID 为高熵 Drive ID,枚举不可行,按最小改动原则不再重构。 回归测试以修复前代码验证失败:TestFileMetadataScopeSkipsRefresh、 TestSelectionResourceScopeHidesOwner。
fix: 收紧文件 key 隔离的侧信道与属主泄漏
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.
来自 fork 的三部分加固,可直接合并或按块拆分。
1. 凭据加密与构建下载(55ff03d)
ENCRYPT_CREDENTIALS扩展到 Linux/Docker:AES-256-GCM,密钥只接受进程环境变量CREDENTIALS_KEY(hex/Base64,32 字节)或数据目录外的CREDENTIALS_KEY_FILE(0600、普通文件、拒绝符号链接),二选一,缺失即拒绝启动,不自动生成、不回显、不写回.envruntime/自动生成密钥的逻辑(密钥和密文同目录,加密形同虚设)NONSTREAM_KEEPALIVE默认改 false:开启后 10 秒即提交 200,429 与认证失败会被盖掉build/fetch-verified.sh对照build/dependency-checksums.txt校验 SHA256 后再解压2. 文件 API 的 key 隔离(同上提交)
ListFiles/FileMetadata/AcquireFor遵守API_KEY_ACCOUNTS绑定,跨 key 访问与不存在文件同样返回 404。3. 安全审查修复(a02ba91)
对上述隔离的严格审查发现并修复四个问题:
selectionIndicesLocked在资源属主不在当前 key 范围时,先于"账户不匹配"错误返回ErrResourceNotFound,原先该错误把属主账户 ID 带进响应/)时跳过密钥文件的工作目录检查,否则所有绝对路径的CREDENTIALS_KEY_FILE被误拒API_KEY_ACCOUNTS未覆盖全部已配置 key 时slog警告(不回显 key 内容),未列出的 key 可访问全部账户与文件验证
go build/go vet/gofmt全通过;本地以 SHA256 校验后的静态库运行go test ./internal/aistudio/... ./internal/config/... ./internal/securefile/...全绿TestFileMetadataScopeSkipsRefresh(刷新错误泄漏)、TestSelectionResourceScopeHidesOwner(属主泄漏)已知残留
AcquireFor判范围前仍会刷新属主账户,存在时延侧信道;文件 ID 为高熵 Drive ID,枚举不可行,按最小改动原则未重构。Created with Perplexity