Skip to content

Close three security gaps and fix the libSQL paginate test - #61

Merged
abdullah-bl merged 1 commit into
mainfrom
fix/security-loose-ends
Nov 16, 2026
Merged

abdullah-bl merged 1 commit into
mainfrom
fix/security-loose-ends

Conversation

@abdullah-bl

Copy link
Copy Markdown
Owner

What changed

Apple sign-in nonce. The check accepted either sha256(rawNonce) or the token's nonce claim itself. The second made it prove nothing: anyone holding a token can read the claim out of it and send that. Only the hash is accepted now, which is what docs/auth.md already tells apps to do.

onebase upgrade verifies who built the binary. SHA256SUMS sits in the same release as the binary, so it only catches a damaged download. The upgrade now fetches the release's build attestation from GitHub and verifies it with sigstore: the signature, the certificate chain, the transparency log entry, and that the certificate was issued to .github/workflows/release.yml at the release's tag, for that exact file.

  • --no-verify skips the check, for machines that can't reach Sigstore or GitHub's API.
  • Releases before 0.3.0 were never signed; they install on their checksum alone and say so.

Uploaded files in backups are encrypted. With ONEBASE_SECRET_KEY set, only the snapshot was encrypted. Files are now stored as files/<id>.enc in the same format, and copies uploaded before the key was set are replaced on the next backup. Restore needs the key, and writes a file under a temporary name until it has decrypted whole.

libSQL paginate test. "clients can't ask paginate() for unbounded pages" inserted 8,194 documents in one mutation. libsql-server ends a transaction after 5 seconds, and over the network each insert is a round trip (6.7 s locally). The test seeds in chunks of 1,024 now. The driver also turns the raw TRANSACTION_TIMEOUT into a message that explains the limit.

For the reviewer

  • New dev dependency: sigstore (the package npm uses), bundled into the binary. 53 transitive packages, about 1 MB added to the binary. Chosen over a hand-written verifier because Sigstore rotates its keys, and pinned keys would eventually break onebase upgrade.
  • Behaviour change: an app that gives Apple the raw nonce instead of its hash will be refused. One test asserted the old behaviour and now asserts the opposite.
  • Behaviour change: the first backup after setting a key re-uploads every file, encrypted, and deletes the plain copies from the bucket.

Testing

  • Typecheck clean; bun test on SQLite: 579 pass, 3 skipped, 0 fail.
  • tests/engine.test.ts on libSQL (libsql-server in Docker): 34 pass. Not run on Postgres or MySQL locally.
  • Upgrade run for real against the v0.3.0 release, from source and as a compiled minified binary: the real binary is accepted, the same binary claimed under tag v0.3.1 is refused, and a digest GitHub has no attestation for is refused.

🤖 Generated with Claude Code

Apple sign-in accepted the token's own nonce claim as the nonce, so anyone
holding a token could pass the check. Only sha256(rawNonce) is accepted now.

onebase upgrade checked a binary against SHA256SUMS from the same release,
which says nothing about who built it. It now verifies the release's signed
build attestation with sigstore: the signature, the certificate chain, the
transparency log entry, and that the release workflow at the release's tag
built that exact file. --no-verify skips it; releases before 0.3.0 were
never signed and install on their checksum alone.

With ONEBASE_SECRET_KEY set, backups encrypted the snapshot but uploaded
files as they were. Files are encrypted the same way now, and copies
uploaded before the key was set are replaced.

The libSQL paginate test inserted 8,194 documents in one mutation, which
runs past libsql-server's 5 second transaction limit on a slow machine. It
seeds in several mutations now, and that timeout gets a message that says
what happened and what to do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@abdullah-bl
abdullah-bl merged commit 39cc805 into main Nov 16, 2026
1 check passed
@abdullah-bl
abdullah-bl deleted the fix/security-loose-ends branch November 16, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants