Skip to content

fix: refuse Bash commands that print a credential in runner sessions - #266

Merged
rfay merged 3 commits into
mainfrom
20261124_rfay_block_token_commands
Nov 24, 2026
Merged

rfay merged 3 commits into
mainfrom
20261124_rfay_block_token_commands

Conversation

@rfay

@rfay rfay commented Nov 24, 2026

Copy link
Copy Markdown
Member

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

  • Runner sessions get a managed PreToolUse hook, claude-deny-token-commands, that refuses Bash commands that print a credential: the Coder external-auth access-token command, gh auth token, and git 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.
  • AGENTS.md now says why messages go through a file (backticks and $(...) run inside double quotes), to write that file with the editor tool, and to never run a command that prints a credential.
  • The runner README mentions the hook.

Manual Testing Instructions

  1. Push the freeform template with the runner enabled and start a runner session.
  2. Ask the session to run gh auth token. The hook refuses it with an explanation.
  3. Ask it to commit with a message that quotes a credential command in backticks inside bash -c "...". The hook refuses that too.
  4. Ordinary commands, git commit -F <file>, and grep access-token still 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 shellcheck on it. I haven't tested it in a live runner session on staging yet.

Automated Testing Overview

None added. terraform fmt and make validate weren'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 freeform version.


Generated by Claude Code

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Previews

The start.coder.ddev.com landing-page preview has been removed. Read the Docs keeps or removes its own docs preview.

rfay commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Tested in a live runner session on staging-coder.ddev.com (freeform version gh-read-3, this branch combined with the gh-read branch). Asked to run gh auth token, the session tried t=$(gh auth token ...) with a redacted echo; the hook refused it with its "Blocked: this command would print a credential…" message, and the session stopped there without trying another way.


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
rfay force-pushed the 20261124_rfay_block_token_commands branch from a01c695 to 0428d83 Compare November 24, 2026 21:20
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 coder-ddev | 🛠️ Build #36143503 | 📁 Comparing 0428d83 against latest (55ead6e)

  🔍 Preview build  

1 file changed
± workspaces/ai-tools/index.html

@rfay
rfay merged commit 7d46ecb into main Nov 24, 2026
21 checks passed
@rfay
rfay deleted the 20261124_rfay_block_token_commands branch November 24, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants