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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user