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

BIN
View File
Binary file not shown.
+10
View File
@@ -443,6 +443,16 @@ outside an sql tag, a bind with no value, an unknown type, and a
statement whose number of ? placeholders differs from its number of
bind tags. The error text never contains the bound value itself.
To find the sql tags that still write values into the statement text,
run the jet compiler's lint over a site:
\begin{verbatim}
jetc --lint-sql /path/to/site
\end{verbatim}
It prints the file and line of each one, with the variables it uses.
Add \texttt{-{}-strict} to include values from the rows of an earlier query.
\section{call}
Use the call tag to evoke an executable file from a jet script.
+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 |
+166
View File
@@ -0,0 +1,166 @@
# `<sql>` migration worklist
Output of `jetc --lint-sql` (phase 2 of [design-sql-bound-parameters.md](design-sql-bound-parameters.md)),
generated 2026-11-20 from the copies of the two sites in `~/Development`.
Each line is a `<sql>` (or a use of a custom tag that wraps one, such as
barant.com's `<showtable>`) whose statement pastes in a variable instead of
using `<bind>`. The kind in brackets is where the value comes from: `global`
includes request parameters, `cgi` is a POST body field, `session` is
`$[@name]`, `local` is `#[name]`.
These local copies are not the whole of either live site. ClockPlanet in
particular has only billing and a few site pages here (no `mobile_api.jet`), so
rerun the lint on the live site trees for the full list:
```
jetc --lint-sql /path/to/site
```
Phase 3 starts with login/signup/password reset, cart/checkout/payment and
admin procs (see the design doc §8).
## barant.com (`JetCore/jetc/barant-site`)
```
./src/SIPPHONE.tag:178: <sql> pastes $[_login_id] (global)
./src/account-info.subpage:3: <sql> pastes $[_login_id] (global)
./src/account-info.subpage:14: <sql> pastes $[_login_id] (global)
./src/account-info.subpage:28: <sql> pastes $[_login_id] (global)
./src/account-info.subpage:54: <sql> pastes $[_login_id] (global)
./src/account-invoices.subpage:3: <sql> pastes $[@_invoice_id] (session)
./src/account-invoices.subpage:14: <showtable> (wraps sql) pastes $[_login_id] (global)
./src/accountconfirm.page:14: <sql> pastes $[uuid] (global)
./src/accountconfirm.page:15: <sql> pastes $[uuid] (global)
./src/accountconfirm.page:16: <sql> pastes $[id] (global)
./src/add_track.page:10: <sql> pastes $[collection_id] (global)
./src/add_track.proc:5: <sql> pastes $[login_id] (global), $[collection_id] (global), $[name] (global), $[artist] (global), $[description] (global), $[price] (global), $[filedata_binary] (global)
./src/addtasknote.page:12: <sql> pastes $[_task_id] (global)
./src/addtasknote.proc:3: <sql> pastes $[_task_id] (global), $[_login_id] (global), $[noteb] (global), $[task_status_id] (global)
./src/addtocart.proc:1: <sql> pastes $[_session_id] (global), $[sku] (global)
./src/addtocart.proc:4: <sql> pastes $[_session_id] (global), $[sku] (global), $[qty] (global)
./src/admin-mailaccounts.subpage:19: <sql> pastes $[@_login_id] (session)
./src/barant.tag:70: <sql> pastes #[table] (local), #[where] (local), #[sortfield] (local)
./src/cart.menu:2: <sql> pastes $[_session_id] (global)
./src/cart.page:17: <sql> pastes $[_session_id] (global)
./src/cart.page:34: <sql> pastes $[_session_id] (global)
./src/cart.page:67: <sql> pastes $[_session_id] (global)
./src/changeprojecticon.proc:3: <sql> pastes $[datax] (global)
./src/changeprojecticon.proc:9: <sql> pastes $[image_id] (global), $[_project_id] (global)
./src/checkout.page:65: <sql> pastes $[_session_id] (global)
./src/checkout.page:75: <sql> pastes $[_session_id] (global)
./src/copy_invoice.jet:14: <sql> pastes $[source_invoice_id] (global)
./src/copy_invoice.jet:19: <sql> pastes $[new_invoice_id] (global), $[source_invoice_id] (global)
./src/create_invoice.jet:14: <sql> pastes $[user_id] (global)
./src/createaccount.proc:17: <sql> pastes $[email:0] (global)
./src/createaccount.proc:28: <sql> pastes $[name] (global), $[company_name] (global), $[email] (global), $[password] (global)
./src/createaccount.proc:46: <sql> pastes $[id] (global), $[link] (global)
./src/createproject.proc:2: <sql> pastes $[_login_id] (global), $[text] (global), $[description] (global)
./src/createreleasetarget.proc:4: <sql> pastes $[_project_id] (global), $[release] (global), $[descriptionx] (global)
./src/createrequest.proc:4: <sql> pastes $[_project_id] (global), $[_login_id] (global), $[priority] (global), $[release_id] (global), $[textx] (global), $[descriptionx] (global)
./src/createtask.proc:5: <sql> pastes $[_request_id] (global), $[_login_id] (global), $[textx] (global), $[descriptionx] (global)
./src/deleterequest.proc:3: <sql> pastes $[_request_id] (global)
./src/documents.jet:2: <sql> pastes $[id] (global), $[@_login_id] (session)
./src/documents_api.jet:17: <sql> pastes $[@_login_id] (session), $[name] (global)
./src/documents_api.jet:29: <sql> pastes $[id] (global), $[@_login_id] (session)
./src/documents_api.jet:31: <sql> pastes $[id] (global), $[@_login_id] (session)
./src/documents_api.jet:43: <sql> pastes $[@_login_id] (session)
./src/documents_delete.proc:4: <sql> pastes $[delete_id] (global), $[@_login_id] (session)
./src/documents_delete.proc:6: <sql> pastes $[delete_id] (global), $[@_login_id] (session)
./src/documents_upload.proc:4: <sql> pastes $[@_login_id] (session), $[name] (global)
./src/editinvoice.page:180: <sql> pastes $[@_invoice_id] (session)
./src/editinvoice.page:234: <sql> pastes $[@_invoice_id] (session)
./src/editproduct.page:8: <sql> pastes $[_product_sku] (global)
./src/editrequest.page:7: <sql> pastes $[_request_id] (global)
./src/edittask.page:12: <sql> pastes $[_task_id] (global)
./src/invoice.method:1: <sql> pastes $[@_invoice_id] (session)
./src/invoice.method:28: <sql> pastes $[@_invoice_id] (session)
./src/invoice.method:51: <sql> pastes $[@_invoice_id] (session)
./src/invoices.menu:2: <sql> pastes $[_user_id] (global)
./src/login.method:1: <sql> pastes $[login_email] (global), $[login_password] (global)
./src/login.method:16: <sql> pastes $[login_id] (global)
./src/login.method:17: <sql> pastes $[login_id] (global)
./src/mailaccounts.jet:25: <sql> pastes $[@_login_id] (session), $[mail_email] (global), $[mail_host] (global), $[mail_password] (global)
./src/mailaccounts.jet:38: <sql> pastes $[account_id] (global), $[@_login_id] (session)
./src/make_invoice.method:5: <sql> pastes $[_session_id] (global)
./src/make_invoice.method:47: <sql> pastes $[_login_id] (global), $[total] (global)
./src/make_invoice.method:62: <sql> pastes $[invoice_id] (global), $[total] (global), $[card_brand] (global), $[last_4_digits] (global), $[exp_month] (global), $[exp_year] (global), $[payment_id] (global), $[tranonce] (global)
./src/make_invoice.method:74: <sql> pastes $[_session_id] (global)
./src/make_invoice.method:81: <sql> pastes $[invoice_id] (global)
./src/make_invoice.method:96: <sql> pastes $[license] (global)
./src/make_invoice.method:97: <sql> pastes $[_login_id] (global), $[invoice_id] (global), $[license] (global), $[key] (global)
./src/make_invoice.method:110: <sql> pastes $[_session_id] (global)
./src/memberhometemplate.temp:25: <sql> pastes $[login_id] (global)
./src/menu.bar:18: <sql> pastes $[_session_id] (global)
./src/musicianhome.page:13: <sql> pastes $[login_id] (global)
./src/musicianhome.page:35: <sql> pastes $[login_id] (global)
./src/myprojects.page:15: <showtable> (wraps sql) pastes $[_login_id] (global)
./src/myworklist.page:10: <showtable> (wraps sql) pastes $[_login_id] (global)
./src/newcollection.proc:11: <sql> pastes $[login_id] (global), $[name] (global), $[artist] (global), $[description] (global), $[price] (global)
./src/payinvoice.page:7: <sql> pastes $[_invoice_id] (global)
./src/phones.section:1: <sql> pastes $[@_login_id] (session)
./src/phones.section:9: <showtable> (wraps sql) pastes $[@_login_id] (session)
./src/processorder.proc:4: <sql> pastes $[_login_id] (global)
./src/processorder.proc:7: <sql> pastes $[_session_id] (global)
./src/processorder.proc:12: <sql> pastes $[invoice_id] (global)
./src/processorder.proc:27: <sql> pastes $[license] (global)
./src/processorder.proc:28: <sql> pastes $[_login_id] (global), $[invoice_id] (global), $[license] (global), $[key] (global)
./src/processorder.proc:41: <sql> pastes $[_session_id] (global)
./src/project.page:16: <sql> pastes $[_project_id] (global)
./src/project.page:37: <showtable> (wraps sql) pastes $[_project_id] (global)
./src/project.tag:3: <sql> pastes $[_project_id] (global)
./src/projects.menu:1: <sql> pastes $[_login_id] (global)
./src/projman.bar:15: <sql> pastes $[_session_id] (global)
./src/registermusician.proc:2: <sql> pastes $[login_id] (global)
./src/removecartitem.proc:1: <sql> pastes $[_session_id] (global), $[sku] (global)
./src/removefromcart.proc:1: <sql> pastes $[_session_id] (global)
./src/request.page:12: <sql> pastes $[_request_id] (global)
./src/request.page:43: <showtable> (wraps sql) pastes $[_request_id] (global)
./src/selectproject.proc:2: <sql> pastes $[project_id] (global)
./src/selecttask.proc:2: <sql> pastes $[task_id] (global)
./src/send_invoice_email.method:5: <sql> pastes $[_send_invoice_id] (global)
./src/task.page:12: <sql> pastes $[_request_id] (global)
./src/task.page:35: <sql> pastes $[_task_id] (global)
./src/taskassignresource.page:15: <sql> pastes $[_task_id] (global)
./src/taskassignresource.proc:5: <sql> pastes $[_task_id] (global), $[user_id] (global), $[estimate_hours] (global)
./src/update_invoice.proc:3: <sql> pastes $[@_invoice_id] (session)
./src/update_invoice.proc:5: <sql> pastes $[@_invoice_id] (session), $[sku$[ix]] (global), $[quantity$[ix]] (global), $[description$[ix]] (global), $[textarea$[ix]] (global), $[price$[ix]] (global), $[total$[ix]] (global), $[tax_amount$[ix]] (global), $[type$[ix]] (global)
./src/update_invoice.proc:8: <sql> pastes $[invoice_total] (global), $[user_id] (global), $[@_invoice_id] (session)
./src/update_product.proc:2: <sql> pastes $[type] (global), $[description] (global), $[text] (global), $[price] (global), $[image] (global), $[_product_sku] (global)
./src/updatecartqty.proc:2: <sql> pastes $[_session_id] (global), $[sku] (global)
./src/updatecartqty.proc:4: <sql> pastes $[qty] (global), $[_session_id] (global), $[sku] (global)
./src/updaterequest.proc:6: <sql> pastes $[textx] (global), $[descriptionx] (global), $[priority] (global), $[owner_id] (global), $[release_id] (global), $[_request_id] (global)
./src/upload_modular1_1_preset.proc:5: <sql> pastes $[title] (global), $[textx] (global), $[preset_datax] (global), $[audio_samplex] (global)
lint-sql: 108 of 139 <sql> blocks (and uses of tags that wrap <sql>) paste values into the statement, in 64 of 76 files (global 174, local 3, session 22)
```
## ClockPlanet (`~/Development/ClockPlanet`)
```
./billing/account.page:9: <sql> pastes $[_acct_bid] (global)
./billing/account.page:46: <sql> pastes $[_acct_bid] (global), $[_acct_req] (global)
./billing/account.page:157: <sql> pastes $[_acct_bid] (global)
./billing/account.page:159: <sql> pastes $[_acct_bid] (global)
./billing/billing_api.jet:28: <sql> pastes $[_mail_key] (global)
./billing/billing_api.jet:50: <sql> pastes $[_mail_key] (global)
./billing/billing_api.jet:53: <sql> pastes $[_notice_business] (global)
./billing/dobilling_pay.proc:16: <sql> pastes $[_bp_bid] (global)
./billing/dobilling_settings.proc:7: <sql> pastes $[_bs_bid] (global), $[_bs_low] (global), $[_bs_rep] (global)
./billing/dobilling_settings.proc:14: <sql> pastes $[_bs_low] (global), $[_bs_rep] (global), $[_bs_bid] (global)
./billing/doemployee_add.proc:6: <sql> pastes $[@_login_business_id] (session), $[name] (global), $[role] (global), $[phone] (global), $[mode] (global), $[invitecode] (global)
./billing/invoice.method:1: <sql> pastes $[_cp_invoice_id] (global)
./billing/invoice.method:33: <sql> pastes $[_cp_invoice_id] (global)
./billing/invoice.method:52: <sql> pastes $[_cp_invoice_id] (global)
./billing/send_invoice_email.method:3: <sql> pastes $[_send_invoice_id] (global)
./site-live/billing-current.txt:10: <sql> pastes $[_acct_bid] (global)
./site-live/billing-current.txt:49: <sql> pastes $[_acct_bid] (global), $[_acct_req] (global)
./site-live/billing-current.txt:114: <sql> pastes $[_acct_bid] (global)
./site-live/billing-current.txt:116: <sql> pastes $[_acct_bid] (global)
./site-live/billing-current.txt:252: <sql> pastes $[_mail_key] (global)
./site-live/billing-current.txt:272: <sql> pastes $[_mail_key] (global)
./site-live/billing-current.txt:275: <sql> pastes $[_notice_business] (global)
./site-live/billing-current.txt:313: <sql> pastes $[@_login_business_id] (session), $[name] (global), $[role] (global), $[phone] (global), $[mode] (global), $[invitecode] (global)
./site-live/sites.page:12: <sql> pastes $[@_login_business_id] (session)
./site-live/sites.page:32: <sql> pastes $[@_login_business_id] (session)
./site-live/sites.page:36: <sql> pastes $[@_login_business_id] (session)
lint-sql: 26 of 28 <sql> blocks paste values into the statement, in 9 of 10 files (global 37, session 5)
```