@wbce-d9/api 11.1.6 → 12.0.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.
|
@@ -76,6 +76,14 @@ export class OpenIDAuthDriver extends BaseOAuthDriver {
|
|
|
76
76
|
const client = await this.client;
|
|
77
77
|
const codeChallenge = generators.codeChallenge(codeVerifier);
|
|
78
78
|
const paramsConfig = typeof this.config['params'] === 'object' ? this.config['params'] : {};
|
|
79
|
+
const redirectAfterLogin = additionalParams?.['redirect'];
|
|
80
|
+
delete additionalParams?.['redirect'];
|
|
81
|
+
let finalRedirectUri = this.redirectUrl;
|
|
82
|
+
if (redirectAfterLogin) {
|
|
83
|
+
const redirectUriWithParams = new URL(this.redirectUrl);
|
|
84
|
+
redirectUriWithParams.searchParams.set('redirect', redirectAfterLogin);
|
|
85
|
+
finalRedirectUri = redirectUriWithParams.toString();
|
|
86
|
+
}
|
|
79
87
|
return client.authorizationUrl({
|
|
80
88
|
scope: this.config['scope'] ?? 'openid profile email',
|
|
81
89
|
access_type: 'offline',
|
|
@@ -86,6 +94,7 @@ export class OpenIDAuthDriver extends BaseOAuthDriver {
|
|
|
86
94
|
// Some providers require state even with PKCE
|
|
87
95
|
state: codeChallenge,
|
|
88
96
|
nonce: codeChallenge,
|
|
97
|
+
redirect_uri: finalRedirectUri,
|
|
89
98
|
...additionalParams,
|
|
90
99
|
});
|
|
91
100
|
}
|
|
@@ -147,28 +156,40 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
147
156
|
expiresIn: '5m',
|
|
148
157
|
issuer: 'directus',
|
|
149
158
|
});
|
|
150
|
-
|
|
159
|
+
const additionalParams = { ...req.query };
|
|
160
|
+
delete additionalParams['prompt'];
|
|
161
|
+
const authUrl = await provider.generateAuthUrl(codeVerifier, prompt, additionalParams);
|
|
162
|
+
const urlParams = new URL(authUrl);
|
|
163
|
+
const state = urlParams.searchParams.get('state');
|
|
164
|
+
const cookieName = `openid.${providerName}.${state || ''}`;
|
|
165
|
+
res.cookie(cookieName, token, {
|
|
151
166
|
httpOnly: true,
|
|
152
167
|
sameSite: 'lax',
|
|
153
168
|
});
|
|
154
|
-
|
|
155
|
-
delete additionalParams['prompt'];
|
|
156
|
-
delete additionalParams['redirect'];
|
|
157
|
-
return res.redirect(await provider.generateAuthUrl(codeVerifier, prompt, additionalParams));
|
|
169
|
+
return res.redirect(authUrl);
|
|
158
170
|
}), respond);
|
|
159
171
|
router.post('/callback', express.urlencoded({ extended: false }), (req, res) => {
|
|
160
172
|
res.redirect(303, `./callback?${new URLSearchParams(req.body)}`);
|
|
161
173
|
}, respond);
|
|
162
174
|
router.get('/callback', asyncHandler(async (req, res, next) => {
|
|
175
|
+
const redirectUrl = req.query['redirect'];
|
|
176
|
+
const validRedirectUrl = isRedirectAllowedOnLogin(redirectUrl, providerName) ? redirectUrl : null;
|
|
177
|
+
const state = req.query['state'];
|
|
178
|
+
const cookieName = `openid.${providerName}.${state || ''}`;
|
|
179
|
+
const cookieValue = req.cookies[cookieName];
|
|
163
180
|
let tokenData;
|
|
164
181
|
try {
|
|
165
|
-
tokenData = jwt.verify(
|
|
182
|
+
tokenData = jwt.verify(cookieValue, env['SECRET'], {
|
|
166
183
|
issuer: 'directus',
|
|
167
184
|
});
|
|
168
185
|
}
|
|
169
186
|
catch (e) {
|
|
170
|
-
logger.warn(e, `[OpenID] Couldn't verify OpenID cookie`);
|
|
171
|
-
|
|
187
|
+
logger.warn(e, `[OpenID] Couldn't verify OpenID cookie ${state ? `for state ${state}` : ''}`);
|
|
188
|
+
const baseUrl = env['PUBLIC_URL'];
|
|
189
|
+
const loginPath = '/admin/login';
|
|
190
|
+
const url = new URL(loginPath, baseUrl);
|
|
191
|
+
const redirectTo = validRedirectUrl || url.toString();
|
|
192
|
+
return res.redirect(`${redirectTo}?reason=INVALID_CREDENTIALS`);
|
|
172
193
|
}
|
|
173
194
|
const { verifier, redirect, prompt } = tokenData;
|
|
174
195
|
const accountability = {
|
|
@@ -187,7 +208,7 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
187
208
|
});
|
|
188
209
|
let authResponse;
|
|
189
210
|
try {
|
|
190
|
-
res.clearCookie(
|
|
211
|
+
res.clearCookie(cookieName);
|
|
191
212
|
authResponse = await authenticationService.login(providerName, {
|
|
192
213
|
code: req.query['code'],
|
|
193
214
|
codeVerifier: verifier,
|
|
@@ -2,7 +2,6 @@ import knex from 'knex';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { promisify } from 'util';
|
|
6
5
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
6
|
export default function createDBConnection(client, credentials) {
|
|
8
7
|
let connection = {};
|
|
@@ -46,10 +45,9 @@ export default function createDBConnection(client, credentials) {
|
|
|
46
45
|
knexConfig.useNullAsDefault = true;
|
|
47
46
|
}
|
|
48
47
|
if (client === 'cockroachdb') {
|
|
49
|
-
knexConfig.pool.afterCreate =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await run('SET default_int_size = 4');
|
|
48
|
+
knexConfig.pool.afterCreate = (conn, callback) => {
|
|
49
|
+
conn.query('SET serial_normalization = "sql_sequence"');
|
|
50
|
+
conn.query('SET default_int_size = 4');
|
|
53
51
|
callback(null, conn);
|
|
54
52
|
};
|
|
55
53
|
}
|
package/dist/database/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import { dirname } from 'node:path';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { performance } from 'perf_hooks';
|
|
9
|
-
import { promisify } from 'util';
|
|
10
9
|
import env from '../env.js';
|
|
11
10
|
import logger from '../logger.js';
|
|
12
11
|
import { getConfigFromEnv } from '../utils/get-config-from-env.js';
|
|
@@ -77,29 +76,31 @@ export default function getDatabase() {
|
|
|
77
76
|
};
|
|
78
77
|
if (client === 'sqlite3') {
|
|
79
78
|
knexConfig.useNullAsDefault = true;
|
|
80
|
-
poolConfig.afterCreate =
|
|
79
|
+
poolConfig.afterCreate = (conn, callback) => {
|
|
81
80
|
logger.trace('Enabling SQLite Foreign Keys support...');
|
|
82
|
-
|
|
83
|
-
await run('PRAGMA foreign_keys = ON');
|
|
81
|
+
conn.run('PRAGMA foreign_keys = ON');
|
|
84
82
|
callback(null, conn);
|
|
85
83
|
};
|
|
86
84
|
}
|
|
87
85
|
if (client === 'cockroachdb') {
|
|
88
|
-
poolConfig.afterCreate =
|
|
86
|
+
poolConfig.afterCreate = (conn, callback) => {
|
|
89
87
|
logger.trace('Setting CRDB serial_normalization and default_int_size');
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await run('SET default_int_size = 4');
|
|
88
|
+
conn.query('SET serial_normalization = "sql_sequence"');
|
|
89
|
+
conn.query('SET default_int_size = 4');
|
|
93
90
|
callback(null, conn);
|
|
94
91
|
};
|
|
95
92
|
}
|
|
96
93
|
if (client === 'mysql') {
|
|
97
|
-
poolConfig.afterCreate =
|
|
94
|
+
poolConfig.afterCreate = (conn, callback) => {
|
|
98
95
|
logger.trace('Retrieving database version');
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
conn.query('SELECT @@version AS version;', (error, results) => {
|
|
97
|
+
if (error) {
|
|
98
|
+
callback(error, null);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
databaseVersion = results[0]?.version || results[0]?.['@@version'];
|
|
102
|
+
callback(null, conn);
|
|
103
|
+
});
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
106
|
if (client === 'mssql') {
|
|
@@ -17,7 +17,7 @@ export default defineOperationApi({
|
|
|
17
17
|
jail.setSync('process', { env: environmentVariables }, { copy: true });
|
|
18
18
|
jail.setSync('module', { exports: null }, { copy: true });
|
|
19
19
|
// Adding a secure logger for the isolate
|
|
20
|
-
const createLoggerCallback = (logFn) => new ivm.Callback((...args) => logFn(args.length === 1 ? args[0] : args), { sync: true });
|
|
20
|
+
const createLoggerCallback = (logFn) => new ivm.Callback((...args) => logFn(args.length === 1 ? args[0] : args), () => { }, { sync: true });
|
|
21
21
|
jail.setSync('console', {
|
|
22
22
|
log: createLoggerCallback(() => logger.info),
|
|
23
23
|
info: createLoggerCallback(() => logger.info),
|
|
@@ -27,12 +27,12 @@ export default defineOperationApi({
|
|
|
27
27
|
trace: createLoggerCallback(() => logger.trace),
|
|
28
28
|
}, { copy: true });
|
|
29
29
|
// Executing the code within the isolate
|
|
30
|
-
await context.eval(code, { timeout: executionTimeout });
|
|
30
|
+
await context.eval(code, { timeout: executionTimeout }, () => { });
|
|
31
31
|
const dataCopy = new ivm.ExternalCopy({ data });
|
|
32
32
|
const resultReference = await context.evalClosure(`return module.exports($0.data)`, [dataCopy.copyInto()], {
|
|
33
33
|
result: { reference: true, promise: true },
|
|
34
34
|
timeout: executionTimeout,
|
|
35
|
-
});
|
|
35
|
+
}, () => { });
|
|
36
36
|
const finalResult = await resultReference.copy();
|
|
37
37
|
// Cleanup memory
|
|
38
38
|
resultReference.release();
|
package/dist/types/meta.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wbce-d9/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"description": "Directus is a real-time API and App dashboard for managing SQL database content",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"icc": "3.0.0",
|
|
102
102
|
"inquirer": "9.1.5",
|
|
103
103
|
"ioredis": "5.3.2",
|
|
104
|
-
"isolated-vm": "^
|
|
104
|
+
"isolated-vm": "^6.0.1",
|
|
105
105
|
"joi": "17.9.1",
|
|
106
106
|
"js-yaml": "4.1.0",
|
|
107
107
|
"js2xmlparser": "5.0.0",
|
|
@@ -143,20 +143,20 @@
|
|
|
143
143
|
"uuid": "9.0.0",
|
|
144
144
|
"uuid-validate": "0.0.3",
|
|
145
145
|
"wellknown": "0.5.0",
|
|
146
|
-
"@wbce-d9/app": "9.33.
|
|
147
|
-
"@wbce-d9/
|
|
148
|
-
"@wbce-d9/
|
|
149
|
-
"@wbce-d9/extensions-sdk": "
|
|
150
|
-
"@wbce-d9/schema": "9.26.4",
|
|
146
|
+
"@wbce-d9/app": "9.33.8",
|
|
147
|
+
"@wbce-d9/constants": "10.0.0",
|
|
148
|
+
"@wbce-d9/exceptions": "10.0.0",
|
|
149
|
+
"@wbce-d9/extensions-sdk": "10.0.0",
|
|
151
150
|
"@wbce-d9/specs": "9.26.5",
|
|
152
|
-
"@wbce-d9/
|
|
153
|
-
"@wbce-d9/storage
|
|
154
|
-
"@wbce-d9/storage-driver-
|
|
155
|
-
"@wbce-d9/storage-driver-
|
|
156
|
-
"@wbce-d9/storage-driver-
|
|
157
|
-
"@wbce-d9/storage-driver-
|
|
158
|
-
"@wbce-d9/
|
|
159
|
-
"@wbce-d9/
|
|
151
|
+
"@wbce-d9/schema": "10.0.0",
|
|
152
|
+
"@wbce-d9/storage": "10.0.0",
|
|
153
|
+
"@wbce-d9/storage-driver-azure": "10.0.0",
|
|
154
|
+
"@wbce-d9/storage-driver-cloudinary": "10.0.0",
|
|
155
|
+
"@wbce-d9/storage-driver-gcs": "10.0.0",
|
|
156
|
+
"@wbce-d9/storage-driver-local": "10.0.0",
|
|
157
|
+
"@wbce-d9/update-check": "10.0.0",
|
|
158
|
+
"@wbce-d9/storage-driver-s3": "10.0.0",
|
|
159
|
+
"@wbce-d9/utils": "10.0.0"
|
|
160
160
|
},
|
|
161
161
|
"devDependencies": {
|
|
162
162
|
"@ngneat/falso": "6.4.0",
|
|
@@ -197,14 +197,14 @@
|
|
|
197
197
|
"@types/uuid-validate": "0.0.1",
|
|
198
198
|
"@types/wellknown": "0.5.4",
|
|
199
199
|
"@vitest/coverage-c8": "0.30.1",
|
|
200
|
-
"@wbce-d9/tsconfig": "0.0
|
|
200
|
+
"@wbce-d9/tsconfig": "2.0.0",
|
|
201
201
|
"copyfiles": "2.4.1",
|
|
202
202
|
"form-data": "4.0.4",
|
|
203
203
|
"knex-mock-client": "3.0.2",
|
|
204
204
|
"supertest": "6.3.3",
|
|
205
205
|
"typescript": "5.0.4",
|
|
206
206
|
"vitest": "0.30.1",
|
|
207
|
-
"@wbce-d9/types": "
|
|
207
|
+
"@wbce-d9/types": "10.0.0"
|
|
208
208
|
},
|
|
209
209
|
"optionalDependencies": {
|
|
210
210
|
"@keyv/redis": "2.5.7",
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
"tedious": "18.6.1"
|
|
219
219
|
},
|
|
220
220
|
"engines": {
|
|
221
|
-
"node": ">=
|
|
221
|
+
"node": ">=22"
|
|
222
222
|
},
|
|
223
223
|
"scripts": {
|
|
224
224
|
"build": "tsc --build && copyfiles \"src/**/*.{yaml,liquid}\" -u 1 dist",
|