Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggest os.Root to avoid directory/symlink traversal #1297

Open
spencerschrock opened this issue Feb 3, 2025 · 0 comments
Open

suggest os.Root to avoid directory/symlink traversal #1297

spencerschrock opened this issue Feb 3, 2025 · 0 comments

Comments

@spencerschrock
Copy link

spencerschrock commented Feb 3, 2025

os.Root is an upcoming type in Go 1.24 aimed at solving directory traversal. (upstream proposal). Note: some methods won't be released until Go 1.25.

Root may be used to only access files within a single directory tree.

Methods on Root can only access files and directories beneath a root directory. If any component of a file name passed to a method of Root references a location outside the root, the method returns an error.

It would be nice for gosec to suggest using os.Root and its methods over the direct os equivalents (e.g. os.Root.Open over os.Open) when appropriate:

This could also be considered when evaluating / remediating G305: File traversal when extracting zip/tar archive

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

No branches or pull requests

2 participants