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
✅ 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.
|
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>
d780697 to
7cde54a
Compare
|
Smoke Test Results — claude-sonnet-4-6
Overall: PASS
|
|
PR Titles:
|
Chroot Version Comparison Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.
|
Smoke Test Results — Run 23028546935
Overall: PASS PR author:
|
This comment has been minimized.
This comment has been minimized.
Multi-threaded programs like rustc call getenv() from many threads during startup. The previous fix held the mutex for every getenv() call to protect lazy initialization, which serialized all threads and caused rustc to timeout (60s) in CI. Move init_token_list() into the library constructor which runs before any threads are created. This eliminates the data race without needing the mutex for non-sensitive variable lookups. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Smoke Test Results
Overall: PASS
|
Chroot Version Comparison Results
Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.
|
|
🤖 Smoke test results for
Overall: PASS
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS Notes
|
|
PRs reviewed: feat(ci): add weekly performance monitoring workflow; fix(squid): run Squid container as non-root proxy user
|
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