Skip to content

fix: prevent path traversal in fileReader function#408

Open
Aakarshit123 wants to merge 1 commit into
google:masterfrom
Aakarshit123:fix-path-traversal
Open

fix: prevent path traversal in fileReader function#408
Aakarshit123 wants to merge 1 commit into
google:masterfrom
Aakarshit123:fix-path-traversal

Conversation

@Aakarshit123

Copy link
Copy Markdown

Summary

This PR fixes a path traversal vulnerability in the fileReader function of gnoi/os/client.go.

The Vulnerability

The fileReader function previously passed the path parameter directly to os.Open() without any sanitization. A caller could pass ../../../../etc/passwd to read arbitrary files from the filesystem.

The Fix

  • Added filepath.Clean to canonicalize the path
  • Added validation to reject paths containing .. (directory traversal)
  • Added validation to reject absolute paths (e.g., /etc/passwd)

Testing

Tested locally:

  • ../../../../etc/hosts → blocked with error
  • /etc/hosts → blocked (absolute path)
  • testfile.txt → allowed (relative path)

Impact

This fix prevents arbitrary file read vulnerabilities without breaking existing functionality.

Related

  • Reported via Google OSS VRP (Issue #538939238)
  • CWE-22: Path Traversal

/cc @google/gnxi-maintainers

@google-cla

google-cla Bot commented Jul 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Aakarshit123

Copy link
Copy Markdown
Author

/easycla

@Aakarshit123

Copy link
Copy Markdown
Author

I have signed the CLA. Please re-run the check.

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.

1 participant