[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2026-05-24 15:14:47 +00:00
commit c7c2e70559
2 changed files with 20 additions and 34 deletions

View file

@ -370,7 +370,9 @@ _BASH_DIR_EXFIL_RE = re.compile(
+ r")\b[^;&|\n]*?"
+ r"(?:"
+ _HOME_PREFIX_RE
+ r"(?:" + "|".join(_BASH_SENSITIVE_DIR_NAMES) + r")"
+ r"(?:"
+ "|".join(_BASH_SENSITIVE_DIR_NAMES)
+ r")"
+ r"(?=/?$|/?[\s'\";&|)<>])"
+ r"|"
+ r"(?<![A-Za-z0-9_./~$%-])/etc(?=/?$|/?[\s'\";&|)<>])"
@ -446,17 +448,13 @@ def _normalize_path_separators(text: str) -> str:
tail = collapsed[len(prefix) :]
if tail.startswith("..") or tail.startswith("./.."):
return posixpath.normpath("/" + tail)
return prefix + posixpath.normpath(
"/" + tail
).lstrip("/")
return prefix + posixpath.normpath("/" + tail).lstrip("/")
tilde_user = _TILDE_USER_PREFIX_RE.match(collapsed)
if tilde_user:
tail = collapsed[tilde_user.end() :]
if tail.startswith("..") or tail.startswith("./.."):
return posixpath.normpath("/" + tail)
return tilde_user.group(0) + posixpath.normpath(
"/" + tail
).lstrip("/")
return tilde_user.group(0) + posixpath.normpath("/" + tail).lstrip("/")
collapsed = posixpath.normpath(collapsed)
return collapsed
@ -1542,9 +1540,7 @@ def _check_signal_escape_patterns(code: str):
elif _node.module == "pathlib":
for alias in _node.names:
if alias.name in _PATHLIB_PATH_CLASSES_PREPASS:
path_class_aliases_prepass.add(
alias.asname or alias.name
)
path_class_aliases_prepass.add(alias.asname or alias.name)
_run_alias_prepass(tree)
@ -1894,9 +1890,11 @@ def _check_signal_escape_patterns(code: str):
# Annotated assignment (``path: str = '/etc/shadow'``) is
# an ast.AnnAssign, not an ast.Assign. Same surface: a
# single Name target bound to a single value.
if isinstance(_assign, ast.AnnAssign) and isinstance(
_assign.target, ast.Name
) and _assign.value is not None:
if (
isinstance(_assign, ast.AnnAssign)
and isinstance(_assign.target, ast.Name)
and _assign.value is not None
):
_val = _extract_string_from_node(_assign.value)
if _val is None:
_val = _extract_pathlib_target(

View file

@ -2062,9 +2062,7 @@ class TestR6_PathTraversalNormalization:
],
)
def test_path_traversal_blocked(self, cmd):
assert _find_sensitive_paths(cmd), (
f"path traversal leaked: {cmd!r}"
)
assert _find_sensitive_paths(cmd), f"path traversal leaked: {cmd!r}"
class TestR6_PandasNumpyKeywordArgs:
@ -2126,9 +2124,7 @@ class TestR6_BashDirectoryExfil:
],
)
def test_bash_dir_exfil_blocked(self, cmd):
assert _find_sensitive_paths(cmd), (
f"bash dir exfil leaked: {cmd!r}"
)
assert _find_sensitive_paths(cmd), f"bash dir exfil leaked: {cmd!r}"
@pytest.mark.parametrize(
"cmd",
@ -2142,9 +2138,7 @@ class TestR6_BashDirectoryExfil:
],
)
def test_bash_dir_exfil_legit_allowed(self, cmd):
assert not _find_sensitive_paths(cmd), (
f"legit bash dir blocked: {cmd!r}"
)
assert not _find_sensitive_paths(cmd), f"legit bash dir blocked: {cmd!r}"
class TestR6_InnerTreeAliasWalk:
@ -2194,9 +2188,7 @@ class TestR6_ChainedAndAnnAssign:
],
)
def test_chained_annassign_legit_allowed(self, code):
assert not _is_blocked(code), (
f"legit chained/AnnAssign blocked: {code!r}"
)
assert not _is_blocked(code), f"legit chained/AnnAssign blocked: {code!r}"
class TestR6_BraceBombEmptyAlt:
@ -2215,9 +2207,9 @@ class TestR6_BraceBombEmptyAlt:
def test_brace_bomb_empty_alt_blocked(self, n_dummies):
dummies = ",".join(f"x{i}" for i in range(n_dummies))
cmd = f"cat ~/{{,{dummies}}}/{{.ssh/id_rsa,other}}"
assert _find_sensitive_paths(cmd), (
f"brace empty-alt bomb leaked at n={n_dummies}: {cmd!r}"
)
assert _find_sensitive_paths(
cmd
), f"brace empty-alt bomb leaked at n={n_dummies}: {cmd!r}"
@pytest.mark.parametrize(
"cmd",
@ -2228,9 +2220,7 @@ class TestR6_BraceBombEmptyAlt:
],
)
def test_inner_brace_sensitive_blocked(self, cmd):
assert _find_sensitive_paths(cmd), (
f"inner-brace sensitive name leaked: {cmd!r}"
)
assert _find_sensitive_paths(cmd), f"inner-brace sensitive name leaked: {cmd!r}"
@pytest.mark.parametrize(
"cmd",
@ -2241,6 +2231,4 @@ class TestR6_BraceBombEmptyAlt:
],
)
def test_brace_legit_allowed(self, cmd):
assert not _find_sensitive_paths(cmd), (
f"legit brace blocked: {cmd!r}"
)
assert not _find_sensitive_paths(cmd), f"legit brace blocked: {cmd!r}"