@base44-preview/sdk 0.8.18-pr.116.3508d64 → 0.8.18-pr.116.605725a
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/modules/auth.js +28 -2
- package/package.json +1 -1
package/dist/modules/auth.js
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a redirect URL is safe to use (prevents open redirect attacks).
|
|
3
|
+
* Only allows same-origin URLs or relative paths.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The URL to validate
|
|
6
|
+
* @param currentOrigin - The current window origin for comparison
|
|
7
|
+
* @returns true if the URL is safe to redirect to
|
|
8
|
+
*/
|
|
9
|
+
function isValidRedirectUrl(url) {
|
|
10
|
+
// Relative URLs starting with / are always safe
|
|
11
|
+
if (url.startsWith("/") && !url.startsWith("//")) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// For absolute URLs, verify same origin
|
|
15
|
+
try {
|
|
16
|
+
const parsed = new URL(url);
|
|
17
|
+
return (typeof window !== "undefined" &&
|
|
18
|
+
parsed.origin === window.location.origin);
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
// If URL parsing fails, reject it for safety
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
1
25
|
/**
|
|
2
26
|
* Creates the auth module for the Base44 SDK.
|
|
3
27
|
*
|
|
@@ -32,9 +56,11 @@ export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
|
32
56
|
// Prevent redirect loops: if redirectUrl is already a login URL, extract the original from_url
|
|
33
57
|
try {
|
|
34
58
|
const parsedUrl = new URL(redirectUrl);
|
|
35
|
-
|
|
59
|
+
const pathname = parsedUrl.pathname;
|
|
60
|
+
// Check for login path with or without trailing slash
|
|
61
|
+
if (pathname.endsWith("/login") || pathname.endsWith("/login/")) {
|
|
36
62
|
const originalFromUrl = parsedUrl.searchParams.get("from_url");
|
|
37
|
-
if (originalFromUrl) {
|
|
63
|
+
if (originalFromUrl && isValidRedirectUrl(originalFromUrl)) {
|
|
38
64
|
// Use the original destination instead of nesting login URLs
|
|
39
65
|
redirectUrl = originalFromUrl;
|
|
40
66
|
}
|