fix(guardrails): probe map and fields verdicts fail closed, console rule sees public/, raw escape WARN, argv silent, plan validation
This commit is contained in:
1 parent
6c0006bce3
commit
c0fdbec3c1
8 files changed
+206
-44
No files matched your search
@@ -188,12 +188,16 @@ def _minified(project, path):
|
||||
for line in project.text(path).splitlines())
|
||||
|
||||
|
||||
def code_files(project, exts=SOURCE_EXTS):
|
||||
"""Hand-written source: no tests, fixtures, built dirs, minified files."""
|
||||
def code_files(project, exts=SOURCE_EXTS, keep_built=False):
|
||||
"""Hand-written source: no tests, fixtures, built dirs, minified files.
|
||||
|
||||
keep_built keeps public/, static/, www/ and assets/: they also hold the
|
||||
hand-written browser scripts of server-rendered stacks."""
|
||||
skipped = set() if keep_built else BUILT_SEGMENTS
|
||||
return [p for p in non_doc_files(project)
|
||||
if p.suffix.lower() in exts
|
||||
and not TEST_PATH.search(project.rel(p))
|
||||
and not set(project.segments(p)) & BUILT_SEGMENTS
|
||||
and not set(project.segments(p)) & skipped
|
||||
and not _minified(project, p)]
|
||||
|
||||
|
||||
|
||||
@@ -261,7 +261,8 @@ def _response_wide(project):
|
||||
|
||||
def check(project):
|
||||
files = code_files(project)
|
||||
found = _console_data(project, files) + _map_config(project)
|
||||
console = code_files(project, keep_built=True)
|
||||
found = _console_data(project, console) + _map_config(project)
|
||||
found += _map_files(project) + _hydrated(project, files)
|
||||
found += _markup_comments(project) + _data_attrs(project)
|
||||
found += _errors(project, files) + _debug(project, files)
|
||||
|
||||
@@ -49,7 +49,7 @@ RAW = {
|
||||
r"\.objects\.raw\(\s*(?![\s'\"`)])|\.extra\(\s*(?![\s'\"`)])"),
|
||||
(".rb",): re.compile(r"\.where\(\s*\"[^\"\n]{0,200}#\{"),
|
||||
}
|
||||
SQLA_TEXT = re.compile(r"\btext\s*\(\s*(?![\s'\"`)])")
|
||||
SQLA_TEXT = re.compile(r"(?<![.\w])text\s*\(\s*(?![\s'\"`)])")
|
||||
DYNAMIC_EXEC = re.compile(r"\bexecute\s+(?:'[^']*'|\w+)\s*\|\|", re.I)
|
||||
POSTGREST = re.compile(
|
||||
r"\.(?:or|filter|not|match|textSearch)\(\s*(?:`[^`\n]{0,200}\$\{"
|
||||
@@ -64,8 +64,8 @@ SHELL_DB = re.compile(
|
||||
r"\b(?:exec|execSync|spawn|spawnSync|system|popen|subprocess\.\w+"
|
||||
r"|os\.system|Command::new|shell_exec|passthru|proc_open)\s*\("
|
||||
r"[^\n]{0,300}?\b(?:psql|mysql|mysqldump|pg_dump|pg_restore|mongosh"
|
||||
r"|mongo|mongodump|redis-cli|sqlite3|clickhouse-client)\b[^\n]{0,300}?"
|
||||
r"(?:\$\{|\+\s*[\w$]|#\{|\{\w+\}|%s|\$[A-Za-z_])")
|
||||
r"|mongo|mongodump|redis-cli|sqlite3|clickhouse-client)\b(?![\"']\s*[,\]])"
|
||||
r"[^\n]{0,300}?(?:\$\{|\+\s*[\w$]|#\{|\{\w+\}|%s|\$[a-z_])")
|
||||
|
||||
|
||||
def applies(project):
|
||||
@@ -85,8 +85,9 @@ def _per_language(project, files, table, rule, message):
|
||||
|
||||
|
||||
def _raw_unsafe(project, files):
|
||||
rule = Rule(DOMAIN, "INJ-SQL-RAW-UNSAFE", "FAIL")
|
||||
msg = "raw SQL escape fed a non-literal: bind the values"
|
||||
rule = Rule(DOMAIN, "INJ-SQL-RAW-UNSAFE", "WARN")
|
||||
msg = ("raw SQL escape fed a non-literal: show it is a constant "
|
||||
"with bound values, else bind them")
|
||||
sqla = [p for p in _by_ext(files, (".py",))
|
||||
if "sqlalchemy" in project.text(p)]
|
||||
return (_per_language(project, files, RAW, rule, msg)
|
||||
|
||||
Reference in new issue
Block a user