CI: Pulse's own semgrep rules, with tests #63

Merged
jared merged 1 commits from semgrep-rules into main 2026-11-22 23:10:41 -05:00
Owner

Part of #45 (phase 4: custom semgrep rules).

.semgrep/pulse.yml runs in the Scan job alongside the registry packs. It has three rules:

Rule What it blocks
pulse-no-vm require('vm'), eval and new Function outside tests, so the workflow-condition bug (#62) can't come back
pulse-no-shell-in-server exec/execSync, or spawn with a shell, in server.js and lib/. Running commands is the worker's job
pulse-innerhtml-unescaped Member values (w.name, r.host, including inside template literals) inserted into innerHTML in public/assets without esc()/Pulse.esc(). Method names, comparisons, Set.has() and the fmt formatters don't count, because they aren't inserted values

Tests: .semgrep/pulse.js holds annotated cases (ruleid:/ok:), which CI checks with semgrep --test before the scan. A rule that stops matching therefore fails CI. I confirmed that flipping a single annotation makes the test fail.

Results: Pulse has no findings today. The innerHTML rule's first version flagged comparisons such as w.status === 'online'; I checked those by hand, and every inserted value in those lines already goes through esc().

Known limit: a value first copied into a plain variable isn't caught. The rule file says so, and that escaping should happen at the point of insertion.

🤖 Generated with Claude Code

Part of #45 (phase 4: custom semgrep rules). `.semgrep/pulse.yml` runs in the Scan job alongside the registry packs. It has three rules: | Rule | What it blocks | |---|---| | `pulse-no-vm` | `require('vm')`, `eval` and `new Function` outside tests, so the workflow-condition bug (#62) can't come back | | `pulse-no-shell-in-server` | `exec`/`execSync`, or `spawn` with a shell, in `server.js` and `lib/`. Running commands is the worker's job | | `pulse-innerhtml-unescaped` | Member values (`w.name`, `r.host`, including inside template literals) inserted into `innerHTML` in `public/assets` without `esc()`/`Pulse.esc()`. Method names, comparisons, `Set.has()` and the `fmt` formatters don't count, because they aren't inserted values | **Tests:** `.semgrep/pulse.js` holds annotated cases (`ruleid:`/`ok:`), which CI checks with `semgrep --test` before the scan. A rule that stops matching therefore fails CI. I confirmed that flipping a single annotation makes the test fail. **Results:** Pulse has no findings today. The `innerHTML` rule's first version flagged comparisons such as `w.status === 'online'`; I checked those by hand, and every inserted value in those lines already goes through `esc()`. **Known limit:** a value first copied into a plain variable isn't caught. The rule file says so, and that escaping should happen at the point of insertion. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-22 23:02:13 -05:00
CI: Pulse's own semgrep rules, with tests
CI / UI screenshots (before/after) (push) Skipped
CI / Test (jest) (push) Successful in 26s
CI / Security (npm audit) (push) Successful in 18s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m13s
CI / Integration (api) (push) Successful in 2m24s
CI / Lint (eslint) (pull_request) Successful in 42s
CI / Test (jest) (pull_request) Successful in 23s
CI / Security (npm audit) (pull_request) Successful in 8s
CI / UI (playwright) (push) Successful in 2m30s
CI / Integration (api) (pull_request) Successful in 1m54s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 1m37s
CI / UI screenshots (before/after) (pull_request) Successful in 6s
CI / Lint (eslint) (push) Successful in 18s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 1m59s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
bf7e91cc57
.semgrep/pulse.yml, run in the Scan job next to the registry packs:
- pulse-no-vm: no require('vm'), eval or new Function outside tests (the
  workflow-condition bug from #62 can't come back).
- pulse-no-shell-in-server: server.js and lib/ may not use exec/execSync
  or spawn with a shell; running commands is the worker's job.
- pulse-innerhtml-unescaped: member values (w.name, r.host) inserted into
  innerHTML in public/assets must go through esc()/Pulse.esc(); method
  names, comparisons, Set.has() and the fmt formatters are not values.

The rules' test cases (.semgrep/pulse.js) run first with semgrep --test,
so a rule that stops matching fails CI. Pulse has no findings today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared merged commit 72933df47a into main 2026-11-22 23:10:41 -05:00
jared deleted branch semgrep-rules 2026-11-22 23:10:42 -05:00
Sign in to join this conversation.