writeFile: missing O_EXCL allows symlink injection and concurrent-run collision on temp file #35
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
mod-nag
mod-nag
mod-nag
mod-nag/ignore
mod-nag/ignore
mod-nag/ignore
nagonag
nagonag/ignore
question
security
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
heiko/cert-proxy#35
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?
Summary
cmd/cert-proxy-client/cert/cert.go:332creates the infixed temp file withoutO_EXCL:The infixed filename (
privkey-1747123456.pem) is derived fromtime.Now().Unix()(second granularity), making it predictable within a small window.Two consequences
1. Symlink injection. A local attacker with write access to the certbase can pre-plant a symlink at the predictable infixed path.
O_TRUNCfollows the symlink; the private key is written to wherever the symlink points.2. Concurrent-run collision. If two
cert-proxy-clientinstances run within the same calendar second (e.g. a timer fires while a previous run is still in progress), they compute the same infix. EachO_TRUNCcall clobbers the other's in-progress write, potentially producing a truncated key or cert file that the final symlink then points to.Fix
Add
O_EXCLwhen creating the temp file. This fails fast if the file already exists (including as a symlink) and forces the concurrent case to surface as an error rather than silent corruption:For the collision case, consider using
os.CreateTempor adding sub-second resolution (nanoseconds) to the infix.AI attribution comment added per repository instruction for this open issue.\n\n(co)authored by ai:gpt-5-codex