@farm.js/auth 0.1.0-beta.90 → 0.1.0-beta.92

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.
Files changed (2) hide show
  1. package/dist/config.js +38 -2
  2. package/package.json +1 -1
package/dist/config.js CHANGED
@@ -48,11 +48,47 @@ export function resolveFarmAuthConfig(input) {
48
48
  return resolved;
49
49
  }
50
50
  function normalizeBasePath(value) {
51
- const path = (value || "/api/auth").trim();
52
- const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
51
+ const route = (value || "/api/auth").trim();
52
+ if (!route)
53
+ return "/api/auth";
54
+ assertStableBasePath(route);
55
+ const withLeadingSlash = route.startsWith("/") ? route : `/${route}`;
53
56
  const normalized = withLeadingSlash.replace(/\/+/g, "/").replace(/\/+$/, "");
54
57
  return normalized || "/api/auth";
55
58
  }
59
+ function assertStableBasePath(route) {
60
+ if (route.includes("?") || route.includes("#")) {
61
+ throw new Error("auth.basePath cannot contain a query string or fragment.");
62
+ }
63
+ if (route.startsWith("//") || /^[a-z][a-z\d+.-]*:\/\//i.test(route)) {
64
+ throw new Error('auth.basePath must be an application pathname such as "/api/auth".');
65
+ }
66
+ if (hasUnstablePathCharacters(route)) {
67
+ throw new Error("auth.basePath cannot contain backslashes or control characters.");
68
+ }
69
+ for (const segment of route.split("/")) {
70
+ let decoded = segment;
71
+ try {
72
+ decoded = decodeURIComponent(segment);
73
+ }
74
+ catch {
75
+ // Malformed escapes remain literal URL pathname segments.
76
+ }
77
+ if (hasUnstablePathCharacters(decoded) || decoded.includes("/")) {
78
+ throw new Error("auth.basePath cannot contain encoded path separators.");
79
+ }
80
+ if (decoded === "." || decoded === "..") {
81
+ throw new Error('auth.basePath cannot contain "." or ".." path segments.');
82
+ }
83
+ }
84
+ }
85
+ function hasUnstablePathCharacters(value) {
86
+ return (value.includes("\\") ||
87
+ Array.from(value).some((character) => {
88
+ const code = character.charCodeAt(0);
89
+ return code <= 31 || (code >= 127 && code <= 159);
90
+ }));
91
+ }
56
92
  function validateFarmAuthConfig(config) {
57
93
  const { minPasswordLength, maxPasswordLength } = config.emailAndPassword;
58
94
  if (!Number.isInteger(minPasswordLength) || minPasswordLength < 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/auth",
3
- "version": "0.1.0-beta.90",
3
+ "version": "0.1.0-beta.92",
4
4
  "description": "Farm-native authentication with email/password, server helpers, and React hooks",
5
5
  "license": "MIT",
6
6
  "repository": {