The vulnerability allows an attacker to craft a malicious git repository that, when cloned and operated on by bbot, can leak the user's GitHub API keys. This is achieved by placing malicious commands in the repository's .git/config file, which are then executed by subsequent git commands.
The analysis of the patch 0ede97fa887de33fcfd1378b4213a09c21dc6140 reveals the vulnerable areas and the mitigation strategy.
-
A new, more robust sanitization function sanitize_git_repo was introduced in bbot/core/helpers/git.py. Instead of trying to parse and clean the git config, it simply renames the .git/config, .git/index, and .git/hooks files, effectively neutralizing any malicious content within them.
-
In bbot/modules/git_clone.py, the clone_git_repository function was identified as a primary entry point for the vulnerability. It clones a repository but previously performed no sanitization. The patch rectifies this by adding a call to the new sanitize_git_repo function immediately after the clone operation. This indicates that clone_git_repository was a vulnerable function.
-
In bbot/modules/gitdumper.py, a function named sanitize_config was removed. This function represented an earlier, insufficient attempt to mitigate the vulnerability by using a regex to comment out dangerous commands. Its removal and replacement show it was part of the vulnerable logic.
-
The git_checkout function in gitdumper.py was modified to call the new sanitize_git_repo function. This is because git checkout is a command that can trigger the malicious configuration. By adding the sanitization step, the patch secures this operation.
-
The handle_event function in gitdumper.py previously called the inadequate sanitize_config. The removal of this call further confirms that the gitdumper module had a vulnerable workflow.
Therefore, the functions GitClone.clone_git_repository, GitDumper.git_checkout, and GitDumper.handle_event would be active during exploitation. The removed GitDumper.sanitize_config function is also a key indicator of the vulnerability's nature and the flawed attempts to fix it.