Repository navigation
Description
Hi @lovasoa, please take a look at this one.
SQL file that shows the bug
select 'cookie' as component, 'session' as name, 'abc123' as value;
select 'text' as component, 'ok' as contents;Requested with:
curl -sD - -o /dev/null http://localhost:8080/test_cookie.sql | grep -i set-cookieWhat happens
set-cookie: session=abc123; HttpOnly; SameSite=Strict; Secure; Path=/
The HttpOnly attribute is added even though http_only was not specified. In the browser console
afterwards:
document.cookie // "session" is not there
document.cookie = 'session=x; path=/' // silently ignoredSo the cookie is neither readable nor writable from client-side JavaScript.
What you expected
No HttpOnly attribute, as the documentation promises:
Whether the cookie should only be accessible via HTTP and not via client-side scripts. If not
specified, the cookie will be accessible via both HTTP and client-side scripts.
Database
SQLite (3.x, embedded)
SQLPage version
v0.48.0 (official lovasoa/sqlpage:latest Docker image)
Last SQLPage version where it worked
I don't know when the docs and the code diverged; the behaviour is already pinned by tests in v0.48.0.
Anything else
Where the code and the docs disagree
src/render.rs:233-234 — HttpOnly unless explicitly disabled:
let http_only = obj.get("http_only");
cookie.set_http_only(http_only != Some(&json!(false)) && http_only != Some(&json!(0)));tests/cookies/mod.rs:16 — cookies_are_http_only_secure_and_same_site_strict_by_default() asserts
HttpOnly in the default header, so the runtime behaviour looks deliberate (the test came from #1429)
and only the documentation is stale.
The stale text lives in
examples/official-site/sqlpage/migrations/05_cookie.sql:68.
Why it matters
I use the component to persist a UI preference (light/dark theme) that is rendered server-side, and —
following the docs — expected JavaScript to be able to read and update the same cookie. Instead:
document.cookienever sees it, so client-side code cannot detect the stored preference.- Writes from JavaScript are dropped (RFC 6265bis §5.7, storage model: a cookie received from a
non-HTTP API is ignored when anHttpOnlycookie with the same name/domain/path already exists).
That combination produces silent failures. On my site, a small client-side fallback that
initialises the preference on the first visit could never see — nor write — the cookie it was supposed
to create, so it re-ran on every page load and reloaded the page each time. Nothing in the logs,
nothing visible on the page; finding the cause required reading render.rs.
Suggested fix
Update the parameter description in examples/official-site/sqlpage/migrations/05_cookie.sql (and
therefore the generated docs table) to match the implementation, e.g.:
Whether the cookie should only be accessible via HTTP and not via client-side scripts.
Defaults to TRUE; set it tofalse(or0) to let client-side JavaScript read and modify the cookie.
Two adjacent details are also worth documenting while touching that entry:
http_onlyandsecureaccept0as well asfalse(seetests/cookies/set_cookie_opt_out.sql),
which is useful on MySQL/MSSQL/Oracle, where there is no boolean literal.pathdefaults to/when omitted (src/render.rs:209-213); the docs only say "the cookie will be
sent for all paths", which is equivalent but less explicit.
Note: the docs site seeds this text through a migration, so the fix needs a new migration file
(05_cookie.sql is already applied) using ON CONFLICT ... DO UPDATE, otherwise the change is
silently skipped.
If instead the intent is that cookies should be JS-readable by default, then the default in
src/render.rs and the assertion in tests/cookies/mod.rs would have to change too — but given that
#1429 deliberately pinned the secure defaults, correcting the documentation looks like the right fix.
Workaround for other users hitting this
select 'cookie' as component,
'lightdarkstatus' as name,
'dark' as value,
false as http_only, -- let JavaScript read and write it
'lax' as same_site; -- 'strict' (the default) drops the cookie on cross-site navigation
Activity
lovasoa commentedon Nov 13, 2026
thanks for letting me know, I updated the docs
Update 'http_only' cookie description (sqlpage#1601)