Skip to content

Avoid passing GitHub token in git clone URL (argv leak via ps)#100

Open
shotaro421 wants to merge 1 commit intoanthropics:mainfrom
shotaro421:fix/clone-url-token-leak
Open

Avoid passing GitHub token in git clone URL (argv leak via ps)#100
shotaro421 wants to merge 1 commit intoanthropics:mainfrom
shotaro421:fix/clone-url-token-leak

Conversation

@shotaro421
Copy link
Copy Markdown

Summary

  • _setup_repository in claudecode/evals/eval_engine.py builds the
    git clone URL as https://{token}@github.com/... and passes it as a
    positional argument to
    subprocess.run(['git', 'clone', ..., clone_url, ...]). argv is
    visible to every other local user via ps -ef for the duration of
    the clone, git additionally persists the URL in the cloned repo's
    .git/config, and any error path that echoes the failed command can
    emit the token to stderr.
  • This PR replaces that with the standard GIT_ASKPASS mechanism: the
    token is supplied to git via an environment variable read by a small
    temp shell helper, so it never appears in argv or .git/config. The
    clone URL uses x-access-token as a placeholder username, and the
    helper file is created with mode 0o700 and removed in a finally
    block.

Test plan

  • Existing test suite still green (174 passed)
  • New regression test
    test_setup_repository_clone_does_not_leak_token_in_argv walks
    every recorded subprocess.run call and asserts the token never
    appears in any argv element, and verifies GIT_ASKPASS /
    GIT_AUTH_TOKEN are set on the clone env.

How this was found

The issue surfaced during a self-audit of a downstream fork that wraps
this repository. Happy to share the original finding payload if useful.

_setup_repository builds clone_url as https://{token}@github.com/... and
passes it positionally to subprocess.run(['git', 'clone', ..., clone_url]).
argv is readable by every other local user through `ps -ef` for the
duration of the clone, git persists the URL in the cloned repo's
.git/config, and any error path that echoes the failed command will
emit the token to stderr.

Switch to the standard GIT_ASKPASS mechanism: the token is supplied to
git via an environment variable read by a small mode-0700 temp shell
helper, so it never appears in argv or .git/config. The clone URL uses
`x-access-token` as a placeholder username, and the helper file is
unlinked in a `finally` block.

Adds a regression test that walks every recorded subprocess.run call and
asserts the token never appears in any argv element, and verifies that
GIT_ASKPASS / GIT_AUTH_TOKEN are set on the clone env. Existing test
suite remains green (174 passed including the new test).
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.

1 participant