@absolutejs/auth 0.61.0 → 0.62.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/dist/server.js CHANGED
@@ -6141,6 +6141,15 @@ init_constants();
6141
6141
  init_crypto();
6142
6142
  import { Elysia as Elysia11, t as t8 } from "elysia";
6143
6143
 
6144
+ // src/csrf.ts
6145
+ var isTrustedOrigin = (request, trustedOrigins) => {
6146
+ if (trustedOrigins === undefined || trustedOrigins.length === 0) {
6147
+ return true;
6148
+ }
6149
+ const origin = request.headers.get("origin");
6150
+ return origin !== null && trustedOrigins.includes(origin);
6151
+ };
6152
+
6144
6153
  // src/credentials/import.ts
6145
6154
  init_crypto();
6146
6155
  var normalizeEmail = (email) => email.trim().toLowerCase();
@@ -6345,7 +6354,8 @@ var credentialsLogin = ({
6345
6354
  passwordVerifier,
6346
6355
  rehashOnLogin = false,
6347
6356
  requireEmailVerification = false,
6348
- sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS
6357
+ sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
6358
+ trustedOrigins
6349
6359
  }) => new Elysia11().use(sessionStore()).post(loginRoute, async ({
6350
6360
  body: { email, password },
6351
6361
  cookie: { user_session_id },
@@ -6353,6 +6363,9 @@ var credentialsLogin = ({
6353
6363
  status,
6354
6364
  store: { session, unregisteredSession }
6355
6365
  }) => withSpan("auth.credentials.login", undefined, async (span) => {
6366
+ if (!isTrustedOrigin(request, trustedOrigins)) {
6367
+ return status("Forbidden", "Request origin is not allowed");
6368
+ }
6356
6369
  const headerBag = {};
6357
6370
  request.headers.forEach((value, key) => {
6358
6371
  headerBag[key] = value;
@@ -6510,19 +6523,26 @@ var credentialsRegister = ({
6510
6523
  credentialStore,
6511
6524
  onCreateCredentialUser,
6512
6525
  onCredentialsLoginSuccess,
6526
+ onExistingAccount,
6513
6527
  onRegistrationSuccess,
6514
6528
  onSendEmail,
6515
6529
  passwordPolicy,
6516
6530
  registerRoute = "/auth/register",
6517
6531
  requireEmailVerification = false,
6532
+ revealRegistrationConflicts = false,
6518
6533
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
6534
+ trustedOrigins,
6519
6535
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS
6520
6536
  }) => new Elysia13().use(sessionStore()).post(registerRoute, async ({
6521
6537
  body: { email, password, ...extraFields },
6522
6538
  cookie: { user_session_id },
6539
+ request,
6523
6540
  status,
6524
6541
  store: { session }
6525
6542
  }) => withSpan("auth.credentials.register", undefined, async () => {
6543
+ if (!isTrustedOrigin(request, trustedOrigins)) {
6544
+ return status("Forbidden", "Request origin is not allowed");
6545
+ }
6526
6546
  const normalizedEmail = email.trim().toLowerCase();
6527
6547
  if (!normalizedEmail.includes("@")) {
6528
6548
  return status("Bad Request", "A valid email is required");
@@ -6536,7 +6556,13 @@ var credentialsRegister = ({
6536
6556
  }
6537
6557
  const existing = await credentialStore.getCredentialByEmail(normalizedEmail);
6538
6558
  if (existing) {
6539
- return status("Conflict", "Email is already registered");
6559
+ if (revealRegistrationConflicts) {
6560
+ return status("Conflict", "Email is already registered");
6561
+ }
6562
+ await onExistingAccount?.({ email: normalizedEmail });
6563
+ return status("Created", {
6564
+ status: "verification_required"
6565
+ });
6540
6566
  }
6541
6567
  const created = await onCreateCredentialUser({
6542
6568
  ...extraFields,
@@ -38723,5 +38749,5 @@ export {
38723
38749
  VerificationProviderError
38724
38750
  };
38725
38751
 
38726
- //# debugId=D218332195145BB664756E2164756E21
38752
+ //# debugId=E5516A34918E793A64756E2164756E21
38727
38753
  //# sourceMappingURL=server.js.map