Skip to content

feat: context binding, contextFallback, stats().unboundReads (0.6.0) - #11

Merged
mpointer merged 2 commits into
mainfrom
feat/context-binding
Oct 28, 2026
Merged

mpointer merged 2 commits into
mainfrom
feat/context-binding

Conversation

@mpointer

Copy link
Copy Markdown
Owner

Implements docs/design/context-binding.md and releases with the already-merged plaintext: "reject" mode as 0.6.0.

Summary

  • Context binding: seal/unseal take an optional context (string or parts like ["users", "email"]), bound into the GCM AAD as version || 0x00 || context. Parts are NUL-joined; empty or NUL-containing parts are rejected; "" and [] mean no context. No token-format change.
  • API (TS): the second argument of seal/unseal/maybeSeal/maybeUnseal is a namespace string (unchanged) or { namespace, context }. Python adds a context= keyword.
  • Row helpers: spec accepts context(field, row).
  • contextFallback / context_fallback: on an auth failure under a context, retry without it, warn once per namespace, count in stats().unboundReads (Python stats()["unbound_reads"]). A bound token still can't move: fallback only drops the context.
  • Rule for legacy formats: they have no AAD, so with a context they read only under fallback and count as unbound. That keeps unboundReads == 0 meaning every read was bound.
  • SQLAlchemy: SealedText/SealedString/SealedJSON take a column-level context, included in the cache key.
  • Docs: README section "Bind tokens to their column" (table+column by default, row ids as opt-in), Python README, CHANGELOG 0.6.0 (dated), design note marked implemented.
  • Version 0.6.0 in package.json, package-lock.json, python/pyproject.toml.

Verification

  • Shared vectors: a bound token from each implementation decodes in both, and both reject it under a wrong context, under no context, and under the one-string form of the same parts.
  • 73/73 TS (new test/context.test.ts), 82/82 Python (including SQLAlchemy). Coverage: TS 96.4% lines / 94.1% branches, Python 94%.

🤖 Generated with Claude Code

mpointer and others added 2 commits October 28, 2026 10:36
…0.6.0)

Optional context bound into the GCM AAD (version || 0x00 || context), so a
token moved to another column or row fails authentication. No wire-format
change. Row-helper context function, SQLAlchemy column context, shared
vectors. 73/73 TS, 82/82 Python.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mpointer
mpointer merged commit 6be567c into main Oct 28, 2026
10 checks passed
@mpointer
mpointer deleted the feat/context-binding branch October 28, 2026 14:40
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.

1 participant