refactor(backend): standardize errors and simplify configuration and test setup
This commit is contained in:
1 parent
1535c19b8c
commit
138666a7bb
92 files changed
+3994
-210
No files matched your search
@@ -0,0 +1,25 @@
|
||||
rules:
|
||||
- id: frontend-no-dynamic-code
|
||||
languages: [javascript, typescript]
|
||||
message: Avoid eval and Function constructors. Use explicit functions and JSON.parse for data.
|
||||
severity: ERROR
|
||||
pattern-either:
|
||||
- pattern: eval(...)
|
||||
- pattern: new Function(...)
|
||||
- pattern: Function(...)
|
||||
|
||||
- id: frontend-no-document-write
|
||||
languages: [javascript, typescript]
|
||||
message: Avoid document.write and document.writeln. Render content through React.
|
||||
severity: ERROR
|
||||
pattern-either:
|
||||
- pattern: document.write(...)
|
||||
- pattern: document.writeln(...)
|
||||
|
||||
- id: frontend-no-inner-html-assignment
|
||||
languages: [javascript, typescript]
|
||||
message: Avoid direct innerHTML assignments. Use textContent or React rendering.
|
||||
severity: ERROR
|
||||
pattern-either:
|
||||
- pattern: $TARGET.innerHTML = $VALUE
|
||||
- pattern: $TARGET.innerHTML += $VALUE
|
||||
@@ -0,0 +1,55 @@
|
||||
rules:
|
||||
- id: python-no-dynamic-code
|
||||
languages: [python]
|
||||
message: Avoid eval and exec. Parse structured data instead of executing input.
|
||||
severity: ERROR
|
||||
pattern-either:
|
||||
- pattern: eval(...)
|
||||
- pattern: exec(...)
|
||||
|
||||
- id: python-safe-yaml-loader
|
||||
languages: [python]
|
||||
message: Use yaml.safe_load, yaml.safe_load_all, or an explicit SafeLoader or CSafeLoader.
|
||||
severity: ERROR
|
||||
patterns:
|
||||
- pattern-either:
|
||||
- pattern: yaml.load(...)
|
||||
- pattern: yaml.load_all(...)
|
||||
- pattern-not: yaml.load(..., Loader=yaml.SafeLoader, ...)
|
||||
- pattern-not: yaml.load(..., Loader=yaml.CSafeLoader, ...)
|
||||
- pattern-not: yaml.load_all(..., Loader=yaml.SafeLoader, ...)
|
||||
- pattern-not: yaml.load_all(..., Loader=yaml.CSafeLoader, ...)
|
||||
- pattern-not: yaml.load($DATA, yaml.SafeLoader)
|
||||
- pattern-not: yaml.load($DATA, yaml.CSafeLoader)
|
||||
- pattern-not: yaml.load_all($DATA, yaml.SafeLoader)
|
||||
- pattern-not: yaml.load_all($DATA, yaml.CSafeLoader)
|
||||
|
||||
- id: python-no-subprocess-shell
|
||||
languages: [python]
|
||||
message: Pass an argument list to subprocess without shell=True.
|
||||
severity: ERROR
|
||||
patterns:
|
||||
- pattern: subprocess.$CALL(..., shell=True, ...)
|
||||
- metavariable-regex:
|
||||
metavariable: $CALL
|
||||
regex: ^(run|Popen|call|check_call|check_output)$
|
||||
|
||||
- id: python-no-disabled-tls
|
||||
languages: [python]
|
||||
message: Keep TLS certificate verification enabled in requests and httpx.
|
||||
severity: ERROR
|
||||
patterns:
|
||||
- pattern-either:
|
||||
- pattern: requests.$CALL(..., verify=False, ...)
|
||||
- pattern: httpx.$CALL(..., verify=False, ...)
|
||||
- metavariable-regex:
|
||||
metavariable: $CALL
|
||||
regex: ^(request|get|post|put|patch|delete|head|options|stream|Client|AsyncClient)$
|
||||
|
||||
- id: python-no-pickle-load
|
||||
languages: [python]
|
||||
message: Avoid pickle deserialization for service data. Use a non-executable format such as JSON.
|
||||
severity: ERROR
|
||||
pattern-either:
|
||||
- pattern: pickle.load(...)
|
||||
- pattern: pickle.loads(...)
|
||||
@@ -0,0 +1,26 @@
|
||||
// Static scanner fixtures. Never execute this file.
|
||||
function dynamicCode(source: string) {
|
||||
// ruleid: frontend-no-dynamic-code
|
||||
eval(source);
|
||||
// ruleid: frontend-no-dynamic-code
|
||||
new Function(source);
|
||||
// ruleid: frontend-no-dynamic-code
|
||||
Function(source);
|
||||
// ok: frontend-no-dynamic-code
|
||||
JSON.parse(source);
|
||||
}
|
||||
|
||||
function renderText(node: HTMLElement, text: string) {
|
||||
// ruleid: frontend-no-document-write
|
||||
document.write(text);
|
||||
// ruleid: frontend-no-document-write
|
||||
document.writeln(text);
|
||||
// ruleid: frontend-no-inner-html-assignment
|
||||
node.innerHTML = text;
|
||||
// ruleid: frontend-no-inner-html-assignment
|
||||
node.innerHTML += text;
|
||||
// ok: frontend-no-inner-html-assignment, frontend-no-document-write
|
||||
node.textContent = text;
|
||||
// ok: frontend-no-inner-html-assignment
|
||||
return <span>{text}</span>;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# Static scanner fixtures. Never import or execute this file.
|
||||
import ast
|
||||
import json
|
||||
import pickle
|
||||
import subprocess
|
||||
|
||||
import httpx
|
||||
import requests
|
||||
import yaml
|
||||
from subprocess import run
|
||||
from yaml import SafeLoader
|
||||
|
||||
|
||||
def dynamic_code(source):
|
||||
# ruleid: python-no-dynamic-code
|
||||
eval(source)
|
||||
# ruleid: python-no-dynamic-code
|
||||
exec(source)
|
||||
# ok: python-no-dynamic-code
|
||||
ast.literal_eval(source)
|
||||
# ok: python-no-dynamic-code
|
||||
json.loads(source)
|
||||
|
||||
|
||||
def yaml_data(source):
|
||||
# ruleid: python-safe-yaml-loader
|
||||
yaml.load(source)
|
||||
# ruleid: python-safe-yaml-loader
|
||||
yaml.load(source, Loader=yaml.Loader)
|
||||
# ruleid: python-safe-yaml-loader
|
||||
yaml.load_all(source, Loader=yaml.UnsafeLoader)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.safe_load(source)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.safe_load_all(source)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.load(source, Loader=yaml.SafeLoader)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.load(source, Loader=SafeLoader)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.load(source, yaml.CSafeLoader)
|
||||
# ok: python-safe-yaml-loader
|
||||
yaml.load_all(source, Loader=yaml.SafeLoader)
|
||||
|
||||
|
||||
def processes(command):
|
||||
# ruleid: python-no-subprocess-shell
|
||||
subprocess.run(command, shell=True, check=True)
|
||||
# ruleid: python-no-subprocess-shell
|
||||
subprocess.Popen(command, shell=True)
|
||||
# ruleid: python-no-subprocess-shell
|
||||
run(command, shell=True)
|
||||
# ok: python-no-subprocess-shell
|
||||
subprocess.run(["tool", command], check=True)
|
||||
# ok: python-no-subprocess-shell
|
||||
subprocess.run(["tool", command], shell=False, check=True)
|
||||
|
||||
|
||||
def http_clients(url):
|
||||
# ruleid: python-no-disabled-tls
|
||||
requests.get(url, verify=False, timeout=5)
|
||||
# ruleid: python-no-disabled-tls
|
||||
httpx.post(url, verify=False)
|
||||
# ruleid: python-no-disabled-tls
|
||||
httpx.Client(verify=False)
|
||||
# ruleid: python-no-disabled-tls
|
||||
httpx.AsyncClient(verify=False)
|
||||
# ok: python-no-disabled-tls
|
||||
requests.get(url, verify=True, timeout=5)
|
||||
# ok: python-no-disabled-tls
|
||||
httpx.Client()
|
||||
# ok: python-no-disabled-tls
|
||||
httpx.get(url, verify="certificates.pem")
|
||||
|
||||
|
||||
def serialized_data(source, file):
|
||||
# ruleid: python-no-pickle-load
|
||||
pickle.loads(source)
|
||||
# ruleid: python-no-pickle-load
|
||||
pickle.load(file)
|
||||
# ok: python-no-pickle-load
|
||||
json.loads(source)
|
||||
Reference in new issue
Block a user