@ultimat3/auth 31.31.0 → 31.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/api-keys.ts +5 -4
- package/src/base64url.ts +3 -1
- package/src/directory.ts +4 -2
- package/src/email.ts +4 -2
- package/src/id-token.ts +7 -5
- package/src/identity-provider-route-core.ts +2 -1
- package/src/jwks.ts +7 -6
- package/src/mfa.ts +5 -3
- package/src/oauth-builtins.ts +5 -4
- package/src/oauth-cookie.ts +6 -4
- package/src/oauth-discovery.ts +2 -1
- package/src/oauth-paths.ts +6 -4
- package/src/oauth-registry.ts +7 -6
- package/src/oauth.ts +4 -3
- package/src/policy-bridge.ts +4 -3
- package/src/policy-numbers.ts +4 -3
- package/src/revocation.ts +6 -4
- package/src/session.ts +5 -3
- package/src/tokens.ts +7 -5
- package/src/workload.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/auth",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.33.0",
|
|
4
4
|
"description": "Sessions, passwords, OAuth, MFA and api keys — resolved to one Actor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"test": "bun test"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ultimat3/core": "31.
|
|
54
|
-
"@ultimat3/db": "31.
|
|
55
|
-
"@ultimat3/schema": "31.
|
|
53
|
+
"@ultimat3/core": "31.33.0",
|
|
54
|
+
"@ultimat3/db": "31.33.0",
|
|
55
|
+
"@ultimat3/schema": "31.33.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/api-keys.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: machine credentials. This is how an agent — an MCP client driving a
|
|
2
|
-
// generated Ultimate app — authenticates: it presents a key, the key resolves to an
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// generated Ultimate app — authenticates: it presents a key, the key resolves to an `agentActor`
|
|
3
|
+
// carrying exactly the key's scopes, and it goes through the same policy evaluation a human does.
|
|
4
|
+
//
|
|
5
|
+
// The plaintext is shown once; only its SHA-256 is ever stored, and lookup happens by the
|
|
6
|
+
// non-secret id so the secret never appears in a query, an index or a log.
|
|
6
7
|
|
|
7
8
|
import { type Clock, randomHex, systemClock, timingSafeEqual } from '@ultimat3/core';
|
|
8
9
|
import type { ApiKeyStore, AuthApiKeyRecord, AuthUser, UserStore } from './adapter';
|
package/src/base64url.ts
CHANGED
|
@@ -8,7 +8,9 @@ const BASE64URL_REPLACEMENTS: Readonly<Record<string, string>> = { '+': '-', '/'
|
|
|
8
8
|
export function base64Url(bytes: Uint8Array): string {
|
|
9
9
|
let binary = '';
|
|
10
10
|
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
11
|
-
return btoa(binary).replace(BASE64URL_UNSAFE, (char) =>
|
|
11
|
+
return btoa(binary).replace(BASE64URL_UNSAFE, (char) =>
|
|
12
|
+
Object.hasOwn(BASE64URL_REPLACEMENTS, char) ? (BASE64URL_REPLACEMENTS[char] ?? '') : '',
|
|
13
|
+
);
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
/**
|
package/src/directory.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: reading accounts back out, safely. A quarterly access review — "who in
|
|
2
2
|
// this org holds `admin`, and is any of them gone?" — was unanswerable: `UserStore` could find one
|
|
3
3
|
// user by address or by id and nothing else, so there was no way to enumerate an org's members at
|
|
4
|
-
// all.
|
|
5
|
-
//
|
|
4
|
+
// all.
|
|
5
|
+
//
|
|
6
|
+
// The projection is `describeApiKey`'s shape and its rule: never the password hash, never the TOTP
|
|
7
|
+
// secret, never a recovery code hash.
|
|
6
8
|
|
|
7
9
|
import type { AuthUser, UserQuery } from './adapter';
|
|
8
10
|
import type { Auth } from './auth';
|
package/src/email.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the ONE normalisation an email address gets before anything uses it as an
|
|
2
2
|
// identity key — a user lookup, a user insert, or the lockout bucket that has to key the same way
|
|
3
|
-
// those two do.
|
|
4
|
-
//
|
|
3
|
+
// those two do.
|
|
4
|
+
//
|
|
5
|
+
// It lives above the `AuthAdapter` seam because an adapter that normalises hides a caller that
|
|
6
|
+
// forgot to: `MemoryAuthAdapter` did and `PostgresAuthAdapter` did not, so "does this account
|
|
5
7
|
// exist" had two answers, one under `x dev` and another in production.
|
|
6
8
|
|
|
7
9
|
/**
|
package/src/id-token.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Single responsibility: turning a provider's id token into claims this handshake is allowed to
|
|
2
|
-
// believe.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
2
|
+
// believe.
|
|
3
|
+
//
|
|
4
|
+
// Every caller must say where its trust comes from: `keys: 'token-endpoint-tls'` is the one channel
|
|
5
|
+
// OIDC Core 3.1.3.7 exempts from a signature check, and anything else — IdP-initiated login,
|
|
6
|
+
// `response_mode=form_post`, back-channel logout, token exchange — passes a `JwksKeySource` and
|
|
7
|
+
// gets the signature verified. The argument is required rather than defaulted because a default is
|
|
8
|
+
// what silently makes the second door as trusting as the first.
|
|
7
9
|
|
|
8
10
|
import type { Clock } from '@ultimat3/core';
|
|
9
11
|
import { renderCauseValue, timingSafeEqual } from '@ultimat3/core';
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isUltimateError,
|
|
9
9
|
logger,
|
|
10
10
|
renderFixShellArg,
|
|
11
|
+
trimTrailingSlashes,
|
|
11
12
|
type UltimateError,
|
|
12
13
|
} from '@ultimat3/core';
|
|
13
14
|
import type { Auth } from './auth';
|
|
@@ -134,7 +135,7 @@ function origin(options: SignInRouteOptions): string {
|
|
|
134
135
|
meta: { key: 'APP_URL' },
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
|
-
return declared
|
|
138
|
+
return trimTrailingSlashes(declared);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
/**
|
package/src/jwks.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Single responsibility: verifying a JWT's signature against a provider's published JWKS.
|
|
2
|
-
// `crypto.subtle` covers RS256 and ES256, so this costs no dependency.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
2
|
+
// `crypto.subtle` covers RS256 and ES256, so this costs no dependency.
|
|
3
|
+
//
|
|
4
|
+
// It exists because the OIDC Core 3.1.3.7 exemption — "a token fetched over TLS straight from the
|
|
5
|
+
// token endpoint needs no signature check" — holds for exactly one channel, and IdP-initiated
|
|
6
|
+
// login, `response_mode=form_post`, back-channel logout and token exchange are all not it. On any
|
|
7
|
+
// of those, an unverified JWT with the right `iss`, `aud` and a victim's `sub` is a full account
|
|
8
|
+
// takeover with no credential, so a signature check has to exist before those doors are opened.
|
|
8
9
|
|
|
9
10
|
import type { Clock, Scheduler } from '@ultimat3/core';
|
|
10
11
|
import {
|
package/src/mfa.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: TOTP (RFC 6238) and recovery codes. The drift window is explicit and
|
|
2
2
|
// small, and every accepted step is remembered: without replay rejection a code shouted over a
|
|
3
|
-
// phishing page stays valid for the rest of its 30 seconds.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// phishing page stays valid for the rest of its 30 seconds.
|
|
4
|
+
//
|
|
5
|
+
// Recovery codes are hashed at rest and single-use, so a database dump is not a permanent MFA
|
|
6
|
+
// bypass; consuming one is the adapter's (`consumeRecoveryCode`), because single-use has to be one
|
|
7
|
+
// atomic step.
|
|
6
8
|
|
|
7
9
|
import { finiteCount, hmac, timingSafeEqual } from '@ultimat3/core';
|
|
8
10
|
import type { Auth } from './auth';
|
package/src/oauth-builtins.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the two consumer IdPs Ultimate ships with, as plain data. Apple left in
|
|
2
|
-
// 26.0.0: it POSTs its callback and both callback routes are GET, so it could never complete.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// 26.0.0: it POSTs its callback and both callback routes are GET, so it could never complete.
|
|
3
|
+
//
|
|
4
|
+
// They live apart from `oauth-registry.ts` so the registry can be seeded from them while `oauth.ts`
|
|
5
|
+
// reads the registry — the only edge back to `oauth.ts` is the type, and a type is erased, so there
|
|
6
|
+
// is no runtime cycle between the three files.
|
|
6
7
|
|
|
7
8
|
import type { OAuthProvider } from './oauth';
|
|
8
9
|
|
package/src/oauth-cookie.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the handshake's server-side codec (`sealHandshake` / `openHandshake`), its
|
|
2
|
-
// secret and its deadline.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// secret and its deadline.
|
|
3
|
+
//
|
|
4
|
+
// The two legs of an authorization-code login are separate HTTP requests, so `beginOAuth`'s state,
|
|
5
|
+
// nonce and PKCE verifier have to survive the round trip — and a framework that leaves that to the
|
|
6
|
+
// app gets one hand-rolled store per app, which is exactly where PKCE quietly stops proving
|
|
7
|
+
// anything. The cookie is `oauth-handshake-cookie.ts`.
|
|
6
8
|
|
|
7
9
|
import type { Clock } from '@ultimat3/core';
|
|
8
10
|
import { EnvMissingError, hmac, systemClock, timingSafeEqual } from '@ultimat3/core';
|
package/src/oauth-discovery.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
renderFixLiteral,
|
|
9
9
|
renderFixShellArg,
|
|
10
10
|
renderThrowable,
|
|
11
|
+
trimTrailingSlashes,
|
|
11
12
|
} from '@ultimat3/core';
|
|
12
13
|
import { outboundResponse } from '@ultimat3/core/outbound';
|
|
13
14
|
import { isRecord } from './json';
|
|
@@ -23,7 +24,7 @@ const TIMEOUT_CONSEQUENCE =
|
|
|
23
24
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
24
25
|
|
|
25
26
|
/** An issuer as it is compared and built on: its trailing slashes are not part of its identity. */
|
|
26
|
-
const bareIssuer = (issuer: string): string => issuer
|
|
27
|
+
const bareIssuer = (issuer: string): string => trimTrailingSlashes(issuer);
|
|
27
28
|
|
|
28
29
|
/** The document lives at a fixed suffix off the issuer; the issuer keeps its own path. */
|
|
29
30
|
export const discoveryUrl = (issuer: string): string =>
|
package/src/oauth-paths.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the one declaration of where the OAuth login routes live. It imports
|
|
2
|
-
// nothing so that `errors.ts` and `oauth-route.ts` can both read it without a cycle — which is
|
|
3
|
-
//
|
|
4
|
-
// while no route was mounted anywhere.
|
|
5
|
-
//
|
|
2
|
+
// nothing so that `errors.ts` and `oauth-route.ts` can both read it without a cycle — which is the
|
|
3
|
+
// point: three shipped `fix:` lines told the caller to restart at `GET /auth/oauth/<provider>`
|
|
4
|
+
// while no route was mounted anywhere.
|
|
5
|
+
//
|
|
6
|
+
// Deriving both the mount and the fix from here makes a fix line that names a route nothing serves
|
|
7
|
+
// impossible rather than merely discouraged.
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* The base and the start path are not configurable, on purpose: a movable start path is a `fix:`
|
package/src/oauth-registry.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// Single responsibility: which OAuth providers this process knows about.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// Single responsibility: which OAuth providers this process knows about.
|
|
2
|
+
//
|
|
3
|
+
// A closed union of three consumer IdPs made an enterprise OP — Okta, Entra, Ping, an in-house OP —
|
|
4
|
+
// *unrepresentable*: the constraint was a type, so there was no runtime escape and the only ways
|
|
5
|
+
// out were forking the package or bypassing the whole subsystem, losing PKCE, the sealed handshake,
|
|
6
|
+
// issuer pinning and account linking with it. The two built-ins register through the same call an
|
|
7
|
+
// app uses, so the opening does not create a second path.
|
|
7
8
|
|
|
8
9
|
import { renderCauseValue, renderFixLiteral } from '@ultimat3/core';
|
|
9
10
|
import { AuthError } from './errors';
|
package/src/oauth.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the OAuth2/OIDC handshake. PKCE is mandatory rather than
|
|
2
2
|
// provider-dependent — an authorization code with no proof-of-possession is stealable from a
|
|
3
|
-
// redirect, and "this provider does not need it" is how that becomes a real incident.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// redirect, and "this provider does not need it" is how that becomes a real incident.
|
|
4
|
+
//
|
|
5
|
+
// Provider configs are pure data and live in `oauth-registry.ts`: importing this file performs no
|
|
6
|
+
// network I/O and reads no env.
|
|
6
7
|
|
|
7
8
|
import { timingSafeEqual } from '@ultimat3/core';
|
|
8
9
|
import { oauthStateInvalid } from './oauth-errors';
|
package/src/policy-bridge.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Single responsibility: turn an authenticated identity into core's `Actor`. There is exactly
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Single responsibility: turn an authenticated identity into core's `Actor`. There is exactly one
|
|
2
|
+
// authz system in Ultimate — `@ultimat3/policy` — and auth's only job is producing the actor it
|
|
3
|
+
// evaluates. Nothing downstream ever authorizes on a session row, a user row or an api key.
|
|
4
|
+
//
|
|
4
5
|
// `PolicyActorFields` mirrors `@ultimat3/policy`'s shape structurally so this package does not
|
|
5
6
|
// import a same-tier package; policy binds to it by structure, in whichever order they land.
|
|
6
7
|
|
package/src/policy-numbers.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the numeric screen over every option this package bounds anything with —
|
|
2
2
|
// the three policies `defineAuth` resolves, and the runtime options (`jwks`, the OAuth legs, TOTP
|
|
3
|
-
// drift, the limiter's key cap) that arrive on a call rather than through config.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// drift, the limiter's key cap) that arrive on a call rather than through config.
|
|
4
|
+
//
|
|
5
|
+
// One file, because the rule is one rule: a duration, a length and an allowance are all "a whole
|
|
6
|
+
// positive number, and NaN is what an unset environment variable parses to".
|
|
6
7
|
|
|
7
8
|
import { authPolicyNumberInvalid } from './errors';
|
|
8
9
|
import type { PasswordPolicy } from './password';
|
package/src/revocation.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: taking a credential away, at the three blast radii an incident actually
|
|
2
|
-
// has — one person, one tenant, everything issued before an instant.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// has — one person, one tenant, everything issued before an instant.
|
|
3
|
+
//
|
|
4
|
+
// `deleteOtherSessions` was the only one of the three the seam could express, so "kill every
|
|
5
|
+
// session in this org, now" was a per-user loop over an enumeration the adapter could not do, or a
|
|
6
|
+
// `TRUNCATE` that killed every other tenant with it. Doing nothing meant thirty days, which is the
|
|
7
|
+
// absolute TTL.
|
|
6
8
|
|
|
7
9
|
import { logger } from '@ultimat3/core';
|
|
8
10
|
import type { AuthUser } from './adapter';
|
package/src/session.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: session lifetime and the cookie that carries it. Two expiries are
|
|
2
2
|
// evaluated independently — `absoluteExpiresAt` is a ceiling activity can never push out, and
|
|
3
|
-
// `idleTtlMs` measures from `lastSeenAt` — because sliding-only expiry means a stolen session
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// `idleTtlMs` measures from `lastSeenAt` — because sliding-only expiry means a stolen session lives
|
|
4
|
+
// forever.
|
|
5
|
+
//
|
|
6
|
+
// `RequestLike`/`CookieJar` are structural on purpose: `@ultimat3/http` binds to them without this
|
|
7
|
+
// package importing it (same-tier packages must not depend on each other).
|
|
6
8
|
|
|
7
9
|
import type { Clock } from '@ultimat3/core';
|
|
8
10
|
import { readCookie, serializeSetCookie, timingSafeEqual } from '@ultimat3/core';
|
package/src/tokens.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// Single responsibility: the secret primitives every other file in this package shares —
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Single responsibility: the secret primitives every other file in this package shares — CSPRNG
|
|
2
|
+
// tokens and SHA-256 hashing. Centralised so no call site can quietly reach for `===` on a secret,
|
|
3
|
+
// which leaks the shared prefix length one request at a time.
|
|
4
|
+
//
|
|
5
|
+
// The constant-time comparison itself is `@ultimat3/core`'s `timingSafeEqual` — `@ultimat3/storage`
|
|
6
|
+
// needs the exact same one — imported from core by every caller, never re-exported here
|
|
7
|
+
// (`X_HELPER_COPY`).
|
|
6
8
|
|
|
7
9
|
import { finiteCount, timingSafeEqual } from '@ultimat3/core';
|
|
8
10
|
import { base64Url } from './base64url';
|
package/src/workload.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Single responsibility: verifying a workload's own JWT and turning it into a `ServiceIdentity`.
|
|
2
|
+
//
|
|
2
3
|
// Before this, `ServiceIdentity` was a plain struct with no non-test caller and nothing in the
|
|
3
4
|
// framework verified a service credential at all — no workload identity, no `client_credentials`,
|
|
4
5
|
// no token exchange — so two Ultimate services could only trust each other through a long-lived
|