fix(cli): fix secure_getenv() bypass of one-shot token protection#1244
fix(cli): fix secure_getenv() bypass of one-shot token protection#1244
Conversation
secure_getenv() was calling get_token_index() before init_token_list() and without the mutex, causing all token protection to be bypassed when secure_getenv() was the first call into the library (empty token list returns -1 for all lookups). Added initialization, mutex acquisition, and recursion guard matching the getenv() implementation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical security flaw in the agent’s one-shot-token LD_PRELOAD library where secure_getenv() could bypass token protection if invoked before getenv(), ensuring sensitive environment variables are still cached/unset on first access.
Changes:
- Add mutex acquisition and
init_token_list()initialization tosecure_getenv()before callingget_token_index(). - Add the same thread-local recursion guard behavior to
secure_getenv()thatgetenv()already uses, preventing re-entrant deadlocks. - Ensure the non-sensitive path releases the mutex and clears the recursion guard before returning.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Smoke Test ResultsRecent merged PRs:
Overall: PASS
|
Smoke Test Results✅ GitHub MCP — Last 2 merged PRs:
✅ Playwright — github.com title contains "GitHub" Overall: PASS
|
|
PR titles:
|
Chroot Version Comparison Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.
|
Summary
secure_getenv()in the C one-shot-token library bypassed all token protection when called beforegetenv()secure_getenv()was callingget_token_index()beforeinit_token_list()and without the mutex, so the empty token list always returned -1 (not sensitive), passing raw token values throughsecure_getenv()matching the correctgetenv()implementationFixes #756
Test plan
npm run buildpassesnpm testpasses (856 tests)npm run lintpasseshandle_getenv_impl)🤖 Generated with Claude Code