@absolutejs/auth 0.59.2 → 0.60.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.
@@ -0,0 +1,2 @@
1
+ export declare const isSafeLocalPath: (value: string) => boolean;
2
+ export declare const toSafeLocalPath: (value: string | undefined, fallback?: string) => string;
package/dist/server.js CHANGED
@@ -6109,6 +6109,9 @@ var credentialsEmailVerification = ({
6109
6109
  if (!consumed) {
6110
6110
  return status("Bad Request", "Invalid or expired verification token");
6111
6111
  }
6112
+ if (consumed.expiresAt < Date.now()) {
6113
+ return status("Bad Request", "Invalid or expired verification token");
6114
+ }
6112
6115
  await credentialStore.setEmailVerified(consumed.email);
6113
6116
  await onEmailVerified?.({ email: consumed.email });
6114
6117
  return status("OK", { status: "email_verified" });
@@ -6462,6 +6465,9 @@ var credentialsPasswordReset = ({
6462
6465
  if (!consumed) {
6463
6466
  return status("Bad Request", "Invalid or expired reset token");
6464
6467
  }
6468
+ if (consumed.expiresAt < Date.now()) {
6469
+ return status("Bad Request", "Invalid or expired reset token");
6470
+ }
6465
6471
  const policy = await evaluatePassword(password, passwordPolicy);
6466
6472
  if (!policy.ok) {
6467
6473
  return status("Bad Request", {
@@ -11271,6 +11277,12 @@ var resolveProviderClientConfiguration = ({
11271
11277
  // src/routes/authorize.ts
11272
11278
  init_constants();
11273
11279
  import { Elysia as Elysia27, t as t20 } from "elysia";
11280
+
11281
+ // src/redirect.ts
11282
+ var isSafeLocalPath = (value) => /^\/(?![/\\])/.test(value);
11283
+ var toSafeLocalPath = (value, fallback = "/") => value !== undefined && isSafeLocalPath(value) ? value : fallback;
11284
+
11285
+ // src/routes/authorize.ts
11274
11286
  var parseReferer = (headerReferer) => {
11275
11287
  if (!headerReferer)
11276
11288
  return "/";
@@ -11278,10 +11290,7 @@ var parseReferer = (headerReferer) => {
11278
11290
  const url = new URL(headerReferer);
11279
11291
  return url.pathname + url.search;
11280
11292
  } catch {
11281
- if (headerReferer.startsWith("/") && !headerReferer.startsWith("//")) {
11282
- return headerReferer;
11283
- }
11284
- return "/";
11293
+ return toSafeLocalPath(headerReferer);
11285
11294
  }
11286
11295
  };
11287
11296
  var authorize = ({
@@ -11496,7 +11505,7 @@ var callback = ({
11496
11505
  if (requiresPKCE && verifier === undefined) {
11497
11506
  return status("Bad Request", "Code verifier not found and is required");
11498
11507
  }
11499
- const originUrl = origin_url?.value ?? "/";
11508
+ const originUrl = toSafeLocalPath(origin_url?.value);
11500
11509
  let tokenResponse2;
11501
11510
  try {
11502
11511
  tokenResponse2 = await providerInstance.validateAuthorizationCode(requiresPKCE ? { code, codeVerifier: verifier } : { code });
@@ -12958,7 +12967,7 @@ var parseReferer2 = (referer) => {
12958
12967
  const url = new URL(referer);
12959
12968
  return url.pathname + url.search;
12960
12969
  } catch {
12961
- return referer.startsWith("/") && !referer.startsWith("//") ? referer : "/";
12970
+ return toSafeLocalPath(referer);
12962
12971
  }
12963
12972
  };
12964
12973
  var oidcSsoRoutes = ({
@@ -13101,18 +13110,13 @@ var oidcSsoRoutes = ({
13101
13110
 
13102
13111
  // src/sso/samlRoutes.ts
13103
13112
  import { Elysia as Elysia39, t as t31 } from "elysia";
13104
- var toLocalPath = (value) => {
13105
- if (value === undefined || value.length === 0)
13106
- return "/";
13107
- return value.startsWith("/") && !value.startsWith("//") ? value : "/";
13108
- };
13109
13113
  var refererPath = (referer) => {
13110
13114
  if (referer === undefined)
13111
13115
  return "/";
13112
13116
  try {
13113
- return toLocalPath(new URL(referer).pathname);
13117
+ return toSafeLocalPath(new URL(referer).pathname);
13114
13118
  } catch {
13115
- return toLocalPath(referer);
13119
+ return toSafeLocalPath(referer);
13116
13120
  }
13117
13121
  };
13118
13122
  var settle = async (work) => {
@@ -13215,7 +13219,7 @@ var samlSsoRoutes = ({
13215
13219
  user,
13216
13220
  userSessionId
13217
13221
  });
13218
- return redirect(toLocalPath(body.RelayState));
13222
+ return redirect(toSafeLocalPath(body.RelayState));
13219
13223
  } catch (error) {
13220
13224
  await onSsoCallbackError?.({ error, organizationId });
13221
13225
  return status("Internal Server Error", "SAML sign-in failed");
@@ -13306,7 +13310,7 @@ var samlSsoRoutes = ({
13306
13310
  sloUrl
13307
13311
  }) ?? Promise.resolve());
13308
13312
  if (!("error" in responseSettled)) {
13309
- return redirect(toLocalPath(RelayState));
13313
+ return redirect(toSafeLocalPath(RelayState));
13310
13314
  }
13311
13315
  await onSsoCallbackError?.({
13312
13316
  error: responseSettled.error,
@@ -13354,7 +13358,7 @@ var samlSsoRoutes = ({
13354
13358
  });
13355
13359
  return redirect(url);
13356
13360
  }
13357
- return redirect(toLocalPath(info.relayState ?? RelayState));
13361
+ return redirect(toSafeLocalPath(info.relayState ?? RelayState));
13358
13362
  }, {
13359
13363
  cookie: t31.Cookie({
13360
13364
  user_session_id: t31.Optional(userSessionIdTypebox)
@@ -38708,5 +38712,5 @@ export {
38708
38712
  VerificationProviderError
38709
38713
  };
38710
38714
 
38711
- //# debugId=82A372899BEA4F4564756E2164756E21
38715
+ //# debugId=F11B818E3AEEB74B64756E2164756E21
38712
38716
  //# sourceMappingURL=server.js.map