fix(security): use re.fullmatch per segment instead of re.search

Fixes chengyongru's review concern: re.search is more permissive
than the original re.fullmatch behavior for single-segment commands.
Using re.fullmatch per segment preserves backward compatibility while
still fixing the chained-command bypass.
This commit is contained in:
michaelxer
2026-07-21 13:50:24 +08:00
committed by Xubin Ren
parent bbca32fea9
commit f4a7079e65
+1 -1
View File
@@ -759,7 +759,7 @@ class ExecTool(Tool):
# only explicitly allowed when every top-level shell segment matches.
segments = self._split_shell_segments(lower)
explicitly_allowed = bool(self.allow_patterns) and bool(segments) and all(
any(re.search(pattern, segment) for pattern in self.allow_patterns)
any(re.fullmatch(pattern, segment) for pattern in self.allow_patterns)
for segment in segments
)
if not explicitly_allowed: