security: make one-time downloads atomic under concurrency (ai:gpt-5) #49
Labels
No labels
nagonag
nagonag/ignore
bug
doc
duplicate
enhancement
help wanted
invalid
question
security
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
IUS/once#49
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Finding from a whole-codebase security review.
Affected code:
content, then removes it.contentand updates metadata after the caller already has an open reader.Impact:
Two concurrent POST requests for the same download key can both open the content file before either request removes it. Both requests then keep valid file handles and can receive the secret, violating the documented exactly-once guarantee.
Suggested fix:
contentto a per-download in-progress path withos.Rename, or by using an advisory lock/claim file in the UUID directory.Fixed by commit
4e53e38(fix: make one-time downloads atomic).Implements atomic claiming via File.Claim() method which uses atomic os.Rename():
content→content.downloadatomicallyPrevent TOCTOU vulnerabilities and concurrent downloads of the same file. Verified with test coverage (TestClaimAllowsOnlyOneDownloader).