Skip to content

feat(git): restrict submodule recursion and credential access - #208

Open
nidsnitesh wants to merge 2 commits into
openai:mainfrom
nidsnitesh:fix/credential-helper-submodule-token-leak
Open

feat(git): restrict submodule recursion and credential access#208
nidsnitesh wants to merge 2 commits into
openai:mainfrom
nidsnitesh:fix/credential-helper-submodule-token-leak

Conversation

@nidsnitesh

Copy link
Copy Markdown

Summary

Fixes a security issue where Git credential helpers could leak GitHub access tokens (GH_TOKEN/GITHUB_TOKEN) when processing submodules.

Details

When scanning a repository, a malicious .gitmodules file pointing to another repository on the same host (e.g. github.com) would cause Git's credential helper to be invoked for the submodule fetch. Since the helper checked the host but not the target repository path or context, it would hand out the token to the attacker-controlled repo.

Fix

This PR implements 3 layers of defense-in-depth:

  1. entrypoint.sh: Configures submodule.recurse=false and fetch.recurseSubmodules=false via Git environment variables so submodules are never fetched automatically.
  2. git-credential.sh: Checks if GIT_DIR points to a submodule context (*/.git/modules/*) and refuses to return credentials.
  3. multiscan.ts: Appends -c submodule.recurse=false to checkout commands in the SDK.

The git credential helper validates the host but not the request context,
so a malicious .gitmodules inside a scanned repository that points to
another repo on the same host (e.g. github.com) would cause the helper
to hand out the GH_TOKEN/GITHUB_TOKEN to the attacker-controlled repo.

This commit adds three layers of defense:

1. entrypoint.sh: Set submodule.recurse=false and
   fetch.recurseSubmodules=false via GIT_CONFIG_* environment
   variables so Git never automatically fetches submodules.

2. git-credential.sh: Detect submodule context by checking if
   GIT_DIR points under .git/modules/ and refuse to serve
   credentials in that case.

3. multiscan.ts: Pass -c submodule.recurse=false to all git
   commands in checkoutRevision() as SDK-level defense-in-depth.
@github-actions github-actions Bot added the bug Something isn't working label Aug 2, 2026
@mldangelo-oai mldangelo-oai added enhancement New feature or request question Further information is requested and removed bug Something isn't working labels Aug 3, 2026
@mldangelo-oai mldangelo-oai changed the title fix: prevent credential token leak via Git submodules feat(git): restrict submodule recursion and credential access Aug 3, 2026
@mldangelo-oai

Copy link
Copy Markdown
Collaborator

@codex review exact head d6c1b56

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: d6c1b56e48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: d6c1b56e48

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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

Labels

enhancement New feature or request question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants