shared.Mkdir: os.Stat follows symlinks, allows redirect of cert file writes #36
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#36
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
internal/shared/mkdir.go:13usesos.Stat(symlink-following) in the EEXIST fallback:Between
os.Mkdirreturning EEXIST andos.Statrunning, a local attacker with write access to the certbase parent can replace the domain directory with a symlink pointing to an arbitrary directory.os.Statfollows the symlink, sees a directory, and returns nil. All subsequent cert and private key writes go to the attacker-controlled path.Fix
Use
os.Lstatinstead ofos.Statso the check applies to the directory entry itself, not its target:Or replace the whole function with
os.MkdirAll, which is race-safe for the common case.Confirmed.
internal/shared/mkdir.go:13doesos.Stat, which follows symlinks. An attacker with write access to the certbase parent can replace a domain directory with a symlink between theos.MkdirEEXIST return and theos.Statcall; cert and private key writes then go to the symlink target.Fix:
os.Lstat— one-liner, makes the stat apply to the entry itself rather than its target. If a symlink is sitting there,stat.IsDir()returns false and we bubble an error rather than silently writing through it.os.MkdirAllis an alternative but changes the semantics (creates intermediate dirs, not just one level); keepingos.Mkdir+os.Lstatis the minimal correct fix.— 🤖 Generated with Claude Code (claude-sonnet-4-6)
heiko referenced this issue2026-05-22 11:36:46 +02:00
AI attribution comment added per repository instruction for this open issue.\n\n(co)authored by ai:gpt-5-codex