Repository navigation
Never write or follow a link in the staging directory as root - #2102
Merged
Merged
Conversation
fog-sign-node-cert runs as root through sudo, but the web user owns the staging directory it works in. Root wrote, chmodded and read files there by name. A symlink placed at the right moment made root overwrite a file the link named and make it world-readable, and a linked name list made root print another file's lines back in its error. The helper now works in a root-only directory beside staging. It copies the staged inputs in with dd iflag=nofollow, so a link is refused. It builds the outputs there and renames them into staging; rename replaces a link and never writes through one. The parent of staging must be owned by root and writable only by root, or the helper refuses to run. A name-list refusal now names the line number, not the line. nofollow does not stop a hard link, so printing the line could still hand a root-only file's content to the web user where fs.protected_hardlinks is off. tests/node-cert-external-ca.test.sh case H: a linked name list whose target is valid must issue nothing, and a refused entry must not be printed. Both fail on the old helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Problem
fog-sign-node-certruns as root throughsudo, but the web user owns the staging directory it works in. Root wrote, chmodded and read files there by name. A process running as the web user could place a symlink there and make root overwrite, or chmod 0644, a file the link names. A linked name list made root print another file's lines in its error. This needs the web user already compromised; it raises that to root-file damage.Change
mktemp -d) beside staging, on the same filesystem..csr,.san,.agent) are copied in withdd iflag=nofollow,nonblock, so a link is refused.mv -T. rename replaces a link and never writes through one.chown/chmodthat fixes it. A default install (/opt/fog, root 0755) passes.nofollowdoes not stop a hard link wherefs.protected_hardlinks=0.The PHP callers (
service/nodecert.php,Agent\Enrollment) are unchanged. The outputs are still root-owned 0644 in staging.Verified
tests/node-cert-external-ca.test.shcase H:nofollowremoved, and against a helper that prints the line, case H fails each time. On the fix, all 27 checks pass.agent-ca-follows-rootandtrust-anchorpass.🤖 Generated with Claude Code