已关闭
security: fix path traversal in GetFile and PostFiles APIs #196
gcw_Nt0RibX4创建于 17 天前关闭于 13 天前
security: fix path traversal in GetFile and PostFiles APIs #196
已关闭
gcw_Nt0RibX4创建于 17 天前关闭于 13 天前
gcw_Nt0RibX4
17 天前

当前PR是否有AI参与:

[x] 否

[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

参考:openEuler社区《生成式AI工具使用与开源贡献政策》

PR功能描述 / 为什么需要这个合入**:

   GetFile gRPC接口直接使用用户提供的 filepath 参数读取文件,没有任何路径验证,攻击者可以通过路径遍历(如 ../../etc/passwd 或绝对路径 /etc/shadow )读取宿主机上的任意敏感文件。 修复 : 添加了路径清理和验证,只允许使用工作目录内的相对路径,禁止绝对路径和包含 .. 的路径遍历
   PostFiles gRPC接口直接使用用户提供的 filepath 参数写入文件,没有任何路径验证,攻击者可以通过路径遍历写入任意位置(如覆盖 /etc/crontab 、 /root/.ssh/authorized_keys 等关键系统文件,实现远程代码执行)。 修复 : 添加了同样的路径验证,只允许在工作目录内写入相对路径文件

该PR关联的issue

(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #

希望检视人员了解:

likedislike
当前Pull Request已关闭, 关闭人@gcw_Nt0RibX4
Ggcw_Nt0RibX4
17 天前 创建了 pull request,commit e78c10ad
atomgit-bot
atomgit-bot
17 天前 评论:

变更摘要

该 PR 修复 cmd/conch-agent/grpc.goAgentServerGetFilePostFiles 两个 gRPC 接口存在的路径遍历(Path Traversal)安全漏洞:此前接口直接使用用户提供的 filepath 参数读取/写入文件,攻击者可通过 ../ 或绝对路径访问工作目录之外的敏感文件。修复方式是在两个接口中统一加入路径校验,仅允许工作目录内的相对路径,禁止绝对路径及包含 .. 的路径。

主要改动

  • PostFiles 增加路径校验:新增 filepath.IsAbs(cleanedFilepath)strings.Contains(cleanedFilepath, "..") 检查,命中时记录错误日志并返回 invalid filepath 错误响应,阻止越界写入关键系统文件。
  • GetFile 清理并校验路径:读取前先通过 filepath.Clean(req.Filepath) 生成 cleanedFilepath,并应用与 PostFiles 相同的绝对路径与 .. 校验,不合法时返回错误而非读取文件。
  • 错误与日志统一改用清理后路径GetFile 中文件不存在、读取失败及成功日志等消息均改用 cleanedFilepath,避免日志暴露用户原始输入路径。
  • 新增 strings 标准库导入:为上述 strings.Contains 校验提供依赖。

变更摘要

该 PR 修复 cmd/conch-agent/grpc.goAgentServerGetFilePostFiles 两个 gRPC 接口存在的路径遍历(Path Traversal)安全漏洞:此前接口直接使用用户提供的 filepath 参数读取/写入文件,攻击者可通过 ../ 或绝对路径访问工作目录之外的敏感文件。修复方式是在两个接口中统一加入路径校验,仅允许工作目录内的相对路径,禁止绝对路径及包含 .. 的路径。

主要改动

  • PostFiles 增加路径校验:新增 filepath.IsAbs(cleanedFilepath)strings.Contains(cleanedFilepath, "..") 检查,命中时记录错误日志并返回 invalid filepath 错误响应,阻止越界写入关键系统文件。
  • GetFile 清理并校验路径:读取前先通过 filepath.Clean(req.Filepath) 生成 cleanedFilepath,并应用与 PostFiles 相同的绝对路径与 .. 校验,不合法时返回错误而非读取文件。
  • 错误与日志统一改用清理后路径GetFile 中文件不存在、读取失败及成功日志等消息均改用 cleanedFilepath,避免日志暴露用户原始输入路径。
  • 新增 strings 标准库导入:为上述 strings.Contains 校验提供依赖。
likedislike
不准确?
atomgit-bot
atomgit-bot
17 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
openeuler-ci-botopeneuler-ci-bot成员
17 天前 将weibaohui,yangzhao_kl,jimmieme,duguhaotian,wonleing,zmr_2020,gaodaweiky,lu-wei-army,zhaoyifan28设为审查人
openeuler-ci-botopeneuler-ci-bot成员
17 天前 添加了label:sig/sig-CloudNative
openeuler-ci-bot
openeuler-ci-bot成员
17 天前 评论:

Welcome To openEuler Community

Hey @gcw_Nt0RibX4 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @Yekelu .

likedislike
openeuler-ci-botopeneuler-ci-bot成员
17 天前 添加了label:openeuler-cla/yes
openeuler-ci-bot
openeuler-ci-bot成员
17 天前 评论:

CLA Signature Pass

gcw_Nt0RibX4, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
gcw_Nt0RibX4
17 天前 评论:
likedislike
hu-zhangying
hu-zhangying
16 天前 评论:

Conch当前开发分支是dev分支,master分支较落后,可以审视dev分支是否存在以上问题。

likedislike
Ggcw_Nt0RibX4
13 天前 关闭了 pull request