67 lines
2.7 KiB
YAML
67 lines
2.7 KiB
YAML
# Pulse's own semgrep rules, run by the Scan job. Test cases: .semgrep/pulse.js
|
|||
|
|
# (semgrep --test --config .semgrep/pulse.yml .semgrep/pulse.js).
|
||
|
|
# The innerHTML rule checks member accesses (w.name, r.host); a value first copied into
|
||
|
|
# a plain variable is not caught, so keep escaping at the point of insertion.
|
||
|
|
rules:
|
||
|
|
- id: pulse-no-vm
|
||
|
|
message: >-
|
||
|
|
Node's vm module is not a sandbox: code it runs can reach the server process.
|
||
|
|
Workflow conditions go through lib/condition.js; don't evaluate user input with vm.
|
||
|
|
severity: ERROR
|
||
|
|
languages: [javascript]
|
||
|
|
paths:
|
||
|
|
exclude: [tests/]
|
||
|
|
pattern-either:
|
||
|
|
- pattern: require('vm')
|
||
|
|
- pattern: new Function(...)
|
||
|
|
- pattern: eval(...)
|
||
|
|
|
||
|
|
- id: pulse-no-shell-in-server
|
||
|
|
message: >-
|
||
|
|
The server must not run shell commands: use execFile/execFileSync with an argument
|
||
|
|
list. (Running commands is the worker's job, over the authenticated WebSocket.)
|
||
|
|
severity: ERROR
|
||
|
|
languages: [javascript]
|
||
|
|
paths:
|
||
|
|
include: [server.js, lib/]
|
||
|
|
pattern-either:
|
||
|
|
- pattern: require('child_process').exec(...)
|
||
|
|
- pattern: require('child_process').execSync(...)
|
||
|
|
- pattern: "require('child_process').spawn(..., {..., shell: true, ...})"
|
||
|
|
- pattern: |
|
||
|
|
const { ..., exec, ... } = require('child_process');
|
||
|
|
- pattern: |
|
||
|
|
const { ..., execSync, ... } = require('child_process');
|
||
|
|
|
||
|
|
- id: pulse-innerhtml-unescaped
|
||
|
|
message: >-
|
||
|
|
Value inserted into innerHTML without escaping. Wrap it in esc() / Pulse.esc(), or
|
||
|
|
build the element with textContent.
|
||
|
|
severity: ERROR
|
||
|
|
languages: [javascript]
|
||
|
|
paths:
|
||
|
|
include: [public/assets/]
|
||
|
|
patterns:
|
||
|
|
- pattern-either:
|
||
|
|
- pattern-inside: $EL.innerHTML = $RHS
|
||
|
|
- pattern-inside: $EL.innerHTML += $RHS
|
||
|
|
- pattern: $OBJ.$PROP
|
||
|
|
- pattern-not: $X.innerHTML
|
||
|
|
- pattern-not-inside: esc(...)
|
||
|
|
- pattern-not-inside: $NS.esc(...)
|
||
|
|
- pattern-not-inside: escHtml(...)
|
||
|
|
- pattern-not-inside: $NS.escHtml(...)
|
||
|
|
- pattern-not-inside: encodeURIComponent(...)
|
||
|
|
- pattern-not-inside: String(...)
|
||
|
|
# The member as a method name (rows.map(...), Pulse.fmt.status(...)): not a value.
|
||
|
|
- pattern-not-inside: $OBJ.$PROP(...)
|
||
|
|
# Inputs to helpers whose result is not the raw value: Set.has() gives a boolean,
|
||
|
|
# the Pulse.fmt formatters give class names or formatted dates.
|
||
|
|
- pattern-not-inside: $SET.has(...)
|
||
|
|
- pattern-not-inside: $NS.fmt.$FN(...)
|
||
|
|
- pattern-not-inside: fmt.$FN(...)
|
||
|
|
# Values only compared (to pick a class or a symbol) are not inserted.
|
||
|
|
- pattern-not-inside: $A === $B
|
||
|
|
- pattern-not-inside: $A !== $B
|
||
|
|
- pattern-not-inside: $A == $B
|
||
|
|
- pattern-not-inside: $A != $B
|