Repository navigation
fix: refuse Bash commands that print a credential in runner sessions - #266
Merged
Merged
Conversation
PreviewsThe start.coder.ddev.com landing-page preview has been removed. Read the Docs keeps or removes its own docs preview. |
This was referenced Nov 24, 2026
Member
Author
|
Tested in a live runner session on staging-coder.ddev.com (freeform version Generated by Claude Code |
A runner session wrote a commit message inside bash -c "..." that quoted the Coder external-auth access-token command in backticks. The shell ran it, the owner's GitHub token went into a commit pushed to this repository, and GitHub's secret scanning revoked it. AGENTS.md already said to pass commit messages through a file, but that session had started in another repository and never read it. Runner sessions now get a managed PreToolUse hook that refuses Bash commands printing a credential (Coder external-auth tokens, gh auth token, git credential fill), whatever repository the session works in. AGENTS.md says why messages go through a file, and to never print a credential. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrTUMxoyzqiN3JtHacV96S
gh-read can now take a machine token from the macOS Keychain or ~/.config/gh-read/token, so the hook refuses security find-generic-password, find-internet-password and commands naming that file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrTUMxoyzqiN3JtHacV96S
Without jq the hook read an empty command and let everything through. It now falls back to matching the raw JSON input, so credential commands are still refused on a machine without jq, such as a fresh macOS runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrTUMxoyzqiN3JtHacV96S
rfay
force-pushed
the
20261124_rfay_block_token_commands
branch
from
November 24, 2026 21:20
a01c695 to
0428d83
Compare
Documentation build overview
|
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.
The Issue
A Claude Code runner session wrote a commit message inside a double-quoted
bash -c "..."string. The message quoted the Coder external-auth access-token command in backticks, so the shell ran it, and the workspace owner's GitHub token went into the message of a commit pushed to a branch of this repository. GitHub's secret scanning found it and revoked the token. The commit was replaced on that branch soon after.AGENTS.md already said to pass commit messages through a file. The session had started in
ddev/ddev, with this repository only as an extra directory, so it never loaded this AGENTS.md. A rule that lives in one repository doesn't reach a runner session that starts in another.How This PR Solves The Issue
PreToolUsehook,claude-deny-token-commands, that refuses Bash commands that print a credential: the Coder external-auth access-token command,gh auth token, andgit credential fill. It's installed with the other runner files, and every runner session uses it, whatever repository it starts in. Tools that need a token fetch it themselves, outside the Bash tool's command string, so they still work.$(...)run inside double quotes), to write that file with the editor tool, and to never run a command that prints a credential.Manual Testing Instructions
freeformtemplate with the runner enabled and start a runner session.gh auth token. The hook refuses it with an explanation.bash -c "...". The hook refuses that too.git commit -F <file>, andgrep access-tokenstill run.I ran the hook script on those sample commands (refused: the three credential commands, including one quoted in backticks; allowed: the rest, and input with no command), and ran
shellcheckon it. I haven't tested it in a live runner session on staging yet.Automated Testing Overview
None added.
terraform fmtandmake validateweren't run here, because Terraform isn't installed in this workspace; CI runs them.Release/Deployment Notes
Takes effect when a workspace with the runner enabled is rebuilt from the new
freeformversion.Generated by Claude Code