Replace securejoin.SecureJoin with handle-based pathrs APIs to eliminate TOCTOU#10
Draft
Replace securejoin.SecureJoin with handle-based pathrs APIs to eliminate TOCTOU#10
Conversation
…d securejoin.SecureJoin for file paths Co-authored-by: sanderhahn <775103+sanderhahn@users.noreply.github.com>
Co-authored-by: sanderhahn <775103+sanderhahn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor to use cyphar/filepath-securejoin for TOCTOU safety
Replace TOCTOU-vulnerable os.MkdirAll with pathrs.MkdirAll from filepath-securejoin
Feb 13, 2026
…lHandle for TOCTOU safety Co-authored-by: sanderhahn <775103+sanderhahn@users.noreply.github.com>
Co-authored-by: sanderhahn <775103+sanderhahn@users.noreply.github.com>
Copilot
AI
changed the title
Replace TOCTOU-vulnerable os.MkdirAll with pathrs.MkdirAll from filepath-securejoin
Replace securejoin.SecureJoin with handle-based pathrs APIs to eliminate TOCTOU
Feb 13, 2026
sanderhahn
reviewed
Feb 13, 2026
gozip.go
Outdated
| } | ||
| defer dirHandle.Close() | ||
|
|
||
| filePath := fmt.Sprintf("/proc/self/fd/%d/%s", dirHandle.Fd(), baseName) |
Owner
There was a problem hiding this comment.
This is Linux specific. Can you ensure that the code runs on all systems?
Author
There was a problem hiding this comment.
Split the implementation into platform-specific files in c3e887e:
unzip_linux.go(//go:build linux): uses TOCTOU-safe pathrs APIs (MkdirAllHandle, OpenatInRoot, Reopen)unzip_other.go(//go:build !linux): falls back tosecurejoin.SecureJoinfor macOS/Windows/othersgozip.go: sharedwriteExtractedFilehelper
Verified cross-compilation succeeds for GOOS=darwin and GOOS=windows.
- unzip_linux.go: TOCTOU-safe pathrs APIs (MkdirAllHandle, OpenatInRoot, Reopen) - unzip_other.go: securejoin.SecureJoin fallback for macOS/Windows/others - gozip.go: shared writeExtractedFile helper Co-authored-by: sanderhahn <775103+sanderhahn@users.noreply.github.com>
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.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.