fix(kvb-check-security): never copy a file through a symlinked folder

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 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-19 07:26:31 +00:00
1 parent 731d0df43b
commit 67cbe0ddd3
2 files changed
+16 -2

No files matched your search

+13
View File
@@ -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")