@cedarjs/auth-dbauth-api 9.0.0-canary.1784 → 9.0.0-canary.3124
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/DbAuthHandler.d.ts +37 -43
- package/dist/DbAuthHandler.d.ts.map +1 -1
- package/dist/DbAuthHandler.js +171 -162
- package/dist/decoder.js +5 -30
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -61
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -36
- package/dist/originValidation.d.ts +131 -0
- package/dist/originValidation.d.ts.map +1 -0
- package/dist/originValidation.js +92 -0
- package/dist/session.d.ts +114 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +103 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +21 -68
- package/package.json +25 -16
- package/LICENSE +0 -21
package/dist/shared.js
CHANGED
|
@@ -1,71 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var shared_exports = {};
|
|
30
|
-
__export(shared_exports, {
|
|
31
|
-
dbAuthSession: () => dbAuthSession,
|
|
32
|
-
decryptSession: () => decryptSession,
|
|
33
|
-
encryptSession: () => encryptSession,
|
|
34
|
-
extractCookie: () => extractCookie,
|
|
35
|
-
extractHashingOptions: () => extractHashingOptions,
|
|
36
|
-
generateCookieName: () => generateCookieName,
|
|
37
|
-
getDbAuthResponseBuilder: () => getDbAuthResponseBuilder,
|
|
38
|
-
getSession: () => getSession,
|
|
39
|
-
hashPassword: () => hashPassword,
|
|
40
|
-
hashToken: () => hashToken,
|
|
41
|
-
isLegacySession: () => isLegacySession,
|
|
42
|
-
legacyHashPassword: () => legacyHashPassword,
|
|
43
|
-
webAuthnSession: () => webAuthnSession
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(shared_exports);
|
|
46
|
-
var import_node_crypto = __toESM(require("node:crypto"));
|
|
47
|
-
var import_api = require("@cedarjs/api");
|
|
48
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
49
|
-
var DbAuthError = __toESM(require("./errors"));
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { getEventHeader, isFetchApiRequest } from "@cedarjs/api";
|
|
3
|
+
import { getConfig, getConfigPath } from "@cedarjs/project-config";
|
|
4
|
+
import * as DbAuthError from "./errors.js";
|
|
50
5
|
const DEFAULT_SCRYPT_OPTIONS = {
|
|
51
6
|
cost: 2 ** 14,
|
|
52
7
|
blockSize: 8,
|
|
53
8
|
parallelization: 1
|
|
54
9
|
};
|
|
55
10
|
const getPort = () => {
|
|
56
|
-
let configPath;
|
|
57
11
|
try {
|
|
58
|
-
|
|
12
|
+
getConfigPath();
|
|
59
13
|
} catch {
|
|
60
14
|
return 8911;
|
|
61
15
|
}
|
|
62
|
-
return
|
|
16
|
+
return getConfig().api.port;
|
|
63
17
|
};
|
|
64
18
|
const eventGraphiQLHeadersCookie = (event) => {
|
|
65
19
|
if (process.env.NODE_ENV !== "development") {
|
|
66
20
|
return;
|
|
67
21
|
}
|
|
68
|
-
const impersationationHeader =
|
|
22
|
+
const impersationationHeader = getEventHeader(
|
|
69
23
|
event,
|
|
70
24
|
"rw-studio-impersonation-cookie"
|
|
71
25
|
);
|
|
@@ -73,7 +27,7 @@ const eventGraphiQLHeadersCookie = (event) => {
|
|
|
73
27
|
return impersationationHeader;
|
|
74
28
|
}
|
|
75
29
|
try {
|
|
76
|
-
if (!
|
|
30
|
+
if (!isFetchApiRequest(event)) {
|
|
77
31
|
const jsonBody = JSON.parse(event.body ?? "{}");
|
|
78
32
|
return jsonBody?.extensions?.headers?.cookie || jsonBody?.extensions?.headers?.Cookie;
|
|
79
33
|
}
|
|
@@ -91,17 +45,17 @@ const legacyDecryptSession = (encryptedText) => {
|
|
|
91
45
|
const md5Hashes = [];
|
|
92
46
|
let digest = password;
|
|
93
47
|
for (let i = 0; i < 3; i++) {
|
|
94
|
-
md5Hashes[i] =
|
|
48
|
+
md5Hashes[i] = crypto.createHash("md5").update(digest).digest();
|
|
95
49
|
digest = Buffer.concat([md5Hashes[i], password]);
|
|
96
50
|
}
|
|
97
51
|
const key = Buffer.concat([md5Hashes[0], md5Hashes[1]]);
|
|
98
52
|
const iv = md5Hashes[2];
|
|
99
53
|
const contents = cypher.slice(16);
|
|
100
|
-
const decipher =
|
|
54
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
101
55
|
return decipher.update(contents) + decipher.final("utf-8");
|
|
102
56
|
};
|
|
103
57
|
const extractCookie = (event) => {
|
|
104
|
-
return eventGraphiQLHeadersCookie(event) ||
|
|
58
|
+
return eventGraphiQLHeadersCookie(event) || getEventHeader(event, "Cookie");
|
|
105
59
|
};
|
|
106
60
|
const isLegacySession = (text) => {
|
|
107
61
|
if (!text) {
|
|
@@ -118,7 +72,7 @@ const decryptSession = (text) => {
|
|
|
118
72
|
const [encryptedText, iv] = text.split("|");
|
|
119
73
|
try {
|
|
120
74
|
if (iv) {
|
|
121
|
-
const decipher =
|
|
75
|
+
const decipher = crypto.createDecipheriv(
|
|
122
76
|
"aes-256-cbc",
|
|
123
77
|
process.env.SESSION_SECRET.substring(0, 32),
|
|
124
78
|
Buffer.from(iv, "base64")
|
|
@@ -135,8 +89,8 @@ const decryptSession = (text) => {
|
|
|
135
89
|
}
|
|
136
90
|
};
|
|
137
91
|
const encryptSession = (dataString) => {
|
|
138
|
-
const iv =
|
|
139
|
-
const cipher =
|
|
92
|
+
const iv = crypto.randomBytes(16);
|
|
93
|
+
const cipher = crypto.createCipheriv(
|
|
140
94
|
"aes-256-cbc",
|
|
141
95
|
process.env.SESSION_SECRET.substring(0, 32),
|
|
142
96
|
iv
|
|
@@ -183,13 +137,13 @@ const webAuthnSession = (event) => {
|
|
|
183
137
|
return webAuthnCookie.split("=")[1].trim();
|
|
184
138
|
};
|
|
185
139
|
const hashToken = (token) => {
|
|
186
|
-
return
|
|
140
|
+
return crypto.createHash("sha256").update(token).digest("hex");
|
|
187
141
|
};
|
|
188
142
|
const hashPassword = (text, {
|
|
189
|
-
salt =
|
|
143
|
+
salt = crypto.randomBytes(32).toString("hex"),
|
|
190
144
|
options = DEFAULT_SCRYPT_OPTIONS
|
|
191
145
|
} = {}) => {
|
|
192
|
-
const encryptedString =
|
|
146
|
+
const encryptedString = crypto.scryptSync(text.normalize("NFC"), salt, 32, options).toString("hex");
|
|
193
147
|
const optionsToString = [
|
|
194
148
|
options.cost,
|
|
195
149
|
options.blockSize,
|
|
@@ -198,9 +152,9 @@ const hashPassword = (text, {
|
|
|
198
152
|
return [`${encryptedString}|${optionsToString.join("|")}`, salt];
|
|
199
153
|
};
|
|
200
154
|
const legacyHashPassword = (text, salt) => {
|
|
201
|
-
const useSalt = salt ||
|
|
155
|
+
const useSalt = salt || crypto.randomBytes(32).toString("hex");
|
|
202
156
|
return [
|
|
203
|
-
|
|
157
|
+
crypto.pbkdf2Sync(text, useSalt, 1, 32, "SHA1").toString("hex"),
|
|
204
158
|
useSalt
|
|
205
159
|
];
|
|
206
160
|
};
|
|
@@ -251,8 +205,7 @@ const extractHashingOptions = (text) => {
|
|
|
251
205
|
return {};
|
|
252
206
|
}
|
|
253
207
|
};
|
|
254
|
-
|
|
255
|
-
0 && (module.exports = {
|
|
208
|
+
export {
|
|
256
209
|
dbAuthSession,
|
|
257
210
|
decryptSession,
|
|
258
211
|
encryptSession,
|
|
@@ -266,4 +219,4 @@ const extractHashingOptions = (text) => {
|
|
|
266
219
|
isLegacySession,
|
|
267
220
|
legacyHashPassword,
|
|
268
221
|
webAuthnSession
|
|
269
|
-
}
|
|
222
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-api",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3124",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
7
7
|
"directory": "packages/auth-providers/dbAuth/api"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"type": "
|
|
10
|
+
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"default": {
|
|
@@ -46,36 +46,45 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"scripts": {
|
|
49
|
-
"build": "
|
|
49
|
+
"build": "node ./build.mts",
|
|
50
50
|
"build:pack": "yarn pack -o cedarjs-auth-dbauth-api.tgz",
|
|
51
|
-
"build:types": "tsc --build --verbose ./tsconfig.json",
|
|
51
|
+
"build:types": "tsc --build --verbose ./tsconfig.build.json",
|
|
52
52
|
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
|
|
53
|
-
"check:attw": "yarn attw
|
|
53
|
+
"check:attw": "yarn cedar-fwtools-attw",
|
|
54
54
|
"check:package": "concurrently npm:check:attw yarn:publint",
|
|
55
55
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
56
56
|
"test": "vitest run",
|
|
57
57
|
"test:watch": "vitest watch"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cedarjs/project-config": "9.0.0-canary.
|
|
61
|
-
"base64url": "3.0.1",
|
|
60
|
+
"@cedarjs/project-config": "9.0.0-canary.3124",
|
|
62
61
|
"md5": "2.3.0",
|
|
63
62
|
"uuid": "11.1.0"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@cedarjs/
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
65
|
+
"@cedarjs/api": "9.0.0-canary.3124",
|
|
66
|
+
"@cedarjs/framework-tools": "9.0.0-canary.3124",
|
|
67
|
+
"@simplewebauthn/server": "13.3.3",
|
|
68
|
+
"@types/aws-lambda": "8.10.163",
|
|
70
69
|
"@types/md5": "2.3.6",
|
|
71
|
-
"concurrently": "9.2.
|
|
72
|
-
"publint": "0.3.
|
|
73
|
-
"tsx": "4.21.0",
|
|
70
|
+
"concurrently": "9.2.4",
|
|
71
|
+
"publint": "0.3.24",
|
|
74
72
|
"typescript": "5.9.3",
|
|
75
|
-
"vitest": "
|
|
73
|
+
"vitest": "4.1.11"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@simplewebauthn/server": "^13.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"@simplewebauthn/server": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=24"
|
|
76
85
|
},
|
|
77
86
|
"publishConfig": {
|
|
78
87
|
"access": "public"
|
|
79
88
|
},
|
|
80
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
|
|
81
90
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Cedar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|