mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
make regex verbose
This commit is contained in:
@@ -48,7 +48,35 @@ register_errors(job_blueprint)
|
|||||||
def is_suspicious_input(input_str):
|
def is_suspicious_input(input_str):
|
||||||
if not isinstance(input_str, str):
|
if not isinstance(input_str, str):
|
||||||
return False
|
return False
|
||||||
pattern = r"(?i)\b(OR|AND|UNION|SELECT|DROP|INSERT|UPDATE|DELETE|EXEC|TRUNCATE|CREATE|ALTER|--|/\*|\bpg_sleep\b|\bsleep\b)|[';]{2,}" # noqa
|
|
||||||
|
pattern = re.compile(
|
||||||
|
r"""
|
||||||
|
(?i) # case insensite
|
||||||
|
\b # word boundary
|
||||||
|
( # start of group for SQL keywords
|
||||||
|
OR # match SQL keyword OR
|
||||||
|
|AND
|
||||||
|
|UNION
|
||||||
|
|SELECT
|
||||||
|
|DROP
|
||||||
|
|INSERT
|
||||||
|
|UPDATE
|
||||||
|
|DELETE
|
||||||
|
|EXEC
|
||||||
|
|TRUNCATE
|
||||||
|
|CREATE
|
||||||
|
|ALTER
|
||||||
|
|-- # match SQL single-line comment
|
||||||
|
|/\* # match SQL multi-line comment
|
||||||
|
|\bpg_sleep\b # Match PostgreSQL 'pg_sleep' function
|
||||||
|
|
||||||
|
|\bsleep\b # Match SQL Server 'sleep' function
|
||||||
|
) # End SQL keywords and function group
|
||||||
|
| # OR operator to include an alternate pattern
|
||||||
|
[';]{2,} # Match two or more consecutive single quotes or semi-colons
|
||||||
|
""",
|
||||||
|
re.VERBOSE,
|
||||||
|
)
|
||||||
return bool(re.search(pattern, input_str))
|
return bool(re.search(pattern, input_str))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user