Repository navigation
fix(examples): write triangle-headless PNG through os.Root - #363
Merged
Merged
Conversation
The latest golangci-lint (gosec G703, path traversal via taint analysis) flags os.WriteFile on the path taken from os.Args. filepath.Clean is not a sanitizer for it: Clean resolves ".." instead of rejecting it. The Lint job therefore fails on main and on every pull request. Open an os.Root on the target directory and write the base name inside it, as gosec recommends. The PNG lands in the same place as before, but the write cannot leave that directory through ".." or a symlink. The error from closing the root is returned too, not dropped in a defer.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Oct 18, 2026
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.
The Lint job fails on
mainand on every open PR. CI runsgolangci-lintwithversion: latest, and the current release's gosec reports G703 (path traversal via taint analysis) forexamples/triangle-headless/main.go:318. The example passes the path fromos.Argstoos.WriteFile. gosec deliberately does not treat thefilepath.Cleanalready on that path as a sanitizer: Clean resolves..instead of rejecting it.The example now opens an
os.Rooton the target directory and writes the base name inside it, as gosec recommends. The PNG goes to the same place as before. I checked relative, nested, absolute and./paths, plus a missing directory, against the oldos.WriteFile: the files land in the same places and a missing directory still fails. The write just can't leave that directory through..or a symlink. The error from closing the root is returned instead of being dropped in adefer. No//nolint.Verified on a clean checkout:
go mod tidyclean; builds for windows, linux/amd64 and darwin/arm64;go test ./...passes;go vetexactly as CI runs it (linux, withouthal/vulkan/vkandhal/gles) is clean.Once this is in, the open PRs pass Lint after a rebase.