evetest: Potential fix for code scanning alert no. 2391: Arbitrary file write extracting an archive containing symbolic links - #6252
eriknordmark wants to merge 1 commit into
Conversation
…extracting an archive containing symbolic links Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
What about using https://pkg.go.dev/os#OpenRoot then you don't need these validation lambdas, do you? |
|
Rewriting it that way is a clear improvement over the autofix. This being a Copilot autofix branch in the upstream repo, it needs a hand-written replacement rather than an amendment — I will open one. |
Potential fix for https://github.com/lf-edge/eve/security/code-scanning/2391
To fix this safely, validate every extracted output path (and symlink target path) against the destination directory using canonical, symlink-aware resolution before creating files/dirs/symlinks. Also avoid using
pathfor OS filesystem paths; usepath/filepath.Best fix here (without changing intended behavior): in
evetest/utils/tar.go, replace the simplepathBuilderwith a secure resolver that:filepath.Join.filepath.EvalSymlinks(or destination for root parent).filepath.Reland..check.Then use this resolver in all three branches (
TypeDir,TypeReg,TypeLink/TypeSymlink) and create symlink with validated link target and validated link path.Suggested fixes powered by Copilot Autofix. Review carefully before merging.