From f85f7cfcbbe9c949ba63304add8be7daf5c13e78 Mon Sep 17 00:00:00 2001 From: mmoore Date: Tue, 1 Sep 2026 11:18:30 -0700 Subject: Claude Security Plugin - v0.11.0 --- plugins/claude-security/scripts/lib/absolute.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'plugins/claude-security/scripts/lib/absolute.py') diff --git a/plugins/claude-security/scripts/lib/absolute.py b/plugins/claude-security/scripts/lib/absolute.py index 45f28ed3..fa72a510 100644 --- a/plugins/claude-security/scripts/lib/absolute.py +++ b/plugins/claude-security/scripts/lib/absolute.py @@ -1,9 +1,10 @@ -"""Whether a path is spelled absolutely on any platform, not just the one this runs on.""" +"""Whether a path is absolute on any platform, and where an absolute path sits under a root.""" from __future__ import annotations import ntpath import os +from pathlib import PurePath def spelled(path: str) -> bool: @@ -13,3 +14,13 @@ def spelled(path: str) -> bool: or path.replace("\\", "/").startswith("/") or bool(ntpath.splitdrive(path)[0]) ) + + +def relative(path: str, root: str) -> str | None: + """Where a normalised absolute `path` sits below `root`, as "a/b" ("." for root); else None.""" + try: + inside = PurePath(path).relative_to(root) + except ValueError: + return None + # A ".." could name somewhere above root; a normalised path never carries one. + return None if ".." in inside.parts else inside.as_posix() -- cgit