@korajs/auth 1.0.0-beta.0 → 1.0.0-beta.1
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/server.cjs +25 -4
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +25 -4
- package/dist/server.js.map +1 -1
- package/package.json +6 -5
package/dist/server.js
CHANGED
|
@@ -77,7 +77,7 @@ var MAX_PASSWORD_LENGTH = 128;
|
|
|
77
77
|
var MAX_NAME_LENGTH = 200;
|
|
78
78
|
var CHALLENGE_TTL_MS = 6e4;
|
|
79
79
|
function isValidEmail(email) {
|
|
80
|
-
if (email.length === 0 || email.length > 254) {
|
|
80
|
+
if (typeof email !== "string" || email.length === 0 || email.length > 254) {
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
83
|
const atIndex = email.indexOf("@");
|
|
@@ -97,6 +97,9 @@ function isValidEmail(email) {
|
|
|
97
97
|
return true;
|
|
98
98
|
}
|
|
99
99
|
function sanitizeName(name) {
|
|
100
|
+
if (typeof name !== "string") {
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
100
103
|
const cleaned = name.replace(/[\x00-\x1f\x7f]/g, "");
|
|
101
104
|
const trimmed = cleaned.trim();
|
|
102
105
|
if (trimmed.length > MAX_NAME_LENGTH) {
|
|
@@ -147,7 +150,7 @@ var BuiltInAuthRoutes = class {
|
|
|
147
150
|
}
|
|
148
151
|
};
|
|
149
152
|
}
|
|
150
|
-
if (body.password.length < MIN_PASSWORD_LENGTH) {
|
|
153
|
+
if (typeof body.password !== "string" || body.password.length < MIN_PASSWORD_LENGTH) {
|
|
151
154
|
return {
|
|
152
155
|
status: 400,
|
|
153
156
|
body: {
|
|
@@ -211,6 +214,12 @@ var BuiltInAuthRoutes = class {
|
|
|
211
214
|
* @returns Auth response with the user and tokens, or an error
|
|
212
215
|
*/
|
|
213
216
|
async handleSignIn(body, clientIp) {
|
|
217
|
+
if (typeof body.email !== "string" || typeof body.password !== "string") {
|
|
218
|
+
return {
|
|
219
|
+
status: 400,
|
|
220
|
+
body: { error: "Email and password are required." }
|
|
221
|
+
};
|
|
222
|
+
}
|
|
214
223
|
const rateLimitKey = clientIp ? `signin:${body.email.toLowerCase()}:${clientIp}` : `signin:${body.email.toLowerCase()}`;
|
|
215
224
|
if (!await this.rateLimiter.isAllowed(rateLimitKey)) {
|
|
216
225
|
return {
|
|
@@ -714,6 +723,9 @@ function decodeJwt(token) {
|
|
|
714
723
|
}
|
|
715
724
|
}
|
|
716
725
|
function verifyJwt(token, secret) {
|
|
726
|
+
if (typeof token !== "string") {
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
717
729
|
const parts = token.split(".");
|
|
718
730
|
if (parts.length !== 3) {
|
|
719
731
|
return null;
|
|
@@ -1716,6 +1728,11 @@ function createDefaultTokenManager(options) {
|
|
|
1716
1728
|
"createKoraAuthServer requires jwtSecret in production. Set KORA_AUTH_SECRET or pass jwtSecret."
|
|
1717
1729
|
);
|
|
1718
1730
|
}
|
|
1731
|
+
if (!secret) {
|
|
1732
|
+
console.warn(
|
|
1733
|
+
"[kora] No JWT secret configured; using an ephemeral random secret. Every token is invalidated when the process restarts. Set KORA_AUTH_SECRET or pass jwtSecret to createKoraAuthServer for stable sessions."
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1719
1736
|
return new TokenManager({
|
|
1720
1737
|
secret: secret ?? TokenManager.generateSecret(),
|
|
1721
1738
|
revocationStore: new InMemoryTokenRevocationStore(),
|
|
@@ -2018,7 +2035,11 @@ function notFound() {
|
|
|
2018
2035
|
return { status: 404, body: { error: "Not found" } };
|
|
2019
2036
|
}
|
|
2020
2037
|
function readEnvSecret() {
|
|
2021
|
-
|
|
2038
|
+
if (typeof process === "undefined") {
|
|
2039
|
+
return void 0;
|
|
2040
|
+
}
|
|
2041
|
+
const value = process.env.KORA_AUTH_SECRET;
|
|
2042
|
+
return value && value.trim().length > 0 ? value : void 0;
|
|
2022
2043
|
}
|
|
2023
2044
|
function isProduction() {
|
|
2024
2045
|
return typeof process !== "undefined" && process.env.NODE_ENV === "production";
|
|
@@ -3515,7 +3536,7 @@ var MAX_ORG_NAME_LENGTH = 200;
|
|
|
3515
3536
|
var MAX_SLUG_LENGTH = 100;
|
|
3516
3537
|
var SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,98}[a-z0-9]$/;
|
|
3517
3538
|
function isValidEmail2(email) {
|
|
3518
|
-
if (email.length === 0 || email.length > 254) return false;
|
|
3539
|
+
if (typeof email !== "string" || email.length === 0 || email.length > 254) return false;
|
|
3519
3540
|
const atIndex = email.indexOf("@");
|
|
3520
3541
|
if (atIndex < 1) return false;
|
|
3521
3542
|
const domain = email.slice(atIndex + 1);
|