From 67cbe0ddd398687702a123ee5ae0bac7d3446e87 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 19 Nov 2026 07:26:31 +0000 Subject: [PATCH] fix(kvb-check-security): never copy a file through a symlinked folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit copy() checked is_symlink() only on the last path part. When a committed folder is replaced by a link to an outside directory, git diff still lists the files below it, so root / name resolved through the link and the scan copied and read a file outside the repository. A source whose resolved path leaves the repository is now skipped. Found by an independent skeptic review of a MEDUSA temp-file hit. 🎯 Fix: 96 % 💥 Break: 2 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 94 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- skills/kvb-check-security/scripts/security.py | 5 +++-- tests/test_security.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/skills/kvb-check-security/scripts/security.py b/skills/kvb-check-security/scripts/security.py index d6e3a73..494b32a 100755 --- a/skills/kvb-check-security/scripts/security.py +++ b/skills/kvb-check-security/scripts/security.py @@ -291,11 +291,12 @@ def copy(root: Path, paths: list[str], tree: Path) -> dict[str, str]: the tree path of every copied file mapped to its repository path. """ names = {} + top = root.resolve() taken = set(paths) | {parent.as_posix() for name in paths for parent in Path(name).parents} for name in paths: source = root / name - # Trip-wire: a symlink's target may lie outside the repository; even a copied link lets the scan read it. - if source.is_symlink() or not source.is_file(): + # Trip-wire: a symlink's target may lie outside the repository, also through a linked parent folder; even a copied link lets the scan read it. + if source.is_symlink() or not source.resolve().is_relative_to(top) or not source.is_file(): continue scratch = name if Path(name).suffix.lower() in SKIPPED: diff --git a/tests/test_security.py b/tests/test_security.py index 379202e..eadca0a 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -609,6 +609,19 @@ class TestSecurity(unittest.TestCase): unread = f"{never}: medusa's own types, exclusions and limits are unreadable from its source: {HAND}" self.assertEqual((result.stdout, result.returncode), (f"🛡️ security – ({unread})\n", 4)) + def test_a_file_behind_a_symlinked_folder_is_never_copied(self): + self.write("dir/a.py", "x = 1\n") + self.git("add", "-A") + self.git("commit", "-qm", "dir") + outside = self.base / "outside" + outside.mkdir() + (outside / "a.py").write_text("secret = 1 # MARK-CRITICAL\n", encoding="utf-8") + shutil.rmtree(self.repo / "dir") + (self.repo / "dir").symlink_to(outside) + self.write("app.py", "print(1)\nx = 1 # MARK-LOW\n") + found = json.loads(self.scan("--json", env=self.env).stdout) + self.assertEqual(([(f["path"], f["severity"]) for f in found["findings"]], found["files"]), ([("app.py", "low")], 1)) + def test_a_file_a_path_exclusion_drops_is_scanned_and_named_at_its_repository_path(self): self.write("app.py", "print(1)\nx = 1 # MARK-HIGH\n") self.write("utils/env/run.py", "y = 1 # MARK-LOW\n")