@aooth/auth-moost 0.2.0 → 0.2.1
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/dist/atscript/index.mjs +1 -1
- package/dist/forms-DDn6m5rP.mjs +474 -0
- package/dist/index.d.mts +74 -18
- package/dist/index.mjs +115 -24
- package/package.json +24 -24
- package/src/atscript/models/forms.as.d.ts +1 -1
- package/dist/forms-C9Wey0e9.mjs +0 -484
package/dist/index.d.mts
CHANGED
|
@@ -201,14 +201,14 @@ declare function authGuardInterceptor(opts?: AuthOptions): TInterceptorDef;
|
|
|
201
201
|
*/
|
|
202
202
|
declare function AuthGuarded(opts?: AuthOptions): ClassDecorator & MethodDecorator;
|
|
203
203
|
//#endregion
|
|
204
|
-
//#region ../../node_modules/.pnpm/@wooksjs+event-wf@0.
|
|
204
|
+
//#region ../../node_modules/.pnpm/@wooksjs+event-wf@0.8.0_@prostojs+logger@0.4.3_@prostojs+router@0.3.6_@wooksjs+event-co_86044e452e9fcfb26549e7ecde073940/node_modules/@wooksjs/event-wf/dist/index.d.ts
|
|
205
205
|
interface WfFinishedResponse {
|
|
206
206
|
type: 'redirect' | 'data';
|
|
207
207
|
/** Redirect URL or response body */
|
|
208
208
|
value: unknown;
|
|
209
209
|
/** HTTP status code (default 200 for data, 302 for redirect) */
|
|
210
210
|
status?: number;
|
|
211
|
-
/** Cookies to set */
|
|
211
|
+
/** Cookies to set — `options` are `setCookie()` attributes (`maxAge` in **seconds**, `expires` a Date or ms timestamp) */
|
|
212
212
|
cookies?: Record<string, {
|
|
213
213
|
value: string;
|
|
214
214
|
options?: Record<string, unknown>;
|
|
@@ -366,6 +366,7 @@ declare const AOOTH_MESSAGES: {
|
|
|
366
366
|
readonly INVALID_PASSWORD: "Invalid password";
|
|
367
367
|
readonly INCORRECT_PASSWORD: "Incorrect password";
|
|
368
368
|
readonly SESSION_LIMIT_REACHED: "Session limit reached";
|
|
369
|
+
readonly PASSWORD_CHANGED_SIGN_IN_AGAIN: "Your password was changed. Please sign in again.";
|
|
369
370
|
readonly INVALID_CODE: "Invalid code";
|
|
370
371
|
/** Params: `seconds`. */
|
|
371
372
|
readonly RESEND_WAIT: "Please wait {seconds}s before requesting a new code.";
|
|
@@ -827,7 +828,12 @@ interface RateLimitInterceptorOptions {
|
|
|
827
828
|
rules?: RateLimitRuleInput$1[];
|
|
828
829
|
/** Default key strategy for routes whose `@RateLimit` doesn't set one. Default: `'ip'`. */
|
|
829
830
|
key?: RateLimitKeyStrategy;
|
|
830
|
-
/**
|
|
831
|
+
/**
|
|
832
|
+
* Trust exactly ONE reverse proxy in front of the app: the client IP is the
|
|
833
|
+
* right-most `x-forwarded-for` entry (the one that proxy wrote). Default:
|
|
834
|
+
* `false` — the client IP as the HTTP app resolves it (`useRequest().getIp()`:
|
|
835
|
+
* the socket peer, unless the wooks HTTP app configures `trustProxy`).
|
|
836
|
+
*/
|
|
831
837
|
trustProxy?: boolean;
|
|
832
838
|
/** Emit draft `RateLimit-*` headers on every response of a limited route. Default: `true`. */
|
|
833
839
|
headers?: boolean;
|
|
@@ -1720,9 +1726,12 @@ interface AuthWfSessionPolicy {
|
|
|
1720
1726
|
* `UserService.changePassword`), NOT rate limiting — so `rateLimit` is
|
|
1721
1727
|
* optional and off by default.
|
|
1722
1728
|
*
|
|
1723
|
-
* - `revokeOtherSessions` — on success, revoke
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
1729
|
+
* - `revokeOtherSessions` — on success, revoke the user's OTHER sessions (OWASP
|
|
1730
|
+
* Session Management: kill ghost sessions after a credential change). Default
|
|
1731
|
+
* `true`. Either way the acting device moves onto a fresh session and the
|
|
1732
|
+
* session the change was made from is revoked; when that session can't be
|
|
1733
|
+
* targeted (stateless JWT / encapsulated store, legacy pre-sessionId
|
|
1734
|
+
* credential) every session is revoked.
|
|
1726
1735
|
* - `rateLimit.minIntervalMs` — minimum gap between successive password changes
|
|
1727
1736
|
* (Okta "minimum password age"). Enforced against `password.lastChanged` with
|
|
1728
1737
|
* ZERO extra storage. Omit to disable.
|
|
@@ -2184,6 +2193,20 @@ interface AuthWfCtx {
|
|
|
2184
2193
|
aborted?: boolean;
|
|
2185
2194
|
isFirstLogin?: boolean;
|
|
2186
2195
|
newPasswordRequired?: boolean;
|
|
2196
|
+
/**
|
|
2197
|
+
* Set by `create-password-form` once it stored a new password. In login.flow
|
|
2198
|
+
* it gates the `revoke-sessions` step after the MFA loop (sessions opened
|
|
2199
|
+
* with the old password end) and exempts the run from
|
|
2200
|
+
* `check-password-unchanged`. Server-only flow control.
|
|
2201
|
+
*/
|
|
2202
|
+
passwordChanged?: boolean;
|
|
2203
|
+
/**
|
|
2204
|
+
* `password.lastChanged` of the account as the `credentials` step verified
|
|
2205
|
+
* it. `check-password-unchanged` compares it before the login is recorded,
|
|
2206
|
+
* so a run paused across a password change can't finish on the replaced
|
|
2207
|
+
* password. Server-only flow control.
|
|
2208
|
+
*/
|
|
2209
|
+
passwordStamp?: number;
|
|
2187
2210
|
/**
|
|
2188
2211
|
* Idempotency latch for the single `record-login` funnel step. Set true once
|
|
2189
2212
|
* a login has been stamped this run — by the `credentials` step (the password
|
|
@@ -2973,7 +2996,8 @@ declare class AuthWorkflow {
|
|
|
2973
2996
|
* successful change (OWASP Session Management) and applies NO rate limit —
|
|
2974
2997
|
* current-password re-entry (enforced by `UserService.changePassword`) is the
|
|
2975
2998
|
* primary protection, not throttling. Customers override to add a min-interval
|
|
2976
|
-
* (`rateLimit.minIntervalMs`) or to keep other sessions alive.
|
|
2999
|
+
* (`rateLimit.minIntervalMs`) or to keep other sessions alive. The session the
|
|
3000
|
+
* change was made from is always ended (see `finish-change-password`).
|
|
2977
3001
|
*
|
|
2978
3002
|
* Whether the flow may be STARTED at all is governed by arbac on the trigger
|
|
2979
3003
|
* route (deny the `change-password` action to forbid it for SSO-only orgs) —
|
|
@@ -3738,11 +3762,28 @@ declare class AuthWorkflow {
|
|
|
3738
3762
|
*/
|
|
3739
3763
|
changePasswordForm(ctx: AuthWfCtx): Promise<unknown>;
|
|
3740
3764
|
/**
|
|
3741
|
-
* Change-password terminal —
|
|
3742
|
-
*
|
|
3743
|
-
*
|
|
3744
|
-
*
|
|
3745
|
-
*
|
|
3765
|
+
* Change-password terminal — sign the current device in on a FRESH session
|
|
3766
|
+
* and end the one the change was made from, then emit a success message.
|
|
3767
|
+
* The new pair is minted under a new session id, so the pre-change session
|
|
3768
|
+
* (its access token, refresh token and every rotation) is revoked here —
|
|
3769
|
+
* whatever `revokeOtherSessions` says, since that policy covers only the
|
|
3770
|
+
* user's OTHER sessions. Runs AFTER the optional `revoke-sessions` step, so
|
|
3771
|
+
* the default net effect is "kill every old session, keep this device on a
|
|
3772
|
+
* new one" (OWASP Session Management: no ghost sessions survive a credential
|
|
3773
|
+
* change).
|
|
3774
|
+
*
|
|
3775
|
+
* The pre-change session is revoked BEFORE the issue, so a failed issue
|
|
3776
|
+
* (store error, `maxConcurrent` refusal) leaves the user signed out, never on
|
|
3777
|
+
* the old session. A refresh in flight during the change is covered by
|
|
3778
|
+
* `AuthCredential`'s revocation protocol (it can't leave live credentials in
|
|
3779
|
+
* a revoked session).
|
|
3780
|
+
*
|
|
3781
|
+
* When one session can't be targeted — a stateless store (JWT /
|
|
3782
|
+
* encapsulated), or a legacy credential minted before `sessionId` existed
|
|
3783
|
+
* (its fallback id, the access token's fingerprint, never reaches the refresh
|
|
3784
|
+
* row) — ALL of the user's sessions are revoked (`revokeAllForUser`, also
|
|
3785
|
+
* under `revokeOtherSessions: false`). A stateless store also denylists the
|
|
3786
|
+
* presented access token (best effort): its revocation epoch is process-local.
|
|
3746
3787
|
*/
|
|
3747
3788
|
finishChangePassword(ctx: AuthWfCtx): Promise<undefined>;
|
|
3748
3789
|
/**
|
|
@@ -4088,15 +4129,20 @@ declare class AuthWorkflow {
|
|
|
4088
4129
|
persistConsents(ctx: AuthWfCtx): Promise<undefined>;
|
|
4089
4130
|
/**
|
|
4090
4131
|
* Revoke the user's existing sessions. Shared by recovery (gated upstream by
|
|
4091
|
-
* `ctx.postReset.revokeAllSessions`)
|
|
4092
|
-
* by `ctx.changePassword.revokeOtherSessions`)
|
|
4132
|
+
* `ctx.postReset.revokeAllSessions`), authenticated change-password (gated
|
|
4133
|
+
* by `ctx.changePassword.revokeOtherSessions`) and the forced password change
|
|
4134
|
+
* at login / invite (gated by `ctx.passwordChanged`).
|
|
4093
4135
|
*
|
|
4094
4136
|
* - Change-password runs in an authenticated context, so we KEEP the caller's
|
|
4095
|
-
* current
|
|
4137
|
+
* current session via `revokeOtherSessions(username, currentSessionId)` —
|
|
4096
4138
|
* OWASP "invalidate other sessions" without logging the user out of the tab
|
|
4097
|
-
* they just changed their password in.
|
|
4098
|
-
*
|
|
4099
|
-
*
|
|
4139
|
+
* they just changed their password in. `finish-change-password` then moves
|
|
4140
|
+
* that tab onto a fresh session and revokes the kept one (and covers stores
|
|
4141
|
+
* that cannot enumerate, where `revokeOtherSessions` is a no-op). If the
|
|
4142
|
+
* current session can't be resolved (no session id), fall back to revoking
|
|
4143
|
+
* everything (fail-secure).
|
|
4144
|
+
* - Recovery and the forced change are anonymous (no current session to
|
|
4145
|
+
* keep) → `revokeAllForUser`.
|
|
4100
4146
|
*/
|
|
4101
4147
|
revokeSessions(ctx: AuthWfCtx): Promise<undefined>;
|
|
4102
4148
|
/**
|
|
@@ -4107,6 +4153,16 @@ declare class AuthWorkflow {
|
|
|
4107
4153
|
* also zeroes `failedLoginAttempts`, so the next login starts clean.
|
|
4108
4154
|
*/
|
|
4109
4155
|
unlockAccount(ctx: AuthWfCtx): Promise<undefined>;
|
|
4156
|
+
/**
|
|
4157
|
+
* Login-only guard before the `record-login` funnel (and again before
|
|
4158
|
+
* `mint-authz-code`, past the consent pause): the account's
|
|
4159
|
+
* `password.lastChanged` must still be the one the `credentials` step
|
|
4160
|
+
* verified (`ctx.passwordStamp`). A run paused after the password check (MFA,
|
|
4161
|
+
* enrolment, consents …) and resumed after the password was changed
|
|
4162
|
+
* elsewhere finishes with an error instead of issuing tokens or minting an
|
|
4163
|
+
* authorization code. Skipped when this run changed the password itself.
|
|
4164
|
+
*/
|
|
4165
|
+
checkPasswordUnchanged(ctx: AuthWfCtx): Promise<undefined>;
|
|
4110
4166
|
/**
|
|
4111
4167
|
* The SINGLE login-completion funnel. Every flow that establishes an
|
|
4112
4168
|
* authenticated session routes through here — placed in each login schema
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as RemoveMfaConfirmForm, D as StepUpConfirmForm, E as SignupForm, O as TermsBumpForm, T as SetPasswordForm, _ as PasswordReauthForm, a as ConcurrencyLimitForm, b as ProveControlOtpForm, c as EnrollConfirmForm, d as InviteChooseUsernameForm, f as InviteForm, g as MfaCodeForm, h as ManageMfaForm, i as ChangePasswordForm, l as EnrollPickMethodForm, n as AskPhoneForm, o as EmailIdentifierForm, p as LoginCredentialsForm, r as AuthorizeConsentForm, s as EnrollAddressForm, t as AskEmailForm, u as EnrollTotpQrForm, v as PincodeForm, w as Select2faForm, y as ProveControlForm } from "./forms-
|
|
1
|
+
import { C as RemoveMfaConfirmForm, D as StepUpConfirmForm, E as SignupForm, O as TermsBumpForm, T as SetPasswordForm, _ as PasswordReauthForm, a as ConcurrencyLimitForm, b as ProveControlOtpForm, c as EnrollConfirmForm, d as InviteChooseUsernameForm, f as InviteForm, g as MfaCodeForm, h as ManageMfaForm, i as ChangePasswordForm, l as EnrollPickMethodForm, n as AskPhoneForm, o as EmailIdentifierForm, p as LoginCredentialsForm, r as AuthorizeConsentForm, s as EnrollAddressForm, t as AskEmailForm, u as EnrollTotpQrForm, v as PincodeForm, w as Select2faForm, y as ProveControlForm } from "./forms-DDn6m5rP.mjs";
|
|
2
2
|
import { Controller, HandlerPaths, Inherit, Inject, InjectMoostLogger, Injectable, Intercept, MoostInit, Optional, Param, Resolve, TInterceptorPriority, defineAfterInterceptor, defineBeforeInterceptor, getMoostMate, useControllerContext, useLogger } from "moost";
|
|
3
3
|
import { AuthCredential, AuthError, RateLimitStoreMemory, RateLimitStoreMemory as RateLimitStoreMemory$1, RateLimiter, RateLimiter as RateLimiter$1, generateMagicLinkToken, generateOpaqueToken, parseRateLimitRule, pickGoverning } from "@aooth/auth";
|
|
4
4
|
import { current, defineWook, eventTypeKey, key } from "@wooksjs/event-core";
|
|
5
|
-
import { HttpError, useAuthorization, useCookies, useHeaders, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
5
|
+
import { HttpError, resolveForwarded, useAuthorization, useCookies, useHeaders, useRequest, useResponse, useUrlParams } from "@wooksjs/event-http";
|
|
6
6
|
import { ArbacAction, ArbacResource, getArbacMate, useArbac } from "@aooth/arbac-moost";
|
|
7
7
|
import { FederatedIdentityStore, SEEN_DEVICES_DEFAULT_CAP, UserAuthError, UserService, generateMfaCode, generateTotpSecret, generateTotpUri, maskEmail, maskPhone, pickDefinedProfile, verifyTotpCode } from "@aooth/user";
|
|
8
8
|
import { Body, Delete, Get, HttpError as HttpError$1, Post, Query } from "@moostjs/event-http";
|
|
@@ -469,7 +469,7 @@ function rateLimitInterceptors(opts) {
|
|
|
469
469
|
const defaultRules = opts?.rules?.map((r) => parseRateLimitRule(r));
|
|
470
470
|
const limiter = opts?.limiter ?? new RateLimiter$1();
|
|
471
471
|
const emitHeaders = opts?.headers ?? true;
|
|
472
|
-
const
|
|
472
|
+
const trustProxy = opts?.trustProxy ?? false;
|
|
473
473
|
const routeConfigs = /* @__PURE__ */ new WeakMap();
|
|
474
474
|
const resolveRouteConfig = (cc) => {
|
|
475
475
|
const ctor = cc.getController().constructor;
|
|
@@ -522,7 +522,7 @@ function rateLimitInterceptors(opts) {
|
|
|
522
522
|
const decisions = [];
|
|
523
523
|
const headers = [];
|
|
524
524
|
for (const policy of owned) {
|
|
525
|
-
const subject = await resolveSubject(policy.keyStrategy,
|
|
525
|
+
const subject = await resolveSubject(policy.keyStrategy, trustProxy, ctx);
|
|
526
526
|
if (subject == null) continue;
|
|
527
527
|
decisions.push(await limiter.check(policy.scope, subject, policy.rules, { ...policy.defaultMessage !== void 0 && { defaultMessage: policy.defaultMessage } }));
|
|
528
528
|
headers.push(policy.policyHeader);
|
|
@@ -547,7 +547,7 @@ function rateLimitInterceptors(opts) {
|
|
|
547
547
|
};
|
|
548
548
|
return [defineBeforeInterceptor(() => evaluate("pre"), TInterceptorPriority.BEFORE_GUARD), defineBeforeInterceptor(() => evaluate("post"), TInterceptorPriority.AFTER_GUARD)];
|
|
549
549
|
}
|
|
550
|
-
async function resolveSubject(strategy,
|
|
550
|
+
async function resolveSubject(strategy, trustProxy, ctx) {
|
|
551
551
|
if (typeof strategy === "function") return await strategy();
|
|
552
552
|
if (strategy !== "ip") {
|
|
553
553
|
const subject = getRateLimitSubject(strategy, ctx);
|
|
@@ -556,7 +556,18 @@ async function resolveSubject(strategy, ipOpts, ctx) {
|
|
|
556
556
|
if (strategy === "user" && auth?.userId !== void 0) return `u:${auth.userId}`;
|
|
557
557
|
if (strategy === "session" && auth?.sessionId !== void 0) return `s:${auth.sessionId}`;
|
|
558
558
|
}
|
|
559
|
-
return `ip:${
|
|
559
|
+
return `ip:${clientIp(trustProxy, ctx)}`;
|
|
560
|
+
}
|
|
561
|
+
/** Hop 0 (the socket peer) is the one trusted proxy. */
|
|
562
|
+
const trustOneHop = (_addr, hop) => hop < 1;
|
|
563
|
+
/**
|
|
564
|
+
* `trustProxy: true` resolves like wooks' deprecated `getIp({ trustProxy: true })`
|
|
565
|
+
* (one trusted hop, the right-most forwarded entry; `''` with no known peer)
|
|
566
|
+
* without its deprecation notice; otherwise the app's own `getIp()`.
|
|
567
|
+
*/
|
|
568
|
+
function clientIp(trustProxy, ctx) {
|
|
569
|
+
const req = useRequest(ctx);
|
|
570
|
+
return trustProxy ? resolveForwarded(req.raw, trustOneHop).ip : req.getIp();
|
|
560
571
|
}
|
|
561
572
|
//#endregion
|
|
562
573
|
//#region src/rate-limit/mate.ts
|
|
@@ -869,7 +880,7 @@ function oauthCsrfCookieAttrs(opts) {
|
|
|
869
880
|
secure: opts.secure,
|
|
870
881
|
sameSite: "Lax",
|
|
871
882
|
path: opts.path ?? "/",
|
|
872
|
-
maxAge:
|
|
883
|
+
maxAge: `${opts.maxAgeSec ?? 600}s`
|
|
873
884
|
};
|
|
874
885
|
}
|
|
875
886
|
/**
|
|
@@ -1074,6 +1085,7 @@ const AOOTH_MESSAGES = {
|
|
|
1074
1085
|
INVALID_PASSWORD: "Invalid password",
|
|
1075
1086
|
INCORRECT_PASSWORD: "Incorrect password",
|
|
1076
1087
|
SESSION_LIMIT_REACHED: "Session limit reached",
|
|
1088
|
+
PASSWORD_CHANGED_SIGN_IN_AGAIN: "Your password was changed. Please sign in again.",
|
|
1077
1089
|
INVALID_CODE: "Invalid code",
|
|
1078
1090
|
/** Params: `seconds`. */
|
|
1079
1091
|
RESEND_WAIT: "Please wait {seconds}s before requesting a new code.",
|
|
@@ -1285,6 +1297,9 @@ const mfaLoopSchema = [{ id: "prepare-mfa" }, {
|
|
|
1285
1297
|
/**
|
|
1286
1298
|
* Forced password change — used by login.flow + invite.start (NOT recovery — recovery's
|
|
1287
1299
|
* gating differs: gated directly on `otp.verified`, NOT `newPasswordRequired`).
|
|
1300
|
+
* login.flow revokes the user's existing sessions after its MFA loop (gated on
|
|
1301
|
+
* `ctx.passwordChanged`), never here: the old password alone must not be
|
|
1302
|
+
* enough to sign the user out everywhere.
|
|
1288
1303
|
*/
|
|
1289
1304
|
const passwordPhaseSchema = [{
|
|
1290
1305
|
condition: (ctx) => !!ctx.newPasswordRequired,
|
|
@@ -2086,7 +2101,8 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
2086
2101
|
* successful change (OWASP Session Management) and applies NO rate limit —
|
|
2087
2102
|
* current-password re-entry (enforced by `UserService.changePassword`) is the
|
|
2088
2103
|
* primary protection, not throttling. Customers override to add a min-interval
|
|
2089
|
-
* (`rateLimit.minIntervalMs`) or to keep other sessions alive.
|
|
2104
|
+
* (`rateLimit.minIntervalMs`) or to keep other sessions alive. The session the
|
|
2105
|
+
* change was made from is always ended (see `finish-change-password`).
|
|
2090
2106
|
*
|
|
2091
2107
|
* Whether the flow may be STARTED at all is governed by arbac on the trigger
|
|
2092
2108
|
* route (deny the `change-password` action to forbid it for SSO-only orgs) —
|
|
@@ -3028,6 +3044,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3028
3044
|
try {
|
|
3029
3045
|
const result = await this.users.login(input.username, input.password, this.lockoutOverride(ctx));
|
|
3030
3046
|
ctx.subject = result.user.id;
|
|
3047
|
+
ctx.passwordStamp = result.user.password.lastChanged ?? 0;
|
|
3031
3048
|
ctx.loginRecorded = true;
|
|
3032
3049
|
swapStrategy("store");
|
|
3033
3050
|
if (ctx.guards?.passwordInitial && result.user.password.isInitial) ctx.isPasswordInitial = true;
|
|
@@ -3736,6 +3753,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3736
3753
|
this.processInlineConsent(ctx, input, wf);
|
|
3737
3754
|
ctx.isPasswordInitial = false;
|
|
3738
3755
|
ctx.isPasswordExpired = false;
|
|
3756
|
+
ctx.passwordChanged = true;
|
|
3739
3757
|
ctx.newPasswordRequired = false;
|
|
3740
3758
|
delete password.changeReason;
|
|
3741
3759
|
delete password.heading;
|
|
@@ -3801,16 +3819,42 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
3801
3819
|
}
|
|
3802
3820
|
}
|
|
3803
3821
|
/**
|
|
3804
|
-
* Change-password terminal —
|
|
3805
|
-
*
|
|
3806
|
-
*
|
|
3807
|
-
*
|
|
3808
|
-
*
|
|
3822
|
+
* Change-password terminal — sign the current device in on a FRESH session
|
|
3823
|
+
* and end the one the change was made from, then emit a success message.
|
|
3824
|
+
* The new pair is minted under a new session id, so the pre-change session
|
|
3825
|
+
* (its access token, refresh token and every rotation) is revoked here —
|
|
3826
|
+
* whatever `revokeOtherSessions` says, since that policy covers only the
|
|
3827
|
+
* user's OTHER sessions. Runs AFTER the optional `revoke-sessions` step, so
|
|
3828
|
+
* the default net effect is "kill every old session, keep this device on a
|
|
3829
|
+
* new one" (OWASP Session Management: no ghost sessions survive a credential
|
|
3830
|
+
* change).
|
|
3831
|
+
*
|
|
3832
|
+
* The pre-change session is revoked BEFORE the issue, so a failed issue
|
|
3833
|
+
* (store error, `maxConcurrent` refusal) leaves the user signed out, never on
|
|
3834
|
+
* the old session. A refresh in flight during the change is covered by
|
|
3835
|
+
* `AuthCredential`'s revocation protocol (it can't leave live credentials in
|
|
3836
|
+
* a revoked session).
|
|
3837
|
+
*
|
|
3838
|
+
* When one session can't be targeted — a stateless store (JWT /
|
|
3839
|
+
* encapsulated), or a legacy credential minted before `sessionId` existed
|
|
3840
|
+
* (its fallback id, the access token's fingerprint, never reaches the refresh
|
|
3841
|
+
* row) — ALL of the user's sessions are revoked (`revokeAllForUser`, also
|
|
3842
|
+
* under `revokeOtherSessions: false`). A stateless store also denylists the
|
|
3843
|
+
* presented access token (best effort): its revocation epoch is process-local.
|
|
3809
3844
|
*/
|
|
3810
3845
|
async finishChangePassword(ctx) {
|
|
3811
3846
|
this.requireSubject(ctx);
|
|
3812
|
-
const issue = await this.issueForContext(ctx);
|
|
3813
3847
|
const auth = useAuth();
|
|
3848
|
+
const prior = auth.getAuthContext();
|
|
3849
|
+
const priorSessionId = prior?.sessionId;
|
|
3850
|
+
const stateful = this.auth.canEnumerateSessions;
|
|
3851
|
+
if (stateful && priorSessionId !== void 0 && priorSessionId !== prior?.credentialId) await this.auth.revokeSession(ctx.subject, priorSessionId);
|
|
3852
|
+
else {
|
|
3853
|
+
await this.auth.revokeAllForUser(ctx.subject);
|
|
3854
|
+
const accessToken = stateful ? void 0 : auth.extractToken();
|
|
3855
|
+
if (accessToken) await this.auth.revoke(accessToken).catch(() => void 0);
|
|
3856
|
+
}
|
|
3857
|
+
const issue = await this.issueForContext(ctx);
|
|
3814
3858
|
const envelope = {
|
|
3815
3859
|
finished: true,
|
|
3816
3860
|
data: auth.buildLoginResponse(ctx.subject, issue),
|
|
@@ -4880,15 +4924,20 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4880
4924
|
}
|
|
4881
4925
|
/**
|
|
4882
4926
|
* Revoke the user's existing sessions. Shared by recovery (gated upstream by
|
|
4883
|
-
* `ctx.postReset.revokeAllSessions`)
|
|
4884
|
-
* by `ctx.changePassword.revokeOtherSessions`)
|
|
4927
|
+
* `ctx.postReset.revokeAllSessions`), authenticated change-password (gated
|
|
4928
|
+
* by `ctx.changePassword.revokeOtherSessions`) and the forced password change
|
|
4929
|
+
* at login / invite (gated by `ctx.passwordChanged`).
|
|
4885
4930
|
*
|
|
4886
4931
|
* - Change-password runs in an authenticated context, so we KEEP the caller's
|
|
4887
|
-
* current
|
|
4932
|
+
* current session via `revokeOtherSessions(username, currentSessionId)` —
|
|
4888
4933
|
* OWASP "invalidate other sessions" without logging the user out of the tab
|
|
4889
|
-
* they just changed their password in.
|
|
4890
|
-
*
|
|
4891
|
-
*
|
|
4934
|
+
* they just changed their password in. `finish-change-password` then moves
|
|
4935
|
+
* that tab onto a fresh session and revokes the kept one (and covers stores
|
|
4936
|
+
* that cannot enumerate, where `revokeOtherSessions` is a no-op). If the
|
|
4937
|
+
* current session can't be resolved (no session id), fall back to revoking
|
|
4938
|
+
* everything (fail-secure).
|
|
4939
|
+
* - Recovery and the forced change are anonymous (no current session to
|
|
4940
|
+
* keep) → `revokeAllForUser`.
|
|
4892
4941
|
*/
|
|
4893
4942
|
async revokeSessions(ctx) {
|
|
4894
4943
|
if (!ctx.subject) return void 0;
|
|
@@ -4907,6 +4956,25 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4907
4956
|
await this.users.unlockAccount(ctx.subject);
|
|
4908
4957
|
}
|
|
4909
4958
|
/**
|
|
4959
|
+
* Login-only guard before the `record-login` funnel (and again before
|
|
4960
|
+
* `mint-authz-code`, past the consent pause): the account's
|
|
4961
|
+
* `password.lastChanged` must still be the one the `credentials` step
|
|
4962
|
+
* verified (`ctx.passwordStamp`). A run paused after the password check (MFA,
|
|
4963
|
+
* enrolment, consents …) and resumed after the password was changed
|
|
4964
|
+
* elsewhere finishes with an error instead of issuing tokens or minting an
|
|
4965
|
+
* authorization code. Skipped when this run changed the password itself.
|
|
4966
|
+
*/
|
|
4967
|
+
async checkPasswordUnchanged(ctx) {
|
|
4968
|
+
this.requireSubject(ctx);
|
|
4969
|
+
if (((await this.users.getUser(ctx.subject)).password.lastChanged ?? 0) !== ctx.passwordStamp) {
|
|
4970
|
+
ctx.aborted = true;
|
|
4971
|
+
finishWf({ message: {
|
|
4972
|
+
level: "error",
|
|
4973
|
+
text: this.msg("PASSWORD_CHANGED_SIGN_IN_AGAIN")
|
|
4974
|
+
} });
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
/**
|
|
4910
4978
|
* The SINGLE login-completion funnel. Every flow that establishes an
|
|
4911
4979
|
* authenticated session routes through here — placed in each login schema
|
|
4912
4980
|
* right after the guards and BEFORE the delivery terminal (`issue` /
|
|
@@ -4991,7 +5059,7 @@ let AuthWorkflow = _AuthWorkflow = class AuthWorkflow {
|
|
|
4991
5059
|
...cookies,
|
|
4992
5060
|
[name]: {
|
|
4993
5061
|
value,
|
|
4994
|
-
options: auth.cookieAttrs({ maxAge: ttlMs })
|
|
5062
|
+
options: auth.cookieAttrs({ maxAge: `${Math.max(0, Math.floor(ttlMs / 1e3))}s` })
|
|
4995
5063
|
}
|
|
4996
5064
|
};
|
|
4997
5065
|
};
|
|
@@ -6423,6 +6491,14 @@ __decorate([
|
|
|
6423
6491
|
__decorateMetadata("design:paramtypes", [Object]),
|
|
6424
6492
|
__decorateMetadata("design:returntype", Promise)
|
|
6425
6493
|
], AuthWorkflow.prototype, "unlockAccount", null);
|
|
6494
|
+
__decorate([
|
|
6495
|
+
Step("check-password-unchanged"),
|
|
6496
|
+
Public(),
|
|
6497
|
+
__decorateParam(0, WorkflowParam("context")),
|
|
6498
|
+
__decorateMetadata("design:type", Function),
|
|
6499
|
+
__decorateMetadata("design:paramtypes", [Object]),
|
|
6500
|
+
__decorateMetadata("design:returntype", Promise)
|
|
6501
|
+
], AuthWorkflow.prototype, "checkPasswordUnchanged", null);
|
|
6426
6502
|
__decorate([
|
|
6427
6503
|
Step("record-login"),
|
|
6428
6504
|
Public(),
|
|
@@ -6654,6 +6730,10 @@ __decorate([
|
|
|
6654
6730
|
condition: (ctx) => !!ctx.enrollment?.ensurePhone && !!ctx.channel?.phone && !ctx.channel?.phoneConfirmed
|
|
6655
6731
|
},
|
|
6656
6732
|
...mfaLoopSchema,
|
|
6733
|
+
{
|
|
6734
|
+
id: "revoke-sessions",
|
|
6735
|
+
condition: (ctx) => !!ctx.passwordChanged && !ctx.aborted
|
|
6736
|
+
},
|
|
6657
6737
|
{
|
|
6658
6738
|
id: "device-trust",
|
|
6659
6739
|
condition: (ctx) => !!ctx.deviceTrust?.enabled && !!ctx.otp?.verified && !!ctx.trust?.newDevice && (!ctx.deviceTrust?.optIn || !!ctx.trust?.rememberDevice)
|
|
@@ -6675,6 +6755,11 @@ __decorate([
|
|
|
6675
6755
|
}]
|
|
6676
6756
|
},
|
|
6677
6757
|
{ break: (ctx) => !!ctx.aborted },
|
|
6758
|
+
{
|
|
6759
|
+
id: "check-password-unchanged",
|
|
6760
|
+
condition: (ctx) => ctx.passwordStamp !== void 0 && !ctx.passwordChanged
|
|
6761
|
+
},
|
|
6762
|
+
{ break: (ctx) => !!ctx.aborted },
|
|
6678
6763
|
{
|
|
6679
6764
|
id: "record-login",
|
|
6680
6765
|
condition: (ctx) => !!ctx.subject && !ctx.authz?.silent
|
|
@@ -6695,6 +6780,11 @@ __decorate([
|
|
|
6695
6780
|
id: "authz-consent",
|
|
6696
6781
|
condition: (ctx) => !!ctx.authz
|
|
6697
6782
|
},
|
|
6783
|
+
{
|
|
6784
|
+
id: "check-password-unchanged",
|
|
6785
|
+
condition: (ctx) => ctx.authz?.approved === true && ctx.passwordStamp !== void 0 && !ctx.passwordChanged
|
|
6786
|
+
},
|
|
6787
|
+
{ break: (ctx) => !!ctx.aborted },
|
|
6698
6788
|
{
|
|
6699
6789
|
id: "mint-authz-code",
|
|
6700
6790
|
condition: (ctx) => ctx.authz?.approved === true
|
|
@@ -7021,16 +7111,17 @@ let AuthController = class AuthController {
|
|
|
7021
7111
|
const auth = useAuth();
|
|
7022
7112
|
const refreshToken = resolveRefreshToken(auth, body);
|
|
7023
7113
|
if (!refreshToken) throw new HttpError$1(401, "Missing refresh token");
|
|
7114
|
+
const fromBody = typeof body?.refreshToken === "string";
|
|
7024
7115
|
let issue;
|
|
7025
7116
|
try {
|
|
7026
7117
|
issue = await this.auth.refresh(refreshToken);
|
|
7027
7118
|
} catch (err) {
|
|
7028
|
-
if (err instanceof AuthError) throw
|
|
7029
|
-
|
|
7119
|
+
if (!(err instanceof AuthError)) throw err;
|
|
7120
|
+
if (!fromBody) auth.clearCookies();
|
|
7121
|
+
throw new HttpError$1(401, "Invalid refresh token");
|
|
7030
7122
|
}
|
|
7031
7123
|
auth.writeCookies(issue);
|
|
7032
7124
|
const validated = await this.auth.validate(issue.accessToken);
|
|
7033
|
-
const fromBody = typeof body?.refreshToken === "string";
|
|
7034
7125
|
return auth.buildLoginResponse(validated?.userId ?? "", issue, fromBody ? { exposeTokens: true } : void 0);
|
|
7035
7126
|
}
|
|
7036
7127
|
status() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/auth-moost",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Moost auth integration for aoothjs — AuthGuard interceptor, useAuth composable, REST endpoints, workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aoothjs",
|
|
@@ -57,33 +57,33 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@atscript/moost-wf": "^0.1.
|
|
61
|
-
"@wooksjs/http-body": "^0.
|
|
62
|
-
"@aooth/arbac-moost": "^0.2.
|
|
63
|
-
"@aooth/
|
|
64
|
-
"@aooth/
|
|
65
|
-
"@aooth/user": "0.2.
|
|
60
|
+
"@atscript/moost-wf": "^0.1.162",
|
|
61
|
+
"@wooksjs/http-body": "^0.8.0",
|
|
62
|
+
"@aooth/arbac-moost": "^0.2.1",
|
|
63
|
+
"@aooth/auth": "0.2.1",
|
|
64
|
+
"@aooth/idp": "0.2.1",
|
|
65
|
+
"@aooth/user": "0.2.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@atscript/core": "^0.1
|
|
69
|
-
"@atscript/typescript": "^0.1
|
|
70
|
-
"@atscript/ui": "^0.1.
|
|
71
|
-
"@atscript/ui-fns": "^0.1.
|
|
72
|
-
"@moostjs/event-http": "^0.
|
|
73
|
-
"@moostjs/event-wf": "^0.
|
|
74
|
-
"moost": "^0.
|
|
75
|
-
"unplugin-atscript": "^0.1
|
|
76
|
-
"wooks": "^0.
|
|
68
|
+
"@atscript/core": "^0.2.1",
|
|
69
|
+
"@atscript/typescript": "^0.2.1",
|
|
70
|
+
"@atscript/ui": "^0.1.162",
|
|
71
|
+
"@atscript/ui-fns": "^0.1.162",
|
|
72
|
+
"@moostjs/event-http": "^0.7.0",
|
|
73
|
+
"@moostjs/event-wf": "^0.7.0",
|
|
74
|
+
"moost": "^0.7.0",
|
|
75
|
+
"unplugin-atscript": "^0.2.1",
|
|
76
|
+
"wooks": "^0.8.0"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@atscript/moost-wf": "^0.1.
|
|
80
|
-
"@atscript/typescript": "^0.1
|
|
81
|
-
"@moostjs/event-http": "^0.
|
|
82
|
-
"@moostjs/event-wf": "^0.
|
|
83
|
-
"@wooksjs/event-core": "^0.
|
|
84
|
-
"@wooksjs/event-http": "^0.
|
|
85
|
-
"@wooksjs/http-body": "^0.
|
|
86
|
-
"moost": "^0.
|
|
79
|
+
"@atscript/moost-wf": "^0.1.162",
|
|
80
|
+
"@atscript/typescript": "^0.2.1",
|
|
81
|
+
"@moostjs/event-http": "^0.7.0",
|
|
82
|
+
"@moostjs/event-wf": "^0.7.0",
|
|
83
|
+
"@wooksjs/event-core": "^0.8.0",
|
|
84
|
+
"@wooksjs/event-http": "^0.8.0",
|
|
85
|
+
"@wooksjs/http-body": "^0.8.0",
|
|
86
|
+
"moost": "^0.7.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@atscript/typescript": {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Do not edit this file!
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TAtscriptAnnotatedType, TMetadataMap, Validator, TValidatorOptions } from "@atscript/typescript/utils"
|
|
10
|
+
import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TAtscriptAnnotatedType, TAtscriptField, TMetadataMap, Validator, TValidatorOptions } from "@atscript/typescript/utils"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Atscript interface **WithInlineConsentForm**
|