Add jetc --lint-sql to find <sql> that pastes values (phase 2)

Implements phase 2 of docs/design-sql-bound-parameters.md. jetc --lint-sql
[--strict] <file|dir>... lists each <sql> whose statement contains a $[...]
or #[...] reference instead of a <bind>, with file:line and where each value
comes from. Row values ($[.col], $[session.col], $[?N], $[#]) are only
reported with --strict. References in <bind>, <if>, <set> and the other
attribute-only tags, <comment> and |> <| are skipped. A custom tag defined
as <sql><container></sql> (barant.com's <showtable>) is checked at each use.
Exit status is 0 for none found, 1 for findings, 2 for an unreadable path.

- jetc/JetLint.*: the scanner; jetc.cpp: the option
- build scripts and runbindtests.sh: link JetLint.cpp
- tests/runlinttests.sh and tests/lintsql/: fixtures and expected output
- docs: worklist for the local copies of both sites, design doc status,
  manual note on the lint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-20 20:29:28 -08:00
1 parent fd81bb877f
commit 2847ce5fa7
22 files changed
+667 -10

No files matched your search

+16 -3
View File
@@ -1,6 +1,6 @@
# Design: bound parameters for `<sql>`
**Status:** draft for review · **Author:** Brad Arant (drafted with Claude) · **Date:** 2026-10-23
**Status:** phases 1 and 2 implemented (2026-11-20) · **Author:** Brad Arant (drafted with Claude) · **Date:** 2026-10-23
**Applies to:** JetCore (`__sql`, `__mysql`, `Tag.cpp` tag dispatch, `jetc` parser/codegen)
## 1. The problem
@@ -184,6 +184,19 @@ Once pages are migrated, make the unsafe form an error instead of a habit:
1. **`jetc --lint-sql`** - lists every `<sql>` whose body contains `$[...]`
other than `$[.column]` (row values from an outer query), with file:line.
This is the migration worklist (§8) and a CI check.
As implemented (`jetc/JetLint.cpp`): `jetc --lint-sql [--strict] <file|dir>...`
scans every file under the given paths. It reports `$[...]` and local
`#[...]` references, with the kind of each (`global`, `cgi`, `session`,
`env`, `keyword`, `local`). Row values (`$[.col]`, `$[session.col]`,
`$[?N]`, `$[#]`, `$[?#]`) are not reported unless `--strict` is given.
References in the attributes of `<bind>`, `<if>`, `<else>`, `<ifrow>`,
`<while>`, `<whilerow>`, `<until>`, `<for>` and `<set>` are not reported,
since those never become statement text; nor is anything inside
`<comment>` or `|> <|`. A custom tag defined as `<sql ...><container></sql>`
(barant.com's `<showtable>`) takes its statement from the caller's content,
so each use of it is checked like an `<sql>`. Exit status: 0 nothing found,
1 findings, 2 a path could not be read. Tests: `tests/runlinttests.sh`.
2. **Per-site strict mode** - an APIServer site setting
`"sqlInterpolation": "warn" | "error"`. In `error` mode `<sql>` refuses to run
if its body substituted any `$[...]` except `$[.column]`; `warn` logs it.
@@ -196,8 +209,8 @@ Once pages are migrated, make the unsafe form an error instead of a habit:
| Phase | What | Notes |
|---|---|---|
| 1 | Implement `<bind>`, escaping, utf8mb4 pinning, tests | JetCore only; no page changes |
| 2 | `jetc --lint-sql`; run on both sites | produces the worklist (≈200 queries) |
| 1 | Implement `<bind>`, escaping, utf8mb4 pinning, tests | JetCore only; no page changes. Done 2026-11-20 |
| 2 | `jetc --lint-sql`; run on both sites | produces the worklist (≈200 queries). Done 2026-11-20 on the local copies: see [sql-lint-worklist.md](sql-lint-worklist.md) |
| 3 | Convert the high-risk pages first | login/signup/password reset, cart/checkout/payment (`pp.jet`), admin procs, ClockPlanet `mobile_api.jet` and auth |
| 4 | Convert the rest; turn on `warn` | logs show anything missed |
| 5 | Switch both sites to `error` | unsafe queries can no longer ship |