Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions reference/core/environments/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion reference/scripts/mutation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions reference/tests/test_sandbox_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down