Skip to content

[Bug]: tests run outside the repo root can write OAuth credentials into the real ~/.opencodex/auth.json #7407

Closed

Description

@lidge-jun

Client or integration

Other

Area

Other

Summary

A test process that bun starts without loading bunfig.toml can write OAuth credentials into the developer's real ~/.opencodex/auth.json. Bun resolves bunfig.toml from the current working directory, so cd elsewhere && bun test <repo>/tests/x.test.ts loads no tests/preload.ts: HOME/OPENCODEX_HOME are not sandboxed and the real-home write guard stays disarmed. bunfig.toml documents this, and tests/ci-workflows/test-home-guard.test.ts enforces a pinned OPENCODEX_HOME only for the destructive rmSync(getConfigDir()) case. Non-destructive credential-store writes (saveCredential, upsertCredentialByIdentity, account-set mutations through src/oauth/store.ts) are not covered. A test that writes the store without pinning OPENCODEX_HOME silently adds accounts to the real auth store and can change the active account when run from another directory.

This happened during review of #7397. A scratch reproduction was run with the working directory outside the repository root. It called saveCredential("anthropic", …) without pinning OPENCODEX_HOME and added a fixture Anthropic account to the real auth store, which it made active. It was repaired by hand. The test was not repository-tracked, but nothing in the repository would have stopped a tracked test from doing the same.

Expected: when the process is a test run (bun test) and the sandbox preload was not loaded, credential-store writes should refuse to target the real home. One option is for src/oauth/store.ts, or the config-dir resolver, to fail closed under bun test unless OPENCODEX_HOME is set explicitly. The other is to extend test-home-guard.test.ts to require a pinned OPENCODEX_HOME in any test file that writes the OAuth store, not only in destructive ones.

Reproduction

  1. From a directory outside the repository (so bunfig.toml is not loaded), run a test file that calls saveCredential("anthropic", { access: "x", refresh: "y", expires: Date.now() + 3600000, email: "[email protected]" }) without setting OPENCODEX_HOME.
  2. Inspect ~/.opencodex/auth.json: the fixture account is present and active.

Version

dev at 1cf98c0 (2.90.0 development)

Operating system

macOS (any platform; cwd-dependent bunfig resolution is Bun behavior)

Provider and model

N/A (test infrastructure; affects any OAuth provider store)

Logs or error output

None. The write succeeds silently.

Screenshots and supporting files

No response

Redacted configuration

No response

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    on Oct 19, 2026
  2. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  3. added
    account-pool
    on Oct 19, 2026
  4. Ingwannu commented on Oct 20, 2026

    @Ingwannu
    Owner

    Checked against trusted dev 12025981e5a304cdb6b1b54f525ba8554f623977. The reported mechanism matches the current guard: OAuth persistence calls assertNotRealHomeUnderTest, but isTestHomeGuardArmed requires the preload-owned OCX_TEST_HOME_GUARD=1. The guard explicitly promises to stay inert in production, including NODE_ENV=test, so broad environment guessing would change that contract. Keep this open for a fail-closed harness/entrypoint design and an outside-cwd regression with a fake protected home, explicit credential-store mutation coverage, and a production-inertness negative. I will not reproduce against a real auth store. A static destructive-removal scan alone does not cover the reported non-destructive write path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-poolbug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions