@payez/next-mvp 4.1.20 → 4.4.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/POST-INSTALL.md +408 -0
- package/README.md +7 -0
- package/dist/api-handlers/account/recovery/initiate.js +35 -2
- package/dist/api-handlers/account/recovery/send-code.d.ts +0 -33
- package/dist/api-handlers/account/recovery/send-code.js +35 -2
- package/dist/api-handlers/account/recovery/verify-code.d.ts +0 -33
- package/dist/api-handlers/account/recovery/verify-code.js +35 -2
- package/dist/api-handlers/account/reset-password.js +35 -2
- package/dist/api-handlers/account/validate-password.js +21 -3
- package/dist/api-handlers/admin/analytics.js +2 -1
- package/dist/api-handlers/admin/audit.js +2 -1
- package/dist/api-handlers/admin/sessions.js +2 -1
- package/dist/api-handlers/admin/stats.js +2 -1
- package/dist/api-handlers/admin/users.js +2 -1
- package/dist/api-handlers/admin/vibe-data.js +2 -1
- package/dist/api-handlers/auth/jwks.js +10 -0
- package/dist/api-handlers/auth/login.js +5 -2
- package/dist/api-handlers/auth/passkey-signin.js +16 -1
- package/dist/api-handlers/auth/refresh.d.ts +23 -3
- package/dist/api-handlers/auth/refresh.js +107 -16
- package/dist/api-handlers/auth/signout.js +3 -2
- package/dist/api-handlers/auth/verify-code.js +5 -2
- package/dist/api-handlers/session/viability.js +27 -1
- package/dist/api-handlers/test/force-expire.d.ts +29 -15
- package/dist/api-handlers/test/force-expire.js +109 -14
- package/dist/auth/better-auth.d.ts +263 -6
- package/dist/auth/better-auth.js +437 -59
- package/dist/auth/utils/idp-client.js +1 -1
- package/dist/client/AuthContext.js +49 -17
- package/dist/components/account/UserAvatarMenu.js +12 -0
- package/dist/components/auth/ModeAwareLoginPage.js +10 -8
- package/dist/components/auth/ModeAwareSignupPage.js +5 -2
- package/dist/components/auth/TraditionalAuthSection.js +5 -1
- package/dist/hooks/useAuthSettings.js +14 -2
- package/dist/hooks/usePublicAuthSettings.d.ts +2 -2
- package/dist/hooks/usePublicAuthSettings.js +28 -14
- package/dist/lib/client-key.d.ts +61 -0
- package/dist/lib/client-key.js +72 -0
- package/dist/lib/demo-mode.js +2 -1
- package/dist/lib/ensure-fresh-access-token.js +12 -1
- package/dist/lib/idp-client-config.d.ts +25 -2
- package/dist/lib/idp-client-config.js +381 -36
- package/dist/lib/idp-fetch.d.ts +2 -0
- package/dist/lib/idp-fetch.js +31 -1
- package/dist/lib/idp-url-guard.d.ts +29 -0
- package/dist/lib/idp-url-guard.js +38 -0
- package/dist/lib/redis.js +77 -5
- package/dist/lib/session-cookie-shape.d.ts +69 -0
- package/dist/lib/session-cookie-shape.js +126 -0
- package/dist/lib/session-store.d.ts +35 -2
- package/dist/lib/session-store.js +135 -4
- package/dist/lib/single-flight.d.ts +35 -0
- package/dist/lib/single-flight.js +30 -0
- package/dist/lib/token-lifecycle.js +12 -0
- package/dist/middleware/create-middleware.js +12 -0
- package/dist/models/SessionModel.d.ts +41 -0
- package/dist/models/SessionModel.js +9 -0
- package/dist/pages/admin-login/page.d.ts +1 -1
- package/dist/pages/admin-login/page.js +5 -41
- package/dist/pages/security/EnhancedSecurityPage.d.ts +35 -1
- package/dist/pages/security/EnhancedSecurityPage.js +42 -2
- package/dist/pages/security/index.d.ts +1 -0
- package/dist/pages/security/index.js +3 -0
- package/dist/pages/test-env/EmergencyLogoutPage.d.ts +17 -5
- package/dist/pages/test-env/EmergencyLogoutPage.js +17 -5
- package/dist/pages/test-env/JwtInspectPage.d.ts +30 -5
- package/dist/pages/test-env/JwtInspectPage.js +166 -7
- package/dist/pages/test-env/RefreshTokenPage.d.ts +22 -6
- package/dist/pages/test-env/RefreshTokenPage.js +22 -6
- package/dist/pages/test-env/TestEnvPage.d.ts +16 -4
- package/dist/pages/test-env/TestEnvPage.js +16 -4
- package/dist/pages/test-env/guarded.d.ts +4 -0
- package/dist/pages/test-env/guarded.js +86 -0
- package/dist/pages/test-env/index.d.ts +50 -7
- package/dist/pages/test-env/index.js +58 -12
- package/dist/routes/auth/logout.js +3 -2
- package/dist/routes/auth/refresh.js +27 -1
- package/dist/routes/auth/session.d.ts +12 -3
- package/dist/routes/auth/session.js +92 -9
- package/dist/routes/auth/settings.d.ts +34 -4
- package/dist/routes/auth/settings.js +87 -33
- package/dist/routes/auth/viability.d.ts +1 -1
- package/dist/routes/auth/viability.js +122 -11
- package/dist/server/auth-guard.js +22 -15
- package/dist/server/auth.d.ts +170 -4
- package/dist/server/auth.js +42 -75
- package/dist/server/decode-session.js +84 -10
- package/dist/types/auth.d.ts +18 -0
- package/package.json +969 -958
- package/scripts/check-internal-url-usage.sh +73 -73
- package/scripts/check-publish-health.mjs +120 -0
- package/scripts/dev-broker.ps1 +71 -6
- package/scripts/print-client-config.mjs +162 -0
- package/scripts/server-only-stub.cjs +4 -0
- package/src/api-handlers/account/recovery/initiate.ts +35 -2
- package/src/api-handlers/account/recovery/send-code.ts +36 -2
- package/src/api-handlers/account/recovery/verify-code.ts +36 -2
- package/src/api-handlers/account/reset-password.ts +35 -2
- package/src/api-handlers/account/validate-password.ts +22 -3
- package/src/api-handlers/admin/analytics.ts +2 -1
- package/src/api-handlers/admin/audit.ts +2 -1
- package/src/api-handlers/admin/sessions.ts +2 -1
- package/src/api-handlers/admin/stats.ts +2 -1
- package/src/api-handlers/admin/users.ts +2 -1
- package/src/api-handlers/admin/vibe-data.ts +2 -1
- package/src/api-handlers/auth/jwks.ts +10 -0
- package/src/api-handlers/auth/login.ts +5 -2
- package/src/api-handlers/auth/passkey-signin.ts +112 -98
- package/src/api-handlers/auth/refresh.ts +112 -15
- package/src/api-handlers/auth/signout.ts +4 -3
- package/src/api-handlers/auth/verify-code.ts +5 -2
- package/src/api-handlers/mfa/backup-code-verify.ts +175 -175
- package/src/api-handlers/mfa/backup-codes.ts +41 -41
- package/src/api-handlers/mfa/methods.ts +46 -46
- package/src/api-handlers/mfa/totp-confirm.ts +42 -42
- package/src/api-handlers/mfa/totp-enroll.ts +42 -42
- package/src/api-handlers/passkeys/list.ts +31 -31
- package/src/api-handlers/passkeys/manage.ts +54 -54
- package/src/api-handlers/passkeys/register-options.ts +42 -42
- package/src/api-handlers/passkeys/register-verify.ts +41 -41
- package/src/api-handlers/session/viability.ts +29 -1
- package/src/api-handlers/test/force-expire.ts +118 -13
- package/src/auth/better-auth.ts +486 -51
- package/src/auth/utils/idp-client.ts +1 -1
- package/src/client/AuthContext.tsx +55 -19
- package/src/components/account/UserAvatarMenu.tsx +11 -0
- package/src/components/auth/ModeAwareLoginPage.tsx +40 -49
- package/src/components/auth/ModeAwareSignupPage.tsx +5 -2
- package/src/components/auth/TraditionalAuthSection.tsx +5 -1
- package/src/hooks/useAuthSettings.ts +14 -2
- package/src/hooks/usePublicAuthSettings.ts +38 -16
- package/src/lib/client-key.ts +88 -0
- package/src/lib/demo-mode.ts +2 -1
- package/src/lib/ensure-fresh-access-token.ts +12 -1
- package/src/lib/idp-client-config.ts +399 -36
- package/src/lib/idp-fetch.ts +36 -1
- package/src/lib/idp-url-guard.ts +37 -0
- package/src/lib/redis.ts +84 -6
- package/src/lib/session-cookie-shape.ts +184 -0
- package/src/lib/session-store.ts +152 -6
- package/src/lib/single-flight.ts +64 -0
- package/src/lib/token-lifecycle.ts +12 -0
- package/src/middleware/create-middleware.ts +11 -0
- package/src/models/SessionModel.ts +49 -0
- package/src/pages/admin-login/page.tsx +17 -127
- package/src/pages/security/EnhancedSecurityPage.tsx +95 -9
- package/src/pages/security/index.ts +3 -0
- package/src/pages/test-env/EmergencyLogoutPage.tsx +17 -5
- package/src/pages/test-env/JwtInspectPage.tsx +235 -20
- package/src/pages/test-env/RefreshTokenPage.tsx +22 -6
- package/src/pages/test-env/TestEnvPage.tsx +16 -4
- package/src/pages/test-env/guarded.tsx +81 -0
- package/src/pages/test-env/index.ts +59 -7
- package/src/routes/auth/logout.ts +4 -3
- package/src/routes/auth/passkey-signin.ts +13 -13
- package/src/routes/auth/refresh.ts +30 -1
- package/src/routes/auth/session.ts +98 -9
- package/src/routes/auth/settings.ts +144 -42
- package/src/routes/auth/viability.ts +129 -11
- package/src/routes/mfa/backup-code-verify.ts +1 -1
- package/src/routes/mfa/backup-codes.ts +10 -10
- package/src/routes/mfa/methods.ts +22 -22
- package/src/routes/mfa/totp-confirm.ts +10 -10
- package/src/routes/mfa/totp-enroll.ts +10 -10
- package/src/routes/mfa/totp-verify.ts +14 -14
- package/src/routes/passkeys/list.ts +10 -10
- package/src/routes/passkeys/manage.ts +23 -23
- package/src/routes/passkeys/register-options.ts +10 -10
- package/src/routes/passkeys/register-verify.ts +10 -10
- package/src/server/auth-guard.ts +24 -17
- package/src/server/auth.ts +54 -74
- package/src/server/decode-session.ts +95 -11
- package/src/templates/instrumentation.ts +21 -2
- package/src/types/auth.ts +20 -0
- package/dist/lib/auth-secret.d.ts +0 -17
- package/dist/lib/auth-secret.js +0 -116
- package/src/lib/auth-secret.ts +0 -137
|
@@ -3,30 +3,135 @@ import { getSession as getBetterAuthSession } from '../../server/auth';
|
|
|
3
3
|
import { getSession, updateSession } from '../../lib/session-store';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* ⚠️ DESTRUCTIVE TEST-ONLY HANDLER — DO NOT MOUNT IN PRODUCTION. ⚠️
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* which will trigger a refresh on the next
|
|
8
|
+
* Force-expire access token for testing refresh flow. Sets the access token
|
|
9
|
+
* expiry to 2 minutes in the past, which will trigger a refresh on the next
|
|
10
|
+
* API call.
|
|
11
|
+
*
|
|
12
|
+
* THIS MUTATES SESSION STATE. It is a test affordance, not a product feature.
|
|
13
|
+
*
|
|
14
|
+
* ── WHY THIS WARNING EXISTS (QAPert 34983) ────────────────────────────────
|
|
15
|
+
* The usage block below is not decoration: THIS DOCSTRING IS THE SPREAD
|
|
16
|
+
* MECHANISM. It ships compiled into dist and into the .d.ts, so it reaches
|
|
17
|
+
* every consumer's editor as hover text, and it is a one-line copy-paste that
|
|
18
|
+
* mounts a destructive endpoint. Every one of the three surfaces this route
|
|
19
|
+
* ended up on followed exactly these instructions.
|
|
20
|
+
*
|
|
21
|
+
* The handler itself was fixed (244877: default-deny behind ENABLE_TEST_ROUTES,
|
|
22
|
+
* plus the caller-supplied-token IDOR removed). But a fixed handler shipped
|
|
23
|
+
* with unqualified mounting instructions still spreads: the guidance was never
|
|
24
|
+
* corrected alongside the code, and a package that documents a dangerous route
|
|
25
|
+
* as a plain convenience is instructing the weaker configuration.
|
|
26
|
+
*
|
|
27
|
+
* ── IF YOU MOUNT IT, MOUNT IT LIKE THIS ───────────────────────────────────
|
|
28
|
+
* Required: set ENABLE_TEST_ROUTES=true IN THAT ENVIRONMENT ONLY. Absent, empty
|
|
29
|
+
* or any other value default-DENIES (404). Never set it in production.
|
|
10
30
|
*
|
|
11
|
-
* Usage in consuming app:
|
|
12
31
|
* ```typescript
|
|
13
|
-
* // app/api/test/force-expire/route.ts
|
|
32
|
+
* // app/api/test/force-expire/route.ts — TEST/DEV ENVIRONMENTS ONLY
|
|
33
|
+
* // Requires ENABLE_TEST_ROUTES=true in that environment; 404s otherwise.
|
|
14
34
|
* export { POST } from '@payez/next-mvp/api-handlers/test/force-expire';
|
|
15
35
|
* ```
|
|
36
|
+
*
|
|
37
|
+
* If you do not need to exercise the refresh flow, DO NOT MOUNT THIS AT ALL.
|
|
38
|
+
* The safest configuration is the absence of the route.
|
|
16
39
|
*/
|
|
17
40
|
export const POST = async (req: NextRequest) => {
|
|
41
|
+
// 244877 (package-level): DEFAULT DENY behind ENABLE_TEST_ROUTES.
|
|
42
|
+
//
|
|
43
|
+
// This handler MUTATES session state — it rewrites idpAccessTokenExpires two
|
|
44
|
+
// minutes into the past — and was gated on nothing but "any signed-in
|
|
45
|
+
// session": no role check, no env kill-switch. Because consuming apps mount
|
|
46
|
+
// it with a one-line re-export, EVERY consumer inherited that, including
|
|
47
|
+
// deployments on production hosts.
|
|
48
|
+
//
|
|
49
|
+
// The card was raised against one app's local copy. Sweeping the pattern
|
|
50
|
+
// rather than the instance found the same route in three places — a local
|
|
51
|
+
// copy in the graft, a local copy in idealvibe.online, and idealresume.online
|
|
52
|
+
// re-exporting THIS handler — so the fix belongs here, at the source all
|
|
53
|
+
// three ultimately derive from, not only in whichever copy was noticed first.
|
|
54
|
+
//
|
|
55
|
+
// The gate is the FIRST statement, before any session decode, so a disabled
|
|
56
|
+
// build does not reveal that the route is live. Absent, empty, or any value
|
|
57
|
+
// other than 'true' disables it. Distinguishable body on purpose: a bare 404
|
|
58
|
+
// reads as "route missing / build broken" and sends someone debugging
|
|
59
|
+
// deployment instead of reading a flag.
|
|
60
|
+
//
|
|
61
|
+
// A consumer that genuinely needs this in a test environment sets
|
|
62
|
+
// ENABLE_TEST_ROUTES=true there, which is the same posture the token
|
|
63
|
+
// inspector already uses for a strictly LESS dangerous, read-only route.
|
|
64
|
+
if (process.env.ENABLE_TEST_ROUTES !== 'true') {
|
|
65
|
+
// DISCLOSURE IS CONDITIONAL ON ENVIRONMENT (QAPert-NightHawk 34539, after
|
|
66
|
+
// QAPert caught that my first version shipped the very leak we had just
|
|
67
|
+
// criticised elsewhere).
|
|
68
|
+
//
|
|
69
|
+
// My original body named the flag: "Set ENABLE_TEST_ROUTES=true...". That
|
|
70
|
+
// is the same class of disclosure as TOKEN_INSPECTOR_DISABLED — it confirms
|
|
71
|
+
// the route exists, names the capability, and hands a prober the exact
|
|
72
|
+
// switch that turns it on. Having argued against that pattern one directory
|
|
73
|
+
// over, shipping it here would have been incoherent.
|
|
74
|
+
//
|
|
75
|
+
// Deleting the message outright is also wrong: it is what stops a developer
|
|
76
|
+
// losing an hour deciding whether their build is broken. The tension
|
|
77
|
+
// resolves by AUDIENCE, not by picking a side:
|
|
78
|
+
// production -> 404, EMPTY body. Nothing about the capability, the
|
|
79
|
+
// flag, or even that a handler is here.
|
|
80
|
+
// non-production -> 404 + the helpful message naming the flag.
|
|
81
|
+
//
|
|
82
|
+
// The operator affordance survives in production too, via the log line
|
|
83
|
+
// below: logs are visible to operators and not to probers, which is exactly
|
|
84
|
+
// the split the response body cannot make.
|
|
85
|
+
console.warn(
|
|
86
|
+
'[FORCE-EXPIRE] blocked: ENABLE_TEST_ROUTES is not "true" (test routes default-deny).',
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (process.env.NODE_ENV === 'production') {
|
|
90
|
+
return new NextResponse(null, { status: 404 });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return NextResponse.json(
|
|
94
|
+
{
|
|
95
|
+
error: 'TEST_ROUTES_DISABLED',
|
|
96
|
+
message:
|
|
97
|
+
'Test routes are disabled in this build. Set ENABLE_TEST_ROUTES=true to enable them (development only).',
|
|
98
|
+
},
|
|
99
|
+
{ status: 404 },
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
18
103
|
try {
|
|
19
104
|
const betterAuthSession = await getBetterAuthSession(req);
|
|
20
105
|
|
|
21
|
-
|
|
106
|
+
// ACCESS CONTROL (QAPert 34553). This handler previously fell back to a
|
|
107
|
+
// CALLER-SUPPLIED `X-Session-Token` header when the request carried no
|
|
108
|
+
// session of its own, and then force-expired whatever token that header
|
|
109
|
+
// named — with NO check that the token belonged to the caller. The 401
|
|
110
|
+
// fired only when a caller supplied NEITHER a session NOR the header. So
|
|
111
|
+
// an UNAUTHENTICATED caller who presented any valid session token could
|
|
112
|
+
// expire ANOTHER USER'S session: an unauthenticated cross-session write.
|
|
113
|
+
//
|
|
114
|
+
// The fallback is removed rather than ownership-checked, because an
|
|
115
|
+
// ownership check would make it exactly equivalent to reading the caller's
|
|
116
|
+
// own session — the header could then never name anything else, so it
|
|
117
|
+
// would be a parameter that cannot legally vary. The session to expire is
|
|
118
|
+
// now ALWAYS the caller's own, which is also what the graft's local copy
|
|
119
|
+
// has always done.
|
|
120
|
+
//
|
|
121
|
+
// This is defence in depth, not the only control: the ENABLE_TEST_ROUTES
|
|
122
|
+
// gate above already 404s this handler by default. But the gate is
|
|
123
|
+
// switched ON in test environments, and "unauthenticated users can expire
|
|
124
|
+
// each other's sessions" is not acceptable there either — a control that
|
|
125
|
+
// only holds while a feature is switched off is not an access control.
|
|
126
|
+
//
|
|
127
|
+
// Corrects NextPert's own scope claim on card 244877 ("a caller could only
|
|
128
|
+
// ever expire their OWN session"): that was read off the graft's LOCAL
|
|
129
|
+
// copy, which derives the token from the caller's JWT. It was never true
|
|
130
|
+
// of THIS handler, which is the one consumers actually mount.
|
|
131
|
+
const sessionToken = betterAuthSession?.session?.token as string | undefined;
|
|
22
132
|
if (!sessionToken) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sessionToken = headerSessionToken;
|
|
26
|
-
} else {
|
|
27
|
-
console.warn('[TEST_EXPIRE] No session token or X-Session-Token header');
|
|
28
|
-
return NextResponse.json({ success: false, error: 'No session token' }, { status: 401 });
|
|
29
|
-
}
|
|
133
|
+
console.warn('[TEST_EXPIRE] No session on the request');
|
|
134
|
+
return NextResponse.json({ success: false, error: 'No session token' }, { status: 401 });
|
|
30
135
|
}
|
|
31
136
|
|
|
32
137
|
const session = await getSession(sessionToken);
|