Skip to content

Potential fix for code scanning alert no. 2391: Arbitrary file write extracting an archive containing symbolic links - #6252

Draft
eriknordmark wants to merge 1 commit into
masterfrom
alert-autofix-2391
Draft

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
masterfrom
alert-autofix-2391

Conversation

@eriknordmark

Copy link
Copy Markdown
Contributor

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 path for OS filesystem paths; use path/filepath.

Best fix here (without changing intended behavior): in evetest/utils/tar.go, replace the simple pathBuilder with a secure resolver that:

  1. Builds candidate path with filepath.Join.
  2. Resolves the parent directory with filepath.EvalSymlinks (or destination for root parent).
  3. Reconstructs final path from resolved parent + base name.
  4. Verifies the final path is inside canonical destination via filepath.Rel and .. check.
  5. For symlink targets, resolve relative to the symlink’s parent directory and enforce the same containment.

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.

…extracting an archive containing symbolic links

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread evetest/utils/tar.go
return fmt.Errorf("ExtractFromTar: MkdirAll(destination) failed: %w", err)
}
realDestination, err := filepath.EvalSymlinks(cleanDestination)
if err != nil {
@christoph-zededa

Copy link
Copy Markdown
Contributor

What about using https://pkg.go.dev/os#OpenRoot then you don't need these validation lambdas, do you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants