@shipfox/client-auth 6.0.2 → 6.0.3
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/components/redirect-context.d.ts.map +1 -1
- package/dist/components/redirect-context.js +6 -9
- package/dist/components/redirect-context.js.map +1 -1
- package/dist/components/redirect-target.d.ts +7 -0
- package/dist/components/redirect-target.d.ts.map +1 -1
- package/dist/components/redirect-target.js +46 -12
- package/dist/components/redirect-target.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/redirect-context.test.ts +13 -0
- package/src/components/redirect-context.ts +5 -8
- package/src/components/redirect-target.test.ts +47 -2
- package/src/components/redirect-target.ts +54 -12
- package/tsconfig.build.tsbuildinfo +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
$ shipfox-swc
|
|
2
|
-
Successfully compiled: 41 files with swc (
|
|
2
|
+
Successfully compiled: 41 files with swc (151.72ms)
|
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect-context.d.ts","sourceRoot":"","sources":["../../src/components/redirect-context.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"redirect-context.d.ts","sourceRoot":"","sources":["../../src/components/redirect-context.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAQpE"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAuthPath, resolveRedirectPath } from './redirect-target.js';
|
|
2
2
|
const INVITATION_ACCEPT_PATH = '/invitations/accept';
|
|
3
3
|
/**
|
|
4
4
|
* Separates a safe post-authentication destination from an invitation token.
|
|
5
5
|
* The token never remains in `returnTo`, so callers can keep it in their
|
|
6
6
|
* short-lived invitation flow instead of forwarding it through generic redirects.
|
|
7
7
|
*/ export function parseRedirectContext(value) {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (path !== INVITATION_ACCEPT_PATH) return {
|
|
13
|
-
returnTo: redirect
|
|
8
|
+
const resolved = resolveRedirectPath(value);
|
|
9
|
+
if (!resolved || isAuthPath(resolved.pathname)) return {};
|
|
10
|
+
if (resolved.pathname !== INVITATION_ACCEPT_PATH) return {
|
|
11
|
+
returnTo: resolved.redirect
|
|
14
12
|
};
|
|
15
|
-
const
|
|
16
|
-
const invitationToken = params.get('token');
|
|
13
|
+
const invitationToken = resolved.target.searchParams.get('token');
|
|
17
14
|
return invitationToken ? {
|
|
18
15
|
invitationToken
|
|
19
16
|
} : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/redirect-context.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/components/redirect-context.ts"],"sourcesContent":["import {isAuthPath, resolveRedirectPath} from './redirect-target.js';\n\nconst INVITATION_ACCEPT_PATH = '/invitations/accept';\n\nexport interface RedirectContext {\n invitationToken?: string;\n returnTo?: string;\n}\n\n/**\n * Separates a safe post-authentication destination from an invitation token.\n * The token never remains in `returnTo`, so callers can keep it in their\n * short-lived invitation flow instead of forwarding it through generic redirects.\n */\nexport function parseRedirectContext(value: unknown): RedirectContext {\n const resolved = resolveRedirectPath(value);\n if (!resolved || isAuthPath(resolved.pathname)) return {};\n\n if (resolved.pathname !== INVITATION_ACCEPT_PATH) return {returnTo: resolved.redirect};\n\n const invitationToken = resolved.target.searchParams.get('token');\n return invitationToken ? {invitationToken} : {};\n}\n"],"names":["isAuthPath","resolveRedirectPath","INVITATION_ACCEPT_PATH","parseRedirectContext","value","resolved","pathname","returnTo","redirect","invitationToken","target","searchParams","get"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,mBAAmB,QAAO,uBAAuB;AAErE,MAAMC,yBAAyB;AAO/B;;;;CAIC,GACD,OAAO,SAASC,qBAAqBC,KAAc;IACjD,MAAMC,WAAWJ,oBAAoBG;IACrC,IAAI,CAACC,YAAYL,WAAWK,SAASC,QAAQ,GAAG,OAAO,CAAC;IAExD,IAAID,SAASC,QAAQ,KAAKJ,wBAAwB,OAAO;QAACK,UAAUF,SAASG,QAAQ;IAAA;IAErF,MAAMC,kBAAkBJ,SAASK,MAAM,CAACC,YAAY,CAACC,GAAG,CAAC;IACzD,OAAOH,kBAAkB;QAACA;IAAe,IAAI,CAAC;AAChD"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export interface ResolvedRedirectPath {
|
|
2
|
+
pathname: string;
|
|
3
|
+
redirect: string;
|
|
4
|
+
target: URL;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveRedirectPath(value: unknown): ResolvedRedirectPath | undefined;
|
|
7
|
+
export declare function isAuthPath(pathname: string): boolean;
|
|
1
8
|
export declare function sanitizeRedirectPath(value: unknown): string | undefined;
|
|
2
9
|
/**
|
|
3
10
|
* Returns the destination used by the shared logout route.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect-target.d.ts","sourceRoot":"","sources":["../../src/components/redirect-target.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redirect-target.d.ts","sourceRoot":"","sources":["../../src/components/redirect-target.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;CACb;AAyBD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAyBpF;AAMD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAID,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIvE;AAOD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAUjE"}
|
|
@@ -3,7 +3,28 @@ const LOGIN_PATH = '/auth/login';
|
|
|
3
3
|
const INVITATION_ACCEPT_PATH = '/invitations/accept';
|
|
4
4
|
const DEFAULT_LOGOUT_REDIRECT = LOGIN_PATH;
|
|
5
5
|
const TRAILING_SLASHES = /\/+$/;
|
|
6
|
-
|
|
6
|
+
const MAX_PATH_DECODE_ITERATIONS = 10;
|
|
7
|
+
// Repeated decoding can reveal `.`/`..` segments or a `//host` prefix that were
|
|
8
|
+
// hidden behind extra encoding layers (e.g. `%25252e%25252e` -> `..`). Those only
|
|
9
|
+
// get collapsed and re-checked against the origin by feeding the fully-decoded,
|
|
10
|
+
// percent-free string back through the URL parser; without this, a multiply
|
|
11
|
+
// encoded `/safe/../auth/login` or `/safe/../invitations/accept?token=...`
|
|
12
|
+
// evades the pathname checks below even though this loop "sees" the real path.
|
|
13
|
+
function decodePathToFixedPoint(pathname) {
|
|
14
|
+
let current = pathname;
|
|
15
|
+
for(let iteration = 0; iteration < MAX_PATH_DECODE_ITERATIONS; iteration += 1){
|
|
16
|
+
let decoded;
|
|
17
|
+
try {
|
|
18
|
+
decoded = decodeURIComponent(current);
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (decoded === current) return current;
|
|
23
|
+
current = decoded;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function resolveRedirectPath(value) {
|
|
7
28
|
if (typeof value !== 'string' || !value.startsWith('/')) return undefined;
|
|
8
29
|
let decoded;
|
|
9
30
|
try {
|
|
@@ -18,23 +39,36 @@ function resolveRedirectPath(value) {
|
|
|
18
39
|
return undefined;
|
|
19
40
|
}
|
|
20
41
|
if (target.origin !== REDIRECT_ORIGIN) return undefined;
|
|
21
|
-
|
|
42
|
+
const decodedPathname = decodePathToFixedPoint(target.pathname);
|
|
43
|
+
if (decodedPathname === undefined) return undefined;
|
|
44
|
+
let canonical;
|
|
45
|
+
try {
|
|
46
|
+
canonical = new URL(decodedPathname, REDIRECT_ORIGIN);
|
|
47
|
+
} catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (canonical.origin !== REDIRECT_ORIGIN) return undefined;
|
|
51
|
+
return {
|
|
52
|
+
pathname: canonical.pathname,
|
|
53
|
+
redirect: formatRedirectPath(target),
|
|
54
|
+
target
|
|
55
|
+
};
|
|
22
56
|
}
|
|
23
57
|
function formatRedirectPath(target) {
|
|
24
58
|
return `${target.pathname}${target.search}${target.hash}`;
|
|
25
59
|
}
|
|
26
|
-
function isAuthPath(pathname) {
|
|
60
|
+
export function isAuthPath(pathname) {
|
|
27
61
|
return pathname === '/auth' || pathname.startsWith('/auth/');
|
|
28
62
|
}
|
|
29
63
|
// Resolves and canonicalizes an internal path before returning it, so browser URL
|
|
30
64
|
// parsing cannot turn a seemingly safe path into an external or auth route.
|
|
31
65
|
export function sanitizeRedirectPath(value) {
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
return
|
|
66
|
+
const resolved = resolveRedirectPath(value);
|
|
67
|
+
if (!resolved || isAuthPath(resolved.pathname)) return undefined;
|
|
68
|
+
return resolved.redirect;
|
|
35
69
|
}
|
|
36
|
-
function containsInvitationToken(target) {
|
|
37
|
-
const normalizedPathname =
|
|
70
|
+
function containsInvitationToken(target, pathname) {
|
|
71
|
+
const normalizedPathname = pathname.replace(TRAILING_SLASHES, '') || '/';
|
|
38
72
|
return normalizedPathname === INVITATION_ACCEPT_PATH && target.searchParams.has('token');
|
|
39
73
|
}
|
|
40
74
|
/**
|
|
@@ -43,12 +77,12 @@ function containsInvitationToken(target) {
|
|
|
43
77
|
* Login is the only auth destination allowed, and invitation tokens never
|
|
44
78
|
* survive this boundary. Invalid values fail closed to login.
|
|
45
79
|
*/ export function sanitizeLogoutRedirectPath(value) {
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
if (isAuthPath(
|
|
80
|
+
const resolved = resolveRedirectPath(value);
|
|
81
|
+
if (!resolved) return DEFAULT_LOGOUT_REDIRECT;
|
|
82
|
+
if (isAuthPath(resolved.pathname) || containsInvitationToken(resolved.target, resolved.pathname)) {
|
|
49
83
|
return DEFAULT_LOGOUT_REDIRECT;
|
|
50
84
|
}
|
|
51
|
-
return
|
|
85
|
+
return resolved.redirect;
|
|
52
86
|
}
|
|
53
87
|
|
|
54
88
|
//# sourceMappingURL=redirect-target.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/redirect-target.ts"],"sourcesContent":["const REDIRECT_ORIGIN = 'https://shipfox-redirect.invalid';\nconst LOGIN_PATH = '/auth/login';\nconst INVITATION_ACCEPT_PATH = '/invitations/accept';\nconst DEFAULT_LOGOUT_REDIRECT = LOGIN_PATH;\nconst TRAILING_SLASHES = /\\/+$/;\n\nfunction resolveRedirectPath(value: unknown):
|
|
1
|
+
{"version":3,"sources":["../../src/components/redirect-target.ts"],"sourcesContent":["const REDIRECT_ORIGIN = 'https://shipfox-redirect.invalid';\nconst LOGIN_PATH = '/auth/login';\nconst INVITATION_ACCEPT_PATH = '/invitations/accept';\nconst DEFAULT_LOGOUT_REDIRECT = LOGIN_PATH;\nconst TRAILING_SLASHES = /\\/+$/;\nconst MAX_PATH_DECODE_ITERATIONS = 10;\n\nexport interface ResolvedRedirectPath {\n pathname: string;\n redirect: string;\n target: URL;\n}\n\n// Repeated decoding can reveal `.`/`..` segments or a `//host` prefix that were\n// hidden behind extra encoding layers (e.g. `%25252e%25252e` -> `..`). Those only\n// get collapsed and re-checked against the origin by feeding the fully-decoded,\n// percent-free string back through the URL parser; without this, a multiply\n// encoded `/safe/../auth/login` or `/safe/../invitations/accept?token=...`\n// evades the pathname checks below even though this loop \"sees\" the real path.\nfunction decodePathToFixedPoint(pathname: string): string | undefined {\n let current = pathname;\n\n for (let iteration = 0; iteration < MAX_PATH_DECODE_ITERATIONS; iteration += 1) {\n let decoded: string;\n try {\n decoded = decodeURIComponent(current);\n } catch {\n return undefined;\n }\n if (decoded === current) return current;\n current = decoded;\n }\n\n return undefined;\n}\n\nexport function resolveRedirectPath(value: unknown): ResolvedRedirectPath | undefined {\n if (typeof value !== 'string' || !value.startsWith('/')) return undefined;\n let decoded: string;\n try {\n decoded = decodeURIComponent(value);\n } catch {\n return undefined;\n }\n let target: URL;\n try {\n target = new URL(decoded, REDIRECT_ORIGIN);\n } catch {\n return undefined;\n }\n if (target.origin !== REDIRECT_ORIGIN) return undefined;\n const decodedPathname = decodePathToFixedPoint(target.pathname);\n if (decodedPathname === undefined) return undefined;\n let canonical: URL;\n try {\n canonical = new URL(decodedPathname, REDIRECT_ORIGIN);\n } catch {\n return undefined;\n }\n if (canonical.origin !== REDIRECT_ORIGIN) return undefined;\n return {pathname: canonical.pathname, redirect: formatRedirectPath(target), target};\n}\n\nfunction formatRedirectPath(target: URL): string {\n return `${target.pathname}${target.search}${target.hash}`;\n}\n\nexport function isAuthPath(pathname: string): boolean {\n return pathname === '/auth' || pathname.startsWith('/auth/');\n}\n\n// Resolves and canonicalizes an internal path before returning it, so browser URL\n// parsing cannot turn a seemingly safe path into an external or auth route.\nexport function sanitizeRedirectPath(value: unknown): string | undefined {\n const resolved = resolveRedirectPath(value);\n if (!resolved || isAuthPath(resolved.pathname)) return undefined;\n return resolved.redirect;\n}\n\nfunction containsInvitationToken(target: URL, pathname: string): boolean {\n const normalizedPathname = pathname.replace(TRAILING_SLASHES, '') || '/';\n return normalizedPathname === INVITATION_ACCEPT_PATH && target.searchParams.has('token');\n}\n\n/**\n * Returns the destination used by the shared logout route.\n *\n * Login is the only auth destination allowed, and invitation tokens never\n * survive this boundary. Invalid values fail closed to login.\n */\nexport function sanitizeLogoutRedirectPath(value: unknown): string {\n const resolved = resolveRedirectPath(value);\n if (!resolved) return DEFAULT_LOGOUT_REDIRECT;\n if (\n isAuthPath(resolved.pathname) ||\n containsInvitationToken(resolved.target, resolved.pathname)\n ) {\n return DEFAULT_LOGOUT_REDIRECT;\n }\n return resolved.redirect;\n}\n"],"names":["REDIRECT_ORIGIN","LOGIN_PATH","INVITATION_ACCEPT_PATH","DEFAULT_LOGOUT_REDIRECT","TRAILING_SLASHES","MAX_PATH_DECODE_ITERATIONS","decodePathToFixedPoint","pathname","current","iteration","decoded","decodeURIComponent","undefined","resolveRedirectPath","value","startsWith","target","URL","origin","decodedPathname","canonical","redirect","formatRedirectPath","search","hash","isAuthPath","sanitizeRedirectPath","resolved","containsInvitationToken","normalizedPathname","replace","searchParams","has","sanitizeLogoutRedirectPath"],"mappings":"AAAA,MAAMA,kBAAkB;AACxB,MAAMC,aAAa;AACnB,MAAMC,yBAAyB;AAC/B,MAAMC,0BAA0BF;AAChC,MAAMG,mBAAmB;AACzB,MAAMC,6BAA6B;AAQnC,gFAAgF;AAChF,kFAAkF;AAClF,gFAAgF;AAChF,4EAA4E;AAC5E,2EAA2E;AAC3E,+EAA+E;AAC/E,SAASC,uBAAuBC,QAAgB;IAC9C,IAAIC,UAAUD;IAEd,IAAK,IAAIE,YAAY,GAAGA,YAAYJ,4BAA4BI,aAAa,EAAG;QAC9E,IAAIC;QACJ,IAAI;YACFA,UAAUC,mBAAmBH;QAC/B,EAAE,OAAM;YACN,OAAOI;QACT;QACA,IAAIF,YAAYF,SAAS,OAAOA;QAChCA,UAAUE;IACZ;IAEA,OAAOE;AACT;AAEA,OAAO,SAASC,oBAAoBC,KAAc;IAChD,IAAI,OAAOA,UAAU,YAA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