🔒 Fix Denial of Service vulnerability in is_empty
Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
This commit is contained in:
parent
5799bb3f00
commit
2192a32d03
11
cli/main.py
11
cli/main.py
|
|
@ -826,8 +826,6 @@ def extract_content_string(content):
|
|||
"""Extract string content from various message formats.
|
||||
Returns None if no meaningful text content is found.
|
||||
"""
|
||||
import ast
|
||||
|
||||
def is_empty(val):
|
||||
"""Check if value is empty using Python's truthiness."""
|
||||
if val is None or val == '':
|
||||
|
|
@ -836,10 +834,11 @@ def extract_content_string(content):
|
|||
s = val.strip()
|
||||
if not s:
|
||||
return True
|
||||
try:
|
||||
return not bool(ast.literal_eval(s))
|
||||
except (ValueError, SyntaxError):
|
||||
return False # Can't parse = real text
|
||||
# Check for common string representations of "empty" values
|
||||
# to avoid using unsafe ast.literal_eval
|
||||
if s.lower() in ("[]", "{}", "()", "none", "false", "0", "0.0", '""', "''"):
|
||||
return True
|
||||
return False
|
||||
return not bool(val)
|
||||
|
||||
if is_empty(content):
|
||||
|
|
|
|||
Loading…
Reference in New Issue