From 75b0ec8662d687f83d4e5223e9683e7fa2bac9bc Mon Sep 17 00:00:00 2001 From: mesutoezdil Date: Tue, 1 Dec 2026 21:56:00 +0100 Subject: [PATCH] fix(sandbox): match protected names in staging whatever their case Signed-off-by: mesutoezdil --- reference/core/environments/staging.py | 8 ++++---- reference/scripts/mutation_test.py | 2 +- reference/tests/test_sandbox_isolation.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/reference/core/environments/staging.py b/reference/core/environments/staging.py index f78ab73..dad6be3 100644 --- a/reference/core/environments/staging.py +++ b/reference/core/environments/staging.py @@ -103,7 +103,7 @@ def get_vetted_staging_files(target_path: Union[str, Path]) -> List[Tuple[Path, if os.path.isfile(target_str): fname = os.path.basename(target_str) - if fname in PROTECTED_METADATA_FILES or fname in PROTECTED_VCS_DIRS: + if fname.lower() in PROTECTED_METADATA_FILES or fname.lower() in PROTECTED_VCS_DIRS: return [] try: if os.lstat(target_str).st_nlink > 1: @@ -120,15 +120,15 @@ def get_vetted_staging_files(target_path: Union[str, Path]) -> List[Tuple[Path, # Prune VCS directories and symlinked directories immediately dirs[:] = [ d for d in dirs - if d not in PROTECTED_VCS_DIRS and not os.path.islink(os.path.join(root, d)) + if d.lower() not in PROTECTED_VCS_DIRS and not os.path.islink(os.path.join(root, d)) ] for file in files: - if file in PROTECTED_METADATA_FILES: + if file.lower() in PROTECTED_METADATA_FILES: continue # A gitdir pointer (".git" holding "gitdir: /elsewhere") is a regular # FILE, so the directory denylist above never sees it. Prune by name. - if file in PROTECTED_VCS_DIRS: + if file.lower() in PROTECTED_VCS_DIRS: continue src_file = os.path.join(root, file) diff --git a/reference/scripts/mutation_test.py b/reference/scripts/mutation_test.py index 3ed619d..edc2390 100644 --- a/reference/scripts/mutation_test.py +++ b/reference/scripts/mutation_test.py @@ -78,7 +78,7 @@ ], "revert_staging_vcs_and_hardlink": [ ("core/environments/staging.py", - " if file in PROTECTED_VCS_DIRS:\n continue\n", + " if file.lower() in PROTECTED_VCS_DIRS:\n continue\n", ""), ("core/environments/staging.py", " if st.st_nlink > 1:\n continue\n", diff --git a/reference/tests/test_sandbox_isolation.py b/reference/tests/test_sandbox_isolation.py index 79f50c3..2b9fcfe 100644 --- a/reference/tests/test_sandbox_isolation.py +++ b/reference/tests/test_sandbox_isolation.py @@ -313,6 +313,23 @@ async def fake_create(name, **kwargs): self.assertIn("MANTIS_MAX_STAGING_BYTES", str(ctx_msb.exception)) +class StagingProtectedNamesTest(unittest.TestCase): + def test_protected_names_are_matched_whatever_their_case(self): + import os + import tempfile + + from core.environments import staging + + with tempfile.TemporaryDirectory() as tmp: + for rel in ("app.py", ".GIT/config", ".Npmrc", ".ENV", ".NetRC"): + path = os.path.join(tmp, rel) + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, "w") as fh: + fh.write("x\n") + staged = sorted(rel for _, rel in staging.get_vetted_staging_files(tmp)) + self.assertEqual(staged, ["app.py"]) + + class GceHardeningTest(unittest.IsolatedAsyncioTestCase): """GCE ssh calls isolate host stdin, disable agent forwarding, and probe PGA VIPs by IP."""