Skip to content

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

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

feat(git): restrict submodule recursion and credential access#208
nidsnitesh wants to merge 1 commit 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
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