Repository navigation
Keep the functions that run code out of the schema - #13
marcobambini merged 2 commits into
Conversation
js_eval(), js_create_*(), js_load_text(), js_load_blob(), js_init_table()
and the js_set_* functions were registered without SQLITE_DIRECTONLY, so
a view, trigger, CHECK constraint or generated column could call them.
With PRAGMA trusted_schema ON, the default of the SQLite library (the
sqlite3 shell turns it off), a database from an untrusted source could
run JavaScript or read files just by being queried:
`CREATE VIEW v AS SELECT js_eval('...')`.
Register every function but js_version() with SQLITE_DIRECTONLY, so only
top-level SQL can call them. The functions created with js_create_* are
unchanged, so they still work in views, triggers and indexes. The flag
is computed from the function's name rather than from a table that
parallels the function list, so a function added later gets it without
a matching edit.
Add a Direct only test: every function but js_version() has the flag in
function_list; with trusted_schema ON, a view, a trigger and a
generated column cannot call js_eval() or js_load_text(), a top-level
statement can, and a view can still use js_version() and a function made
with js_create_scalar().
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
SQLite trusts the TEMP schema, since only the connection itself can make it, so SQLITE_DIRECTONLY does not keep js_eval() and the others out of TEMP views and triggers. Say so. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
…ntents PR #13 added the section but not its table-of-contents entry.
|
Merged into Verified locally on macOS/arm64: universal build with no new warnings, full suite green, clean under ASan + UBSan. The new Direct only test is load-bearing — with Computing the flag from the function name rather than a parallel table is the right call: a function added later gets it without a matching edit. One small thing I fixed on merge (1c6f1c8): the new top-level Functions in the Schema section was missing from the README's table of contents, so I added the entry. Worth stating plainly for anyone reading later: this is a deliberate breaking change for a database that already calls Thanks, good catch and a thorough test. |
js_eval(),js_create_*(),js_load_text(),js_load_blob(),js_init_table()andjs_set_max_stack_size()are registered withoutSQLITE_DIRECTONLY, so a view, trigger, CHECK constraint or generated column can call them. WithPRAGMA trusted_schemaon, which is the SQLite library's default (thesqlite3shell turns it off), a database from an untrusted source runs JavaScript or reads files as soon as it is queried:This registers every function but
js_version()withSQLITE_DIRECTONLY, so only top-level SQL can call them. The flag is computed from the function's name rather than from a table that parallels the function list, so a function added later gets it without a matching edit. The functions made withjs_create_*are unchanged and still work in views, triggers and indexes. The README explains this in a new "Functions in the Schema" section, with a note thatjs_init_table(1)runs the JavaScript a database stores.Test: a new Direct only test checks that every function but
js_version()has the flag infunction_listand, withtrusted_schemaon, that a view, a trigger and a generated column cannot calljs_eval()orjs_load_text(), that a top-level statement can, and that a view can still usejs_version()and a function made withjs_create_scalar().make testpasses on x86_64 Linux, also under ASan and UBSan.These are six separate pull requests, #11 to #16, so each can be taken or declined on its own; only #15 depends on another (#14). They add tests at the same places in
test/main.c, and #11 and #12 both add code just aboveglobaljs_init(), so those merged later will need a small rebase, which we will do.This pull request originated with AI. Claude, Anthropic's AI model, wrote the code, the tests and this description while packaging sqlite-js for Code on the Go, App Dev For All's Android IDE, which ships sqlite-js with this change. Contact: [email protected]
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Update, 2026-11-12. The README now says that TEMP views and triggers can still call these functions, since SQLite trusts the TEMP schema (72db0d2).