feat(git): restrict submodule recursion and credential access - #208
Open
nidsnitesh wants to merge 1 commit into
Open
feat(git): restrict submodule recursion and credential access#208nidsnitesh wants to merge 1 commit into
nidsnitesh wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.gitmodulesfile 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:
entrypoint.sh: Configuressubmodule.recurse=falseandfetch.recurseSubmodules=falsevia Git environment variables so submodules are never fetched automatically.git-credential.sh: Checks ifGIT_DIRpoints to a submodule context (*/.git/modules/*) and refuses to return credentials.multiscan.ts: Appends-c submodule.recurse=falseto checkout commands in the SDK.