GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

CVE-2023-40590 fix capitalized all environment variables on Windows

Open irwand opened this issue 3 years ago • 1 comments

This fix: https://github.com/gitpython-developers/GitPython/commit/6029211d729a0dd81e08fcc9c1a3ab7fe9af85c9 capitalized all environment variables on Windows. It can be illustrated by this short program:

import subprocess

print(subprocess.check_output(
    "set | findstr /c:SystemRoot /i", shell=True, universal_newlines=True
))

import git

print(subprocess.check_output(
    "set | findstr /c:SystemRoot /i", shell=True, universal_newlines=True
))

The output is:

SystemRoot=C:\Windows

SYSTEMROOT=C:\Windows

This side effect breaks our use case currently. We use gnu make in cygwin for our build, in which all environment variables are case sensitive.

The core problem was unittest.mock.patch.dict(os.environ, {"NoDefaultCurrentDirectoryInExePath": "1"}) -- in which it will try to treat os.environ as a dictionary, but os.environ is not just a simple dictionary. It actually remembers the original casing of the environment variable. Unfortunately when reading it as dictionary it capitalize all letters.

We can also observe the same side effect with this code below:

import os
import subprocess
import unittest.mock

print(subprocess.check_output(
    "set | findstr /c:SystemRoot /i", shell=True, universal_newlines=True
))

with unittest.mock.patch.dict(os.environ, {"NoDefaultCurrentDirectoryInExePath": "1"}):
    pass

print(subprocess.check_output(
    "set | findstr /c:SystemRoot /i", shell=True, universal_newlines=True
))

The side effect is the same as above.

irwand avatar Sep 06 '23 21:09 irwand

Thanks for reporting!

It's an unexpected side-effect for sure :/. Maybe there are other ways to solve the original problem instead of affecting the callers os.environ like that.

CC @EliahKagan

Byron avatar Sep 07 '23 05:09 Byron