Skip to content

Improve .gitmodules file handling in scan_content_warn - #1

Open
0xScratch wants to merge 1 commit into
devdacian:mainfrom
0xScratch:gitmodules-fix
Open

Improve .gitmodules file handling in scan_content_warn#1
0xScratch wants to merge 1 commit into
devdacian:mainfrom
0xScratch:gitmodules-fix

Conversation

@0xScratch

Copy link
Copy Markdown

While exploring coldclone, I ran into a weird TypeError related to .gitmodules when scanning a Sherlock audit repository (TARE). Here's the .gitmodules present in the repo:

[submodule "tare-io__tare-contracts/lib/solmate"]
	path = tare-io__tare-contracts/lib/solmate
	url = https://github.com/transmissions11/solmate
[submodule "tare-io__tare-contracts/lib/forge-std"]
	path = tare-io__tare-contracts/lib/forge-std
	url = https://github.com/foundry-rs/forge-std
[submodule "tare-io__tare-contracts/lib/createx-forge"]
	path = tare-io__tare-contracts/lib/createx-forge
	url = https://github.com/radeksvarz/createx-forge
[submodule "tare-io__tare-contracts/lib/safe-smart-account"]
	path = tare-io__tare-contracts/lib/safe-smart-account
	url = https://github.com/safe-global/safe-smart-account
[submodule "tare-io__tare-contracts/lib/openzeppelin-contracts"]
	path = tare-io__tare-contracts/lib/openzeppelin-contracts
	url = https://github.com/OpenZeppelin/openzeppelin-contracts

And when coldclone was run on this repo, I got the following error:

WARN could not parse .gitmodules (TypeError); review manually

After digging in the issue, and checking the two main functions i.e. _warn_gitmodules and scan_content_warn, it turns out that the issue is related to some newline thing which even has a comment explaining why it's there:

def scan_content_warn(repo: Path) -> list[str]:

...

    elif nm == ".gitmodules":
        # newline="" preserves \r so the CVE-2025-48384 CR vector is
        # not silently translated to \n before _warn_gitmodules sees it
        out += _warn_gitmodules(
            rel, p.read_text(encoding="utf-8", errors="replace", newline=""))

...

    return out

The issue is that, Path.read_text() only accepts the newline parameter starting from Python 3.13, causing .gitmodules scanning to fail with a TypeError on Python 3.11 and 3.12, despite the project indicating support for Python >= 3.11.

So I think a better approach is to use Path.open(..., newline=""), which preserves the intended behaviour while remaining compatible with earlier supported python versions. The fixed code snippet looks like:

def scan_content_warn(repo: Path) -> list[str]:

...

    elif nm == ".gitmodules":
        # newline="" preserves \r so the CVE-2025-48384 CR vector is
        # not silently translated to \n before _warn_gitmodules sees it
        with p.open(
            "r", encoding="utf-8", errors="replace", newline=""
        ) as f:
             out += _warn_gitmodules(rel, f.read())

...

    return out

This removes the TypeError while preserving the intended newline behaviour. Additionally, just for precaution sake, I also checked whether this new fix doesn't break anything related to .gitmodules by adding various weird urls. Thankfully, it doesn't and still gives warning for weird stuff!

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