Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .changeset/audit-chain-head.md

This file was deleted.

14 changes: 0 additions & 14 deletions .changeset/magic-link-fragment-code.md

This file was deleted.

11 changes: 0 additions & 11 deletions .changeset/refresh-rotation-chain.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/refuse-weak-service-token.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/syslog-audit-sinks.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/system-config-cross-instance.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/unauthenticated-refusal-audit.md

This file was deleted.

41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# seamless-auth-api

## 0.24.0

### Minor Changes

- e2bd56e: The audit chain head is protected and can be signed (#595).

- A new migration adds a trigger to `auth_event_chain_head` that refuses INSERT, DELETE and TRUNCATE, and any change to `seq` or `last_hash` outside the `auth_events` insert trigger, which now runs as SECURITY DEFINER. A role that deletes the newest audit events can no longer move the head back to hide it, so `GET /admin/auth-events/integrity` reports the loss as `head_mismatch`.
- New optional `AUDIT_CHAIN_KEY`. When set, every audit insert signs the new head with an HMAC under it, and the integrity check fails a head whose signature is missing (`head_unsigned`, a new `reason`) or does not verify (`head_mismatch`). Set it on every instance. The migration signs the head when the key is set while it runs. Otherwise sign it once with `node dist/scripts/sealAuditHead.js`, and again after rotating the key. Production warns at boot while it is unset.
- The integrity report gains `headSigned`.
- `docs/security-posture.md` now recommends revoking writes on `auth_event_chain_head` as well, and notes that the retention setting is open to any session, so the DELETE privilege is the control.

- edb274f: Magic links now need a code from the link fragment to sign in, and a requested `redirectUri` must match exactly (#594).

Breaking, in two places:

- `redirectUri` on `POST /magic-link` is no longer accepted on its origin alone. With `magic_link_redirect_uris` empty, the only accepted value is the `/verify-magiclink` page on `frontend_url` or a configured origin, spelled exactly with no query. Any other path, such as a mobile landing page, has to be listed in `magic_link_redirect_uris`.
- The link is now `...?token=<token>#code=<code>`. `GET /magic-link/verify/:token` no longer consumes the link, even on the device that requested it: it always answers `409 confirmation_required`, with a new `sameDevice` boolean. `POST /magic-link/verify/:token/confirm` now requires a JSON body `{ "code": "<code>" }` and answers `400` without it. A wrong code spends the link. Links mailed before the upgrade carry no code and can no longer be completed, so a user with one in flight requests another.

Clients need to read `code` from the fragment, confirm with it, and confirm without asking when `sameDevice` is true. Release a client that does this before upgrading the API: it keeps working against older API versions, which ignore the body. A caller using external delivery that builds its own URL from `delivery.token` has to switch to `delivery.magicLinkUrl`, which carries the code.

Run the database migrations: this adds `magic_link_tokens.code_hash`.

- a335f78: Refresh rotation fixes:

- `DELETE /sessions/:id` and `DELETE /admin/sessions/by-id/:id` revoke the whole chain from the row given, so a session that rotated after it was listed is revoked at its head instead of surviving while the API answers 200 (#592).
- A rotated refresh token is treated as reuse however long after its rotation it is presented. It used to be answered `401 invalid_refresh_token` once the rotated row's idle window had passed, without revoking the chain. It is now `401 refresh_token_reused` and the chain is revoked (#593).
- New refresh replay window (#598): for `REFRESH_REPLAY_WINDOW_SECONDS` (default 5, at most 60, `0` disables) after a rotation, the rotated token is answered with the same successor, up to three times, so two adapter instances refreshing at once no longer sign the user out. The response shape is unchanged. Only the immediate predecessor of a live head qualifies. The successor token is stored encrypted on the rotated row and cleared when the window lapses or the chain is revoked.

Adds a migration for the `rotatedAt`, `replayTokenCiphertext` and `replayCount` session columns.

- 45530a8: With `NODE_ENV=production`, the server now refuses to start when `SEAMLESS_SERVICE_TOKEN` (or the fallback `API_SERVICE_TOKEN`) is shorter than 32 bytes or is a published default or placeholder value, such as `local-development-service-token-not-for-deployment` from `docker-compose.yml` or `GRAB_FROM_SEAMLESS_AUTH_PORTAL_DEV` from the templates (#599). The token is the key that signs service tokens, so a guessable value lets anyone call the API as a trusted adapter. `validateEnvs.sh` applies the same check before migrations run, and `src/config/serviceToken.ts` applies it at boot.

This is a breaking change for a production deployment that kept one of those values. Before upgrading, set a new token with `openssl rand -base64 48` on the API and on every server adapter that calls it. Development and test runs are unchanged.

- fbdecb7: Refusals anyone can produce for free no longer write audit events (#596). A request from a disallowed origin (`403`), a request to an unknown route (`404`), and `POST /refresh` with no token or one that matches no session (`401`) used to each write a hash-chained `request_suspicious` or `refresh_token_failed` row, taking the chain head lock. They are now counted in process, and each instance logs a one-line summary at most once a minute. Responses are unchanged. Expect far fewer `request_suspicious` rows in the trail and the security anomaly view. A refresh token that matches a revoked session is still recorded, now against that session and its user. The stored audit user agent is capped at 512 characters and a refused bearer's recorded route at 256.

### Patch Changes

- 5902e00: Syslog audit sinks are available (#586). Creating or updating a syslog sink no longer returns a 400. Records go over RFC 5424 on TLS with octet counting, and carry `seq` and `hash` in the structured data element `seamless@67592`, under the Fells Code IANA Private Enterprise Number 67592. Key collector parsing rules on that SD-ID.
- cc2a474: A `system_config` change now takes effect on every instance within about a second, not only on the instance that took the write (#597). Each instance used to cache config for five minutes, so disabling a login method, removing an OAuth provider or turning on `phishing_resistant_only` could stay ineffective on the other replicas for that long. Each instance now compares a hash of the stored rows with its cached copy at most once a second and reloads when they differ. Direct database edits are picked up the same way. If that check cannot reach the database, the config read fails instead of serving a copy it cannot show is current.

## 0.23.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion adapter-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"apiVersion": "0.23.0",
"apiVersion": "0.24.0",
"session": {
"subject": "sub",
"token": "token",
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"openapi": "3.0.3",
"info": { "title": "Seamless Auth API", "version": "0.23.0" },
"info": { "title": "Seamless Auth API", "version": "0.24.0" },
"components": {
"schemas": {},
"parameters": {},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seamless-auth-api",
"version": "0.23.0",
"version": "0.24.0",
"description": "Seamless Auth API - A web application server for supporting a Seamless Auth server instance.",
"main": "index.js",
"type": "module",
Expand Down