Skip to content

feat: accept only publishable keys in a browser - #16

Merged
MobileMage merged 1 commit into
gatepost-dev:mainfrom
lui01212:feat/publishable-key-allow-list
Oct 28, 2026
Merged

MobileMage merged 1 commit into
gatepost-dev:mainfrom
lui01212:feat/publishable-key-allow-list

Conversation

@lui01212

Copy link
Copy Markdown
Contributor

In a browser, a client and the field now accept only a publishable key, which starts with
nipost_pk_, and refuse any other key before a request leaves. An allow list fails safely if
a new secret prefix appears. Server clients are unchanged.

client.md gets a section on keys in a browser: trim, then classify, with one message for the
two secret prefixes and a second one for an unsupported key. field.md adds the error code
unsupported_key, which behaves as secret_key does and shows the same text on screen.
SEC-1, TS-12, CONTEXT.md and the catalogue follow, and the spec version goes to 0.4.0.

Browser code with a key of any other prefix now stops working. Apps that use the mock server
or a custom gateway with a made-up key in a web page should check that key before they move
to 0.4.0.

Closes #14

Verification: make check passed in a Linux container with Python 3.12, including 423 tests,
vectors, contract validation, lint, types, licences and the offline workflow audit. Claude
Code wrote most of this change, the wording and the doc test updates, from the plan agreed
in #14.

Signed-off-by: Lui Lui 40736418+lui01212@users.noreply.github.com

A browser client and the field now accept only a key that starts with
nipost_pk_ and refuse any other key before a request leaves, so a new
secret prefix cannot slip through. client.md gets the browser rule, and
field.md adds the error code unsupported_key with the text of
secret_key. The spec version goes to 0.4.0.

Signed-off-by: Lui Lui <40736418+lui01212@users.noreply.github.com>
@MobileMage
MobileMage merged commit b8a2119 into gatepost-dev:main Oct 28, 2026
5 checks passed
@MobileMage

Copy link
Copy Markdown
Collaborator

Thanks, merged. The js change can follow on 0.4.0.

MobileMage pushed a commit to gatepost-dev/js that referenced this pull request Nov 8, 2026
Move the spec submodule to 0.4.0 and follow its rules for keys in a
browser (SEC-1).
In a page with a `document`, the client now accepts only a key that
starts with
`nipost_pk_`. It reads the key without the white space around it. A
secret key keeps its
message, and any other key raises a `TypeError` that says it is not a
publishable key.
Neither message holds the key. A server client still accepts any key.

The field reads the kind of a refused key. For an unsupported key it
raises
`gatepost-error` with the new code `unsupported_key`, shows the same
text as for a secret
key and logs its own console error. The change also bumps `SPEC_VERSION`
in the four
packages, adds `unsupported_key` to the messages, the API reports and
the READMEs, copies the
new glossary entry into `CONTEXT.md` and adds two change files.

The new client, key secrecy and field tests failed on the old code, and
pass now.
`pnpm check` passes in a Linux container. I did not run the Node 22
tests or the Firefox
and WebKit journeys.

This follows gatepost-dev/spec#16.

Claude Code helped write the tests, the code, the docs and the change
files, and review the diff.

Signed-off-by: Lui Lui <40736418+lui01212@users.noreply.github.com>

Signed-off-by: Lui Lui <40736418+lui01212@users.noreply.github.com>
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.

Allow only publishable key prefixes in browser clients

2 participants