Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id: js-eval-code-injection
valid:
- const x = JSON.parse(input);
invalid:
- function run(userInput) { return eval(userInput); }
---
id: ts-eval-code-injection
valid:
- "const x: unknown = JSON.parse(input);"
invalid:
- "function run(userInput: string): unknown { return eval(userInput); }"
---
id: tsx-eval-code-injection
valid:
- "function R({input}: Props) { return <div>{JSON.parse(input)}</div>; }"
invalid:
- "function R({userInput}: Props) { return <div>{eval(userInput)}</div>; }"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
id: js-eval-code-injection
language: JavaScript
severity: error
message: "Direct eval() call — runtime code execution from a value (code injection, CWE-94)."
rule:
pattern: eval($$$ARGS)
---
id: ts-eval-code-injection
language: TypeScript
severity: error
message: "Direct eval() call — runtime code execution from a value (code injection, CWE-94)."
rule:
pattern: eval($$$ARGS)
---
id: tsx-eval-code-injection
language: Tsx
severity: error
message: "Direct eval() call — runtime code execution from a value (code injection, CWE-94)."
rule:
pattern: eval($$$ARGS)
7 changes: 7 additions & 0 deletions .github/scripts/sigilix_sarif_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ def _sanitize_run_results(run):
# guard keeps this collision-safe.
_RULE_CLASS_PATTERNS["gitleaks"] = [(re.compile(r".+"), "hardcoded-secret")]
_RULE_CLASS_PATTERNS["trufflehog"] = [(re.compile(r".+"), "hardcoded-secret")]
# Sigilix-owned ast-grep rules (deterministic floors re-run on the signed HEAD).
# Rule ids embed the class token, e.g. `ts-eval-code-injection`. Logic rules
# (await-for-each, async-array-predicate) match nothing → left unset.
_RULE_CLASS_PATTERNS["ast-grep"] = [
(re.compile(r"(?<![a-z])eval"), "code-injection"),
(re.compile(r"exec-shell|shell-interpolation|command[-_.]?inj"), "command-injection"),
]


def stamp_rule_classes(run, tool_id):
Expand Down
10 changes: 10 additions & 0 deletions .github/scripts/sigilix_sarif_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,16 @@ def test_collision_safe_unset_when_two_classes_match(self):
def test_stamps_eval_code_injection(self):
self.assertEqual(self._run("javascript.lang.security.detect-eval-with-expression"), "code-injection")

def test_ast_grep_eval_rule_maps_to_code_injection(self):
run = {"tool": {"driver": {}}, "results": [{"ruleId": "ts-eval-code-injection", "properties": {}}]}
stamp_rule_classes(run, "ast-grep")
self.assertEqual(run["results"][0]["properties"]["sigilixRuleClass"], "code-injection")

def test_ast_grep_logic_rule_left_unset(self):
run = {"tool": {"driver": {}}, "results": [{"ruleId": "ts-await-for-each-async-callback", "properties": {}}]}
stamp_rule_classes(run, "ast-grep")
self.assertNotIn("sigilixRuleClass", run["results"][0]["properties"])

def test_secret_scanners_map_to_hardcoded_secret(self):
for tool in ("gitleaks", "trufflehog"):
run = {"tool": {"driver": {}}, "results": [{"ruleId": "aws-access-token", "properties": {}}]}
Expand Down
Loading