Fix path traversal attack in -proto-out-dir - #573
Merged
Conversation
A malicious file descriptor name (e.g. from an untrusted protoset or server reflection) could escape the output directory through ../ sequences, writing attacker-controlled content to arbitrary paths. Confine all writes to an `os.Root` opened on the output directory.
dragonsinth
approved these changes
Jul 27, 2026
dragonsinth
left a comment
Member
There was a problem hiding this comment.
LGTM after a few changes; I wanted to actually traverse the live-code root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A malicious file descriptor name (e.g. from an untrusted protoset or server reflection) could escape the output directory through
../sequences, writing attacker-controlled content to arbitrary paths.Confine all writes to an
os.Rootopened on the output directory.Note
Low Risk
Security-hardening change with targeted tests; behavior for legitimate relative proto paths should be unchanged while blocking traversal.
Overview
Fixes a path traversal vulnerability when exporting protos via
-proto-out-dir: descriptor names from untrusted protosets or server reflection could use../and write outside the chosen output directory.Proto export now opens an
os.Rooton the output directory and performs allMkdirAll/Createoperations through it, so malicious names like../escape.protoor nestedfoo/../../../escape.protoare rejected instead of escaping the sandbox. The write loop is factored intowriteProtoFiles, and directory creation uses0755instead of0777.Tests cover a normal nested path (
foo/bar.proto) and assert traversal attempts fail and do not create files outside the temp output dir.Reviewed by Cursor Bugbot for commit c4fbb35. Bugbot is set up for automated code reviews on this repo. Configure here.