Repository navigation
Harden agent log file creation in the shared log directory - #515
Merged
Merged
Conversation
The agent log directory is world-writable and log file names are predictable, so another local user could plant a file or symlink under the name before the agent opens it. Open log files with O_EXCL so an existing entry is never followed or reused, and stop creating them world-writable. Also set the sticky bit on /var/log/aikido-* and /run/aikido-* so users cannot remove or replace each other's files there, and escape CR/LF in log messages so logged request data cannot forge extra log lines.
One token can register several servers (one per PHP server PID), so two servers with the same token registering in the same second used to get the same log file name. With O_EXCL the second one would fail to open its log file, so add the server PID to keep the names unique.
teta2k
marked this pull request as ready for review
October 8, 2026 14:39
hansott
approved these changes
Oct 8, 2026
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.
Summary
The agent writes its logs to
/var/log/aikido-<version>/, which is world-writable so PHP processes running as the web server user can log there too. Log file names are predictable, so another local user could create a file or symlink under the name before the agent opens it.O_CREATE|O_EXCL, so an existing file or symlink (including a dangling one) is never followed or reused. If the name is taken, the agent logs to stdout as it already does when the open fails. New log files are0644instead of0666.aikido-agent-<time>-<agent pid>-<token tail>-<server pid>.log). One token can register several servers, and two of them registering in the same second used to share one file name; they opened the same file at offset 0 and overwrote each other's lines. WithO_EXCLthe second one would have fallen back to stdout, so the names now stay unique instead./var/log/aikido-*and/run/aikido-*as1777instead of0777, so users can't delete or replace each other's files there. On most distros this also enables the kernel'sprotected_symlinks/protected_regularchecks for these directories....\nmessages don't print a literal\n.Notes
/run/aikido-*left behind by a root agent.Testing
lib/agent/log/log_test.go: planted symlink, dangling symlink and pre-existing file are all refused and left untouched; new file is not group/world-writable; newlines are escaped; trailing newlines are trimmed.go vetonlogandserver_utilsis clean;go test ./...inlib/agentpasses on Linux.