@aura-stack/auth 0.4.0-rc.5 → 0.5.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/@types/index.d.ts +8 -3
- package/dist/@types/router.d.cjs +0 -17
- package/dist/@types/router.d.d.ts +7 -2
- package/dist/@types/router.d.js +0 -1
- package/dist/actions/callback/access-token.cjs +130 -71
- package/dist/actions/callback/access-token.d.ts +9 -4
- package/dist/actions/callback/access-token.js +3 -4
- package/dist/actions/callback/callback.cjs +428 -152
- package/dist/actions/callback/callback.d.ts +11 -3
- package/dist/actions/callback/callback.js +12 -10
- package/dist/actions/callback/userinfo.cjs +159 -65
- package/dist/actions/callback/userinfo.d.ts +8 -3
- package/dist/actions/callback/userinfo.js +7 -6
- package/dist/actions/csrfToken/csrfToken.cjs +70 -19
- package/dist/actions/csrfToken/csrfToken.js +8 -7
- package/dist/actions/index.cjs +780 -348
- package/dist/actions/index.d.ts +6 -2
- package/dist/actions/index.js +23 -18
- package/dist/actions/session/session.cjs +107 -26
- package/dist/actions/session/session.js +7 -5
- package/dist/actions/signIn/authorization-url.cjs +288 -0
- package/dist/actions/signIn/authorization-url.d.ts +31 -0
- package/dist/actions/signIn/authorization-url.js +16 -0
- package/dist/actions/signIn/authorization.cjs +209 -211
- package/dist/actions/signIn/authorization.d.ts +32 -21
- package/dist/actions/signIn/authorization.js +12 -9
- package/dist/actions/signIn/signIn.cjs +470 -235
- package/dist/actions/signIn/signIn.d.ts +12 -3
- package/dist/actions/signIn/signIn.js +11 -8
- package/dist/actions/signOut/signOut.cjs +376 -228
- package/dist/actions/signOut/signOut.d.ts +1 -1
- package/dist/actions/signOut/signOut.js +10 -9
- package/dist/api/createApi.cjs +750 -0
- package/dist/api/createApi.d.ts +12 -0
- package/dist/api/createApi.js +19 -0
- package/dist/api/getSession.cjs +141 -0
- package/dist/api/getSession.d.ts +16 -0
- package/dist/api/getSession.js +10 -0
- package/dist/api/signIn.cjs +549 -0
- package/dist/api/signIn.d.ts +26 -0
- package/dist/api/signIn.js +15 -0
- package/dist/api/signOut.cjs +279 -0
- package/dist/api/signOut.d.ts +16 -0
- package/dist/api/signOut.js +13 -0
- package/dist/assert.cjs +150 -5
- package/dist/assert.d.ts +26 -3
- package/dist/assert.js +17 -3
- package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
- package/dist/chunk-2GQLSIJ2.js +40 -0
- package/dist/chunk-2IR674WX.js +44 -0
- package/dist/chunk-3J5TUH2I.js +50 -0
- package/dist/chunk-4RWSYUKX.js +98 -0
- package/dist/chunk-4YHJ4IEQ.js +25 -0
- package/dist/chunk-54CZPKR4.js +25 -0
- package/dist/chunk-5LZ7TOM3.js +25 -0
- package/dist/chunk-7BE46WWS.js +88 -0
- package/dist/chunk-7YYXFKLR.js +35 -0
- package/dist/chunk-C3A37LQC.js +33 -0
- package/dist/chunk-CITNGXDA.js +31 -0
- package/dist/chunk-CWX724AG.js +78 -0
- package/dist/chunk-D2CSIUKP.js +74 -0
- package/dist/chunk-E6G5YCI6.js +25 -0
- package/dist/chunk-EBAMFRB7.js +34 -0
- package/dist/chunk-EEE7UM5T.js +25 -0
- package/dist/{chunk-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
- package/dist/chunk-FW4W3REU.js +25 -0
- package/dist/chunk-GNNBM2WJ.js +83 -0
- package/dist/chunk-IPKO6UQN.js +25 -0
- package/dist/chunk-JOCGX3RP.js +59 -0
- package/dist/chunk-KBXWTD6E.js +94 -0
- package/dist/chunk-KMMAZFSJ.js +25 -0
- package/dist/chunk-LATR3NIV.js +117 -0
- package/dist/chunk-LAYPUDQF.js +39 -0
- package/dist/chunk-LDU7A2JE.js +25 -0
- package/dist/chunk-LX3TJ2TJ.js +294 -0
- package/dist/chunk-NHZBQNRR.js +143 -0
- package/dist/chunk-OVHNRULD.js +33 -0
- package/dist/chunk-PDP3PHB3.js +127 -0
- package/dist/chunk-PHYNROD4.js +47 -0
- package/dist/chunk-QQEKY4XP.js +29 -0
- package/dist/chunk-U4RK4LKJ.js +348 -0
- package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
- package/dist/chunk-UN7X6SU5.js +53 -0
- package/dist/chunk-UZQJJD6A.js +100 -0
- package/dist/chunk-V6LLEAR4.js +80 -0
- package/dist/chunk-WHNDRO3N.js +50 -0
- package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
- package/dist/client/client.cjs +135 -0
- package/dist/client/client.d.ts +85 -0
- package/dist/client/client.js +9 -0
- package/dist/client/index.cjs +135 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +10 -0
- package/dist/context.cjs +1237 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +28 -0
- package/dist/cookie.cjs +57 -22
- package/dist/cookie.d.ts +11 -6
- package/dist/cookie.js +3 -2
- package/dist/createAuth.cjs +2320 -0
- package/dist/createAuth.d.ts +12 -0
- package/dist/createAuth.js +48 -0
- package/dist/env.cjs +78 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +12 -0
- package/dist/errors.cjs +17 -0
- package/dist/errors.d.ts +15 -4
- package/dist/errors.js +5 -1
- package/dist/headers.cjs +28 -2
- package/dist/headers.d.ts +25 -1
- package/dist/headers.js +9 -3
- package/dist/index-_aXtxb_s.d.ts +1377 -0
- package/dist/index.cjs +1843 -610
- package/dist/index.d.ts +11 -92
- package/dist/index.js +53 -85
- package/dist/jose.cjs +113 -38
- package/dist/jose.d.ts +12 -23
- package/dist/jose.js +17 -7
- package/dist/logger.cjs +424 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +17 -0
- package/dist/oauth/atlassian.cjs +57 -0
- package/dist/oauth/atlassian.d.ts +12 -0
- package/dist/oauth/atlassian.js +6 -0
- package/dist/oauth/bitbucket.cjs +19 -15
- package/dist/oauth/bitbucket.d.ts +7 -2
- package/dist/oauth/bitbucket.js +1 -1
- package/dist/oauth/discord.cjs +27 -24
- package/dist/oauth/discord.d.ts +7 -2
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/dropbox.cjs +53 -0
- package/dist/oauth/dropbox.d.ts +12 -0
- package/dist/oauth/dropbox.js +6 -0
- package/dist/oauth/figma.cjs +19 -16
- package/dist/oauth/figma.d.ts +7 -2
- package/dist/oauth/figma.js +1 -1
- package/dist/oauth/github.cjs +19 -8
- package/dist/oauth/github.d.ts +7 -2
- package/dist/oauth/github.js +1 -1
- package/dist/oauth/gitlab.cjs +19 -16
- package/dist/oauth/gitlab.d.ts +7 -2
- package/dist/oauth/gitlab.js +1 -1
- package/dist/oauth/index.cjs +529 -239
- package/dist/oauth/index.d.ts +7 -2
- package/dist/oauth/index.js +39 -22
- package/dist/oauth/mailchimp.cjs +19 -16
- package/dist/oauth/mailchimp.d.ts +7 -2
- package/dist/oauth/mailchimp.js +1 -1
- package/dist/oauth/notion.cjs +131 -0
- package/dist/oauth/notion.d.ts +12 -0
- package/dist/oauth/notion.js +9 -0
- package/dist/oauth/pinterest.cjs +19 -16
- package/dist/oauth/pinterest.d.ts +7 -2
- package/dist/oauth/pinterest.js +1 -1
- package/dist/oauth/spotify.cjs +19 -16
- package/dist/oauth/spotify.d.ts +7 -2
- package/dist/oauth/spotify.js +1 -1
- package/dist/oauth/strava.cjs +19 -16
- package/dist/oauth/strava.d.ts +7 -2
- package/dist/oauth/strava.js +1 -1
- package/dist/oauth/twitch.cjs +95 -0
- package/dist/oauth/twitch.d.ts +12 -0
- package/dist/oauth/twitch.js +7 -0
- package/dist/oauth/x.cjs +19 -16
- package/dist/oauth/x.d.ts +7 -2
- package/dist/oauth/x.js +1 -1
- package/dist/schemas.cjs +89 -42
- package/dist/schemas.d.ts +114 -18
- package/dist/schemas.js +5 -3
- package/dist/secure.cjs +73 -31
- package/dist/secure.d.ts +11 -11
- package/dist/secure.js +7 -6
- package/dist/utils.cjs +203 -90
- package/dist/utils.d.ts +21 -40
- package/dist/utils.js +21 -12
- package/package.json +9 -6
- package/dist/chunk-3EUWD5BB.js +0 -63
- package/dist/chunk-42XB3YCW.js +0 -22
- package/dist/chunk-6R2YZ4AC.js +0 -22
- package/dist/chunk-A3N4PVAT.js +0 -70
- package/dist/chunk-B737EUJV.js +0 -22
- package/dist/chunk-CXLATHS5.js +0 -143
- package/dist/chunk-E3OXBRYF.js +0 -22
- package/dist/chunk-EIL2FPSS.js +0 -22
- package/dist/chunk-EMKJA2GJ.js +0 -89
- package/dist/chunk-FIPU4MLT.js +0 -21
- package/dist/chunk-FKRDCWBF.js +0 -22
- package/dist/chunk-GA2SMTJO.js +0 -58
- package/dist/chunk-HP34YGGJ.js +0 -22
- package/dist/chunk-IKHPGFCW.js +0 -14
- package/dist/chunk-IUYZQTJV.js +0 -30
- package/dist/chunk-IVET23KF.js +0 -58
- package/dist/chunk-JVFTCTTE.js +0 -33
- package/dist/chunk-KRNOMBXQ.js +0 -22
- package/dist/chunk-KSWLO5ZU.js +0 -102
- package/dist/chunk-N2APGLXA.js +0 -71
- package/dist/chunk-N4SX7TZT.js +0 -96
- package/dist/chunk-STHEPPUZ.js +0 -11
- package/dist/chunk-TLE4PXY3.js +0 -39
- package/dist/index-B8jeIElf.d.ts +0 -679
- /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/actions/signOut/signOut.ts
|
|
@@ -33,106 +23,247 @@ __export(signOut_exports, {
|
|
|
33
23
|
signOutAction: () => signOutAction
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(signOut_exports);
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
// src/secure.ts
|
|
40
|
-
var import_crypto = __toESM(require("crypto"), 1);
|
|
26
|
+
var import_v4 = require("zod/v4");
|
|
27
|
+
var import_router3 = require("@aura-stack/router");
|
|
41
28
|
|
|
42
29
|
// src/utils.ts
|
|
43
30
|
var import_router = require("@aura-stack/router");
|
|
44
31
|
|
|
45
32
|
// src/errors.ts
|
|
33
|
+
var AuthInternalError = class extends Error {
|
|
34
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
35
|
+
code;
|
|
36
|
+
constructor(code, message, options) {
|
|
37
|
+
super(message, options);
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.name = new.target.name;
|
|
40
|
+
Error.captureStackTrace(this, new.target);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
46
43
|
var AuthSecurityError = class extends Error {
|
|
47
44
|
type = "AUTH_SECURITY_ERROR";
|
|
48
45
|
code;
|
|
49
|
-
constructor(code, message,
|
|
50
|
-
super(message,
|
|
46
|
+
constructor(code, message, options) {
|
|
47
|
+
super(message, options);
|
|
51
48
|
this.code = code;
|
|
52
49
|
this.name = new.target.name;
|
|
53
50
|
Error.captureStackTrace(this, new.target);
|
|
54
51
|
}
|
|
55
52
|
};
|
|
56
|
-
var isAuthSecurityError = (error) => {
|
|
57
|
-
return error instanceof AuthSecurityError;
|
|
58
|
-
};
|
|
59
53
|
|
|
60
|
-
// src/
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (protocolMatch) {
|
|
72
|
-
protocol = protocolMatch[1];
|
|
73
|
-
rest = decodedURL.slice(protocol.length);
|
|
74
|
-
const slashIndex = rest.indexOf("/");
|
|
75
|
-
if (slashIndex === -1) {
|
|
76
|
-
return protocol + rest;
|
|
54
|
+
// src/env.ts
|
|
55
|
+
var import_meta = {};
|
|
56
|
+
var env = new Proxy({}, {
|
|
57
|
+
get(_, prop) {
|
|
58
|
+
if (typeof prop !== "string") return void 0;
|
|
59
|
+
const hasProperty = (process2) => {
|
|
60
|
+
return process2 && Object.prototype.hasOwnProperty.call(process2, prop);
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
if (typeof process !== "undefined" && hasProperty(process.env)) {
|
|
64
|
+
return process.env[prop];
|
|
77
65
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (path !== "/" && path.endsWith("/")) {
|
|
81
|
-
path = path.replace(/\/+$/, "/");
|
|
82
|
-
} else if (path !== "/") {
|
|
83
|
-
path = path.replace(/\/+$/, "");
|
|
66
|
+
if (typeof import_meta !== "undefined" && hasProperty(import_meta.env)) {
|
|
67
|
+
return import_meta.env[prop];
|
|
84
68
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
if (typeof Deno !== "undefined" && Deno.env?.get) {
|
|
70
|
+
return Deno.env.get(prop);
|
|
71
|
+
}
|
|
72
|
+
if (typeof Bun !== "undefined" && hasProperty(Bun.env)) {
|
|
73
|
+
return Bun.env[prop];
|
|
74
|
+
}
|
|
75
|
+
const globalValue = globalThis[prop];
|
|
76
|
+
return typeof globalValue === "string" ? globalValue : void 0;
|
|
77
|
+
} catch {
|
|
78
|
+
return void 0;
|
|
92
79
|
}
|
|
93
|
-
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
var getEnv = (key) => {
|
|
83
|
+
const keys = [`AURA_AUTH_${key.toUpperCase()}`, `AURA_${key.toUpperCase()}`, `AUTH_${key.toUpperCase()}`, key.toUpperCase()];
|
|
84
|
+
return env[keys.find((k) => env[k]) ?? ""];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/assert.ts
|
|
88
|
+
var import_crypto = require("@aura-stack/jose/crypto");
|
|
89
|
+
var unsafeChars = [
|
|
90
|
+
"<",
|
|
91
|
+
">",
|
|
92
|
+
'"',
|
|
93
|
+
"`",
|
|
94
|
+
" ",
|
|
95
|
+
"\r",
|
|
96
|
+
"\n",
|
|
97
|
+
" ",
|
|
98
|
+
"\\",
|
|
99
|
+
"%2F",
|
|
100
|
+
"%5C",
|
|
101
|
+
"%2f",
|
|
102
|
+
"%5c",
|
|
103
|
+
"\r\n",
|
|
104
|
+
"%0A",
|
|
105
|
+
"%0D",
|
|
106
|
+
"%0a",
|
|
107
|
+
"%0d",
|
|
108
|
+
"..",
|
|
109
|
+
"//",
|
|
110
|
+
"///",
|
|
111
|
+
"...",
|
|
112
|
+
"%20",
|
|
113
|
+
"\0"
|
|
114
|
+
];
|
|
115
|
+
var isValidURL = (value) => {
|
|
116
|
+
if (!new RegExp(/^https?:\/\/[^/]/).test(value)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const match = value.match(/^(https?:\/\/)(.*)$/);
|
|
120
|
+
if (!match) return false;
|
|
121
|
+
const rest = match[2];
|
|
122
|
+
for (const char of unsafeChars) {
|
|
123
|
+
if (rest.includes(char)) return false;
|
|
124
|
+
}
|
|
125
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()?#*+,;=:@-]*)*\/?$/;
|
|
126
|
+
return regex.test(match[0]);
|
|
127
|
+
};
|
|
128
|
+
var isJWTPayloadWithToken = (payload) => {
|
|
129
|
+
return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
|
|
130
|
+
};
|
|
131
|
+
var isRelativeURL = (value) => {
|
|
132
|
+
if (value.length > 100) return false;
|
|
133
|
+
for (const char of unsafeChars) {
|
|
134
|
+
if (value.includes(char)) return false;
|
|
135
|
+
}
|
|
136
|
+
const regex = /^\/[a-zA-Z0-9\-_\/.?&=#]*\/?$/;
|
|
137
|
+
return regex.test(value);
|
|
138
|
+
};
|
|
139
|
+
var isSameOrigin = (origin, expected) => {
|
|
140
|
+
const originURL = new URL(origin);
|
|
141
|
+
const expectedURL = new URL(expected);
|
|
142
|
+
return equals(originURL.origin, expectedURL.origin);
|
|
143
|
+
};
|
|
144
|
+
var patternToRegex = (pattern) => {
|
|
145
|
+
try {
|
|
146
|
+
if (pattern.length > 2048) return null;
|
|
147
|
+
pattern = pattern.replace(/\\/g, "");
|
|
148
|
+
const match = pattern.match(/^(https?):\/\/([a-zA-Z0-9.*-]{1,253})(?::(\d{1,5}|\*))?(?:\/.*)?$/);
|
|
149
|
+
if (!match) return null;
|
|
150
|
+
const [, protocol, host, port] = match;
|
|
151
|
+
const hasWildcard = host.includes("*");
|
|
152
|
+
if (hasWildcard && !host.startsWith("*.")) return null;
|
|
153
|
+
if (hasWildcard && host.slice(2).includes("*")) return null;
|
|
154
|
+
const domain = hasWildcard ? host.slice(2) : host;
|
|
155
|
+
const escapedDomain = domain.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
156
|
+
const hostRegex = hasWildcard ? `[^.]+\\.${escapedDomain}` : escapedDomain;
|
|
157
|
+
const portRegex = port === "*" ? ":\\d{1,5}" : port ? `:${port}` : "";
|
|
158
|
+
return new RegExp(`^${protocol}:\\/\\/${hostRegex}${portRegex}$`);
|
|
94
159
|
} catch {
|
|
95
|
-
return
|
|
160
|
+
return null;
|
|
96
161
|
}
|
|
97
162
|
};
|
|
98
|
-
var
|
|
163
|
+
var isTrustedOrigin = (url, trustedOrigins) => {
|
|
164
|
+
if (!isValidURL(url) || trustedOrigins.length === 0) return false;
|
|
99
165
|
try {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
166
|
+
const urlOrigin = new URL(url).origin;
|
|
167
|
+
for (const pattern of trustedOrigins) {
|
|
168
|
+
const regex = patternToRegex(pattern);
|
|
169
|
+
if (regex?.test(urlOrigin)) return true;
|
|
170
|
+
try {
|
|
171
|
+
if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return true;
|
|
172
|
+
} catch {
|
|
173
|
+
}
|
|
174
|
+
}
|
|
104
175
|
} catch {
|
|
105
|
-
return sanitizeURL(path);
|
|
106
176
|
}
|
|
177
|
+
return false;
|
|
178
|
+
};
|
|
179
|
+
var timingSafeEqual = (a, b) => {
|
|
180
|
+
const bufferA = import_crypto.encoder.encode(a);
|
|
181
|
+
const bufferB = import_crypto.encoder.encode(b);
|
|
182
|
+
const len = Math.max(bufferA.length, bufferB.length);
|
|
183
|
+
let diff = 0;
|
|
184
|
+
for (let i = 0; i < len; i++) {
|
|
185
|
+
diff |= (bufferA[i] ?? 0) ^ (bufferB[i] ?? 0);
|
|
186
|
+
}
|
|
187
|
+
return diff === 0 && bufferA.length === bufferB.length;
|
|
107
188
|
};
|
|
108
189
|
|
|
109
|
-
// src/
|
|
110
|
-
var
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
return regex.test(value);
|
|
190
|
+
// src/utils.ts
|
|
191
|
+
var equals = (a, b) => {
|
|
192
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
193
|
+
return a === b;
|
|
114
194
|
};
|
|
115
|
-
var
|
|
116
|
-
|
|
195
|
+
var getBaseURL = (request) => {
|
|
196
|
+
const url = new URL(request.url);
|
|
197
|
+
return `${url.origin}${url.pathname}`;
|
|
198
|
+
};
|
|
199
|
+
var extractPath = (url) => {
|
|
200
|
+
const pathRegex = /^https?:\/\/[a-zA-Z0-9_\-\.]+(:\d+)?(\/.*)$/;
|
|
201
|
+
const match = url.match(pathRegex);
|
|
202
|
+
return match && match[2] ? match[2] : "/";
|
|
203
|
+
};
|
|
204
|
+
var getErrorName = (error) => {
|
|
205
|
+
if (error instanceof Error) {
|
|
206
|
+
return error.name;
|
|
207
|
+
}
|
|
208
|
+
return typeof error === "string" ? error : "UnknownError";
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/cookie.ts
|
|
212
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
213
|
+
var defaultCookieOptions = {
|
|
214
|
+
httpOnly: true,
|
|
215
|
+
sameSite: "lax",
|
|
216
|
+
path: "/",
|
|
217
|
+
maxAge: 60 * 60 * 24 * 15
|
|
218
|
+
};
|
|
219
|
+
var oauthCookieOptions = {
|
|
220
|
+
httpOnly: true,
|
|
221
|
+
maxAge: 5 * 60,
|
|
222
|
+
sameSite: "lax",
|
|
223
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
224
|
+
};
|
|
225
|
+
var expiredCookieAttributes = {
|
|
226
|
+
...defaultCookieOptions,
|
|
227
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
228
|
+
maxAge: 0,
|
|
229
|
+
secure: true
|
|
230
|
+
};
|
|
231
|
+
var getCookie = (request, cookieName) => {
|
|
232
|
+
const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
|
|
233
|
+
if (!cookies) {
|
|
234
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
235
|
+
}
|
|
236
|
+
const value = (0, import_cookie.parse)(cookies)[cookieName];
|
|
237
|
+
if (!value) {
|
|
238
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
|
|
239
|
+
}
|
|
240
|
+
return value;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/jose.ts
|
|
244
|
+
var import_jose = require("@aura-stack/jose");
|
|
245
|
+
var import_jose2 = require("@aura-stack/jose/jose");
|
|
246
|
+
var import_crypto2 = require("@aura-stack/jose/crypto");
|
|
247
|
+
var jwtVerificationOptions = {
|
|
248
|
+
algorithms: ["HS256"],
|
|
249
|
+
typ: "JWT"
|
|
117
250
|
};
|
|
118
251
|
|
|
119
252
|
// src/secure.ts
|
|
120
253
|
var verifyCSRF = async (jose, cookie, header) => {
|
|
121
254
|
try {
|
|
122
|
-
const cookiePayload = await jose.verifyJWS(cookie);
|
|
123
|
-
const headerPayload = await jose.verifyJWS(header);
|
|
255
|
+
const cookiePayload = await jose.verifyJWS(cookie, jwtVerificationOptions);
|
|
256
|
+
const headerPayload = await jose.verifyJWS(header, jwtVerificationOptions);
|
|
124
257
|
if (!isJWTPayloadWithToken(cookiePayload)) {
|
|
125
258
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
|
|
126
259
|
}
|
|
127
260
|
if (!isJWTPayloadWithToken(headerPayload)) {
|
|
128
261
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
|
|
129
262
|
}
|
|
130
|
-
|
|
131
|
-
const headerBuffer = Buffer.from(headerPayload.token);
|
|
132
|
-
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
263
|
+
if (!equals(cookiePayload.token.length, headerPayload.token.length)) {
|
|
133
264
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
134
265
|
}
|
|
135
|
-
if (!
|
|
266
|
+
if (!timingSafeEqual(cookiePayload.token, headerPayload.token)) {
|
|
136
267
|
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
137
268
|
}
|
|
138
269
|
return true;
|
|
@@ -148,193 +279,210 @@ var cacheControl = {
|
|
|
148
279
|
Expires: "0",
|
|
149
280
|
Vary: "Cookie"
|
|
150
281
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
282
|
+
var contentSecurityPolicy = {
|
|
283
|
+
"Content-Security-Policy": [
|
|
284
|
+
"default-src 'none'",
|
|
285
|
+
"script-src 'self'",
|
|
286
|
+
"frame-src 'none'",
|
|
287
|
+
"object-src 'none'",
|
|
288
|
+
"frame-ancestors 'none'",
|
|
289
|
+
"base-uri 'none'"
|
|
290
|
+
].join("; ")
|
|
159
291
|
};
|
|
160
|
-
var
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
292
|
+
var secureHeaders = {
|
|
293
|
+
"X-Content-Type-Options": "nosniff",
|
|
294
|
+
"X-Frame-Options": "DENY",
|
|
295
|
+
"Referrer-Policy": "strict-origin-when-cross-origin"
|
|
165
296
|
};
|
|
166
|
-
var
|
|
167
|
-
...
|
|
168
|
-
|
|
169
|
-
|
|
297
|
+
var secureApiHeaders = {
|
|
298
|
+
...cacheControl,
|
|
299
|
+
...contentSecurityPolicy,
|
|
300
|
+
...secureHeaders
|
|
170
301
|
};
|
|
171
302
|
|
|
172
|
-
// src/
|
|
173
|
-
var
|
|
174
|
-
var
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
"
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
303
|
+
// src/api/signOut.ts
|
|
304
|
+
var import_router2 = require("@aura-stack/router");
|
|
305
|
+
var signOut = async ({
|
|
306
|
+
ctx,
|
|
307
|
+
headers: headersInit,
|
|
308
|
+
redirectTo = "/",
|
|
309
|
+
skipCSRFCheck = false
|
|
310
|
+
}) => {
|
|
311
|
+
const headers = new Headers(headersInit);
|
|
312
|
+
const header = headers.get("X-CSRF-Token");
|
|
313
|
+
let session = null;
|
|
314
|
+
let csrfToken = null;
|
|
315
|
+
try {
|
|
316
|
+
session = getCookie(headers, ctx.cookies.sessionToken.name);
|
|
317
|
+
} catch {
|
|
318
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
csrfToken = getCookie(headers, ctx.cookies.csrfToken.name);
|
|
322
|
+
} catch {
|
|
323
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
324
|
+
}
|
|
325
|
+
ctx?.logger?.log("SIGN_OUT_ATTEMPT", {
|
|
326
|
+
structuredData: {
|
|
327
|
+
has_session: Boolean(session),
|
|
328
|
+
has_csrf_token: Boolean(csrfToken),
|
|
329
|
+
has_csrf_header: Boolean(header),
|
|
330
|
+
skip_csrf_check: skipCSRFCheck
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
if (!session) {
|
|
334
|
+
ctx?.logger?.log("SESSION_TOKEN_MISSING");
|
|
335
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
336
|
+
}
|
|
337
|
+
if (!skipCSRFCheck) {
|
|
338
|
+
if (!csrfToken) {
|
|
339
|
+
ctx?.logger?.log("CSRF_TOKEN_MISSING");
|
|
340
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
341
|
+
}
|
|
342
|
+
if (!header) {
|
|
343
|
+
ctx?.logger?.log("CSRF_HEADER_MISSING");
|
|
344
|
+
throw new AuthSecurityError("CSRF_HEADER_MISSING", "The CSRF header is missing.");
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
await verifyCSRF(ctx.jose, csrfToken, header);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
|
|
350
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
|
|
351
|
+
}
|
|
352
|
+
ctx?.logger?.log("SIGN_OUT_CSRF_VERIFIED");
|
|
353
|
+
} else {
|
|
354
|
+
try {
|
|
355
|
+
await ctx.jose.verifyJWS(csrfToken);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
ctx?.logger?.log("CSRF_TOKEN_INVALID", { structuredData: { error_type: getErrorName(error) } });
|
|
358
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "CSRF token verification failed");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
await ctx.jose.decodeJWT(session);
|
|
363
|
+
ctx?.logger?.log("SIGN_OUT_SUCCESS");
|
|
364
|
+
} catch (error) {
|
|
365
|
+
ctx?.logger?.log("INVALID_JWT_TOKEN", { structuredData: { error_type: getErrorName(error) } });
|
|
366
|
+
}
|
|
367
|
+
const headersList = new import_router2.HeadersBuilder(secureApiHeaders).setHeader("Location", redirectTo).setCookie(ctx.cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(ctx.cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
368
|
+
return Response.json(
|
|
369
|
+
{ redirect: Boolean(redirectTo), url: redirectTo },
|
|
370
|
+
{
|
|
371
|
+
status: 202,
|
|
372
|
+
headers: headersList
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
};
|
|
239
376
|
|
|
240
377
|
// src/actions/signIn/authorization.ts
|
|
241
|
-
var
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
378
|
+
var getTrustedOrigins = async (request, trustedOrigins) => {
|
|
379
|
+
if (!trustedOrigins) return [];
|
|
380
|
+
const raw = typeof trustedOrigins === "function" ? await trustedOrigins(request) : trustedOrigins;
|
|
381
|
+
return Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
|
|
382
|
+
};
|
|
383
|
+
var getBaseURL2 = async ({
|
|
384
|
+
ctx,
|
|
385
|
+
request,
|
|
386
|
+
headers: headersInit
|
|
387
|
+
}) => {
|
|
388
|
+
const origin = getEnv("BASE_URL") || ctx?.baseURL;
|
|
389
|
+
if (origin && origin !== "/") return origin;
|
|
390
|
+
if (ctx?.trustedProxyHeaders) {
|
|
391
|
+
const headers = headersInit && new Headers(headersInit) || request?.headers;
|
|
392
|
+
const protocol = headers?.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Proto") ?? "http";
|
|
393
|
+
const host = headers?.get("Host") ?? headers?.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? headers?.get("X-Forwarded-Host") ?? null;
|
|
394
|
+
if (host) return `${protocol}://${host}`;
|
|
395
|
+
throw new AuthInternalError(
|
|
396
|
+
"INVALID_OAUTH_CONFIGURATION",
|
|
397
|
+
"The URL cannot be constructed. Please set the BASE_URL environment variable or provide trusted proxy host headers."
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
return new URL(request?.url ?? "not-found").origin;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
throw new AuthInternalError(
|
|
404
|
+
"INVALID_OAUTH_CONFIGURATION",
|
|
405
|
+
"The URL cannot be constructed. Please set the BASE_URL environment variable or enable trustedProxyHeaders.",
|
|
406
|
+
{ cause: error }
|
|
407
|
+
);
|
|
249
408
|
}
|
|
250
409
|
};
|
|
251
|
-
var
|
|
410
|
+
var getOriginURL = async (request, context) => {
|
|
411
|
+
const trustedOrigins = await getTrustedOrigins(request, context?.trustedOrigins);
|
|
412
|
+
trustedOrigins.push(new URL(request.url).origin);
|
|
413
|
+
const origin = await getBaseURL2({ request, ctx: context });
|
|
414
|
+
if (!isTrustedOrigin(origin, trustedOrigins)) {
|
|
415
|
+
context?.logger?.log("UNTRUSTED_ORIGIN", { structuredData: { origin } });
|
|
416
|
+
throw new AuthInternalError("UNTRUSTED_ORIGIN", "The constructed origin URL is not trusted.");
|
|
417
|
+
}
|
|
418
|
+
return origin;
|
|
419
|
+
};
|
|
420
|
+
var createRedirectTo = async (request, redirectTo, context) => {
|
|
252
421
|
try {
|
|
253
422
|
const headers = request.headers;
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
|
|
423
|
+
const requestOrigin = await getOriginURL(request, context);
|
|
424
|
+
const origins = await getTrustedOrigins(request, context?.trustedOrigins);
|
|
425
|
+
const validateURL = (url) => {
|
|
426
|
+
if (!isRelativeURL(url) && !isValidURL(url)) return "/";
|
|
427
|
+
if (isRelativeURL(url)) return url;
|
|
428
|
+
if (origins.length > 0) {
|
|
429
|
+
if (isTrustedOrigin(url, origins)) {
|
|
430
|
+
const urlOrigin = new URL(url).origin;
|
|
431
|
+
for (const pattern of origins) {
|
|
432
|
+
const regex = patternToRegex(pattern);
|
|
433
|
+
if (regex?.test(urlOrigin)) {
|
|
434
|
+
return isSameOrigin(url, request.url) ? extractPath(url) : url;
|
|
435
|
+
}
|
|
436
|
+
if (isValidURL(pattern) && equals(new URL(pattern).origin, urlOrigin)) return url;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
context?.logger?.log("OPEN_REDIRECT_ATTACK");
|
|
440
|
+
return "/";
|
|
260
441
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
throw new AuthSecurityError(
|
|
264
|
-
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
265
|
-
"The redirectTo parameter does not match the hosted origin."
|
|
266
|
-
);
|
|
442
|
+
if (isSameOrigin(url, requestOrigin)) {
|
|
443
|
+
return extractPath(url);
|
|
267
444
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
273
|
-
throw new AuthSecurityError(
|
|
274
|
-
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
275
|
-
"The referer of the request does not match the hosted origin."
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
return sanitizeURL(refererURL.pathname);
|
|
279
|
-
}
|
|
280
|
-
if (origin) {
|
|
281
|
-
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
282
|
-
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
283
|
-
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
284
|
-
}
|
|
285
|
-
return sanitizeURL(originURL.pathname);
|
|
286
|
-
}
|
|
287
|
-
return "/";
|
|
445
|
+
context?.logger?.log("OPEN_REDIRECT_ATTACK");
|
|
446
|
+
return "/";
|
|
447
|
+
};
|
|
448
|
+
return validateURL(redirectTo ?? headers.get("Referer") ?? headers.get("Origin") ?? "/");
|
|
288
449
|
} catch (error) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
450
|
+
context?.logger?.log("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED");
|
|
451
|
+
return "/";
|
|
293
452
|
}
|
|
294
453
|
};
|
|
295
454
|
|
|
296
455
|
// src/actions/signOut/signOut.ts
|
|
297
|
-
var config = (0,
|
|
456
|
+
var config = (0, import_router3.createEndpointConfig)({
|
|
298
457
|
schemas: {
|
|
299
|
-
searchParams:
|
|
300
|
-
token_type_hint:
|
|
301
|
-
redirectTo:
|
|
458
|
+
searchParams: import_v4.z.object({
|
|
459
|
+
token_type_hint: import_v4.z.literal("session_token"),
|
|
460
|
+
redirectTo: import_v4.z.string().optional()
|
|
302
461
|
})
|
|
303
462
|
}
|
|
304
463
|
});
|
|
305
|
-
var signOutAction = (0,
|
|
464
|
+
var signOutAction = (0, import_router3.createEndpoint)(
|
|
306
465
|
"POST",
|
|
307
466
|
"/signOut",
|
|
308
467
|
async (ctx) => {
|
|
309
468
|
const {
|
|
310
469
|
request,
|
|
311
|
-
headers,
|
|
312
470
|
searchParams: { redirectTo },
|
|
313
|
-
context
|
|
471
|
+
context
|
|
314
472
|
} = ctx;
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
320
|
-
}
|
|
321
|
-
if (!csrfToken) {
|
|
322
|
-
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
323
|
-
}
|
|
324
|
-
if (!header) {
|
|
325
|
-
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF header is missing.");
|
|
326
|
-
}
|
|
327
|
-
await verifyCSRF(jose, csrfToken, header);
|
|
328
|
-
await jose.decodeJWT(session);
|
|
329
|
-
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
330
|
-
const location = createRedirectTo(
|
|
331
|
-
new Request(normalizedOriginPath, {
|
|
332
|
-
headers: headers.toHeaders()
|
|
473
|
+
const baseURL = getBaseURL(request);
|
|
474
|
+
const location = await createRedirectTo(
|
|
475
|
+
new Request(baseURL, {
|
|
476
|
+
headers: request.headers
|
|
333
477
|
}),
|
|
334
|
-
redirectTo
|
|
478
|
+
redirectTo,
|
|
479
|
+
context
|
|
335
480
|
);
|
|
336
|
-
|
|
337
|
-
|
|
481
|
+
return await signOut({
|
|
482
|
+
ctx: context,
|
|
483
|
+
headers: request.headers,
|
|
484
|
+
redirectTo: location
|
|
485
|
+
});
|
|
338
486
|
},
|
|
339
487
|
config
|
|
340
488
|
);
|