fix: use description as pattern_key to prevent approval collisions

pattern_key was derived by splitting the regex on \b and taking [1],
so patterns starting with the same word (e.g. find -exec rm and
find -delete) produced the same key "find". Approving one silently
approved the other. Using the unique description string as the key
eliminates all collisions.
This commit is contained in:
0xbyt4 2026-03-12 22:39:46 +03:00 committed by teknium1
parent 08081e5969
commit 4a93cfd889
2 changed files with 28 additions and 1 deletions

View file

@ -63,7 +63,7 @@ def detect_dangerous_command(command: str) -> tuple:
command_lower = command.lower()
for pattern, description in DANGEROUS_PATTERNS:
if re.search(pattern, command_lower, re.IGNORECASE | re.DOTALL):
pattern_key = pattern.split(r'\b')[1] if r'\b' in pattern else pattern[:20]
pattern_key = description
return (True, pattern_key, description)
return (False, None, None)