@directus/api 32.2.0 → 33.0.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/ai/chat/lib/create-ui-stream.d.ts +1 -1
- package/dist/ai/tools/assets/index.js +1 -1
- package/dist/ai/tools/collections/index.js +2 -2
- package/dist/ai/tools/fields/index.js +2 -2
- package/dist/ai/tools/files/index.js +1 -1
- package/dist/ai/tools/flows/index.js +1 -1
- package/dist/ai/tools/folders/index.js +1 -1
- package/dist/ai/tools/items/index.js +2 -2
- package/dist/ai/tools/relations/index.js +1 -1
- package/dist/ai/tools/trigger-flow/index.js +1 -1
- package/dist/app.js +8 -8
- package/dist/auth/drivers/ldap.js +2 -2
- package/dist/auth/drivers/local.js +1 -1
- package/dist/auth/drivers/oauth2.d.ts +1 -2
- package/dist/auth/drivers/oauth2.js +22 -17
- package/dist/auth/drivers/openid.d.ts +1 -2
- package/dist/auth/drivers/openid.js +18 -13
- package/dist/auth/drivers/saml.js +3 -3
- package/dist/auth/utils/generate-callback-url.d.ts +11 -0
- package/dist/auth/utils/generate-callback-url.js +40 -0
- package/dist/auth/utils/is-login-redirect-allowed.d.ts +7 -0
- package/dist/{utils → auth/utils}/is-login-redirect-allowed.js +12 -9
- package/dist/cache.js +2 -2
- package/dist/cli/commands/bootstrap/index.js +2 -2
- package/dist/cli/commands/database/install.js +1 -1
- package/dist/cli/commands/database/migrate.js +1 -1
- package/dist/cli/commands/init/index.js +2 -2
- package/dist/cli/commands/roles/create.js +4 -4
- package/dist/cli/commands/schema/apply.js +3 -3
- package/dist/cli/commands/schema/snapshot.js +1 -1
- package/dist/cli/utils/create-db-connection.d.ts +1 -1
- package/dist/cli/utils/create-db-connection.js +1 -1
- package/dist/cli/utils/create-env/index.js +1 -1
- package/dist/constants.d.ts +7 -3
- package/dist/constants.js +7 -3
- package/dist/controllers/access.js +1 -1
- package/dist/controllers/assets.js +1 -1
- package/dist/controllers/extensions.js +1 -1
- package/dist/controllers/fields.js +2 -2
- package/dist/controllers/files.js +1 -1
- package/dist/controllers/items.js +1 -1
- package/dist/controllers/not-found.js +1 -1
- package/dist/controllers/relations.js +1 -1
- package/dist/database/errors/dialects/mysql.d.ts +1 -1
- package/dist/database/errors/dialects/postgres.d.ts +1 -1
- package/dist/database/errors/dialects/sqlite.d.ts +1 -1
- package/dist/database/errors/translate.d.ts +1 -1
- package/dist/database/errors/translate.js +1 -1
- package/dist/database/helpers/date/dialects/mssql.js +1 -1
- package/dist/database/helpers/date/dialects/mysql.js +1 -1
- package/dist/database/helpers/date/types.js +1 -1
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -0
- package/dist/database/helpers/schema/dialects/cockroachdb.js +24 -1
- package/dist/database/helpers/schema/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.d.ts +2 -1
- package/dist/database/helpers/schema/dialects/mysql.js +16 -3
- package/dist/database/helpers/schema/dialects/postgres.d.ts +1 -1
- package/dist/database/helpers/schema/types.d.ts +13 -0
- package/dist/database/helpers/schema/types.js +24 -0
- package/dist/database/index.js +4 -4
- package/dist/database/migrations/20220429A-add-flows.js +1 -1
- package/dist/database/migrations/20230526A-migrate-translation-strings.js +1 -1
- package/dist/database/migrations/20231009A-update-csv-fields-to-text.js +1 -1
- package/dist/database/migrations/20240204A-marketplace.js +9 -7
- package/dist/database/migrations/20240311A-deprecate-webhooks.d.ts +15 -0
- package/dist/database/migrations/20240311A-deprecate-webhooks.js +1 -1
- package/dist/database/migrations/20240806A-permissions-policies.js +2 -2
- package/dist/database/migrations/20240924A-migrate-legacy-comments.js +1 -1
- package/dist/database/migrations/20251014A-add-project-owner.js +1 -1
- package/dist/database/migrations/20251224A-remove-webhooks.d.ts +3 -0
- package/dist/database/migrations/20251224A-remove-webhooks.js +19 -0
- package/dist/database/migrations/20260113A-add-revisions-index.d.ts +3 -0
- package/dist/database/migrations/20260113A-add-revisions-index.js +41 -0
- package/dist/database/migrations/run.js +3 -3
- package/dist/database/run-ast/lib/apply-query/filter/get-filter-type.d.ts +2 -2
- package/dist/database/run-ast/lib/apply-query/filter/get-filter-type.js +1 -1
- package/dist/database/run-ast/lib/apply-query/filter/operator.js +1 -1
- package/dist/database/run-ast/lib/apply-query/sort.js +1 -1
- package/dist/database/run-ast/utils/get-column-pre-processor.js +2 -2
- package/dist/database/run-ast/utils/get-column.js +1 -1
- package/dist/database/seeds/run.js +3 -3
- package/dist/extensions/lib/get-extensions-path.js +1 -1
- package/dist/extensions/lib/get-extensions-settings.js +1 -1
- package/dist/extensions/lib/get-extensions.js +1 -1
- package/dist/extensions/lib/get-shared-deps-mapping.js +3 -3
- package/dist/extensions/lib/installation/manager.js +3 -3
- package/dist/extensions/lib/sandbox/register/route.d.ts +1 -1
- package/dist/extensions/lib/sync/status.js +1 -1
- package/dist/extensions/lib/sync/sync.js +7 -7
- package/dist/extensions/lib/sync/utils.js +2 -2
- package/dist/extensions/manager.d.ts +1 -1
- package/dist/extensions/manager.js +8 -8
- package/dist/flows.d.ts +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/logger/logs-stream.d.ts +1 -1
- package/dist/logger/logs-stream.js +1 -1
- package/dist/mailer.js +1 -1
- package/dist/metrics/lib/create-metrics.js +2 -2
- package/dist/middleware/authenticate.js +3 -3
- package/dist/middleware/collection-exists.js +1 -1
- package/dist/middleware/extract-token.js +1 -1
- package/dist/middleware/graphql.js +2 -2
- package/dist/middleware/validate-batch.js +1 -1
- package/dist/operations/exec/index.js +2 -1
- package/dist/operations/mail/index.js +1 -1
- package/dist/operations/mail/rate-limiter.js +2 -2
- package/dist/permissions/cache.js +5 -0
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.js +1 -1
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js +1 -1
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.js +2 -2
- package/dist/permissions/modules/process-ast/lib/inject-cases.js +1 -1
- package/dist/permissions/modules/process-ast/process-ast.js +1 -1
- package/dist/permissions/modules/process-payload/process-payload.js +1 -1
- package/dist/permissions/modules/validate-access/lib/validate-item-access.d.ts +13 -1
- package/dist/permissions/modules/validate-access/lib/validate-item-access.js +54 -6
- package/dist/permissions/modules/validate-access/validate-access.js +3 -2
- package/dist/rate-limiter.js +1 -1
- package/dist/request/is-denied-ip.js +1 -1
- package/dist/schedules/project.js +1 -1
- package/dist/schedules/telemetry.js +1 -1
- package/dist/schedules/tus.js +1 -1
- package/dist/server.js +4 -4
- package/dist/services/assets.d.ts +2 -1
- package/dist/services/assets.js +35 -8
- package/dist/services/authentication.js +2 -2
- package/dist/services/collections.js +1 -1
- package/dist/services/extensions.d.ts +1 -1
- package/dist/services/files/utils/get-metadata.d.ts +1 -1
- package/dist/services/files/utils/get-metadata.js +1 -1
- package/dist/services/files.d.ts +1 -1
- package/dist/services/files.js +4 -4
- package/dist/services/graphql/index.d.ts +1 -1
- package/dist/services/graphql/index.js +1 -1
- package/dist/services/graphql/resolvers/mutation.js +1 -1
- package/dist/services/graphql/schema/get-types.d.ts +1 -1
- package/dist/services/graphql/schema/read.js +1 -1
- package/dist/services/graphql/subscription.d.ts +1 -1
- package/dist/services/graphql/types/date.js +1 -1
- package/dist/services/graphql/types/hash.js +1 -1
- package/dist/services/graphql/utils/add-path-to-validation-error.js +1 -1
- package/dist/services/import-export.d.ts +1 -1
- package/dist/services/import-export.js +2 -2
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/services/mail/index.js +2 -2
- package/dist/services/mail/rate-limiter.js +2 -2
- package/dist/services/payload.js +2 -2
- package/dist/services/schema.js +1 -1
- package/dist/services/server.js +12 -4
- package/dist/services/settings.js +2 -2
- package/dist/services/tfa.js +1 -1
- package/dist/services/translations.js +1 -1
- package/dist/services/tus/data-store.d.ts +1 -3
- package/dist/services/tus/data-store.js +2 -5
- package/dist/services/tus/server.js +6 -6
- package/dist/services/users.js +4 -4
- package/dist/services/versions.js +1 -1
- package/dist/telemetry/lib/send-report.d.ts +1 -1
- package/dist/telemetry/lib/send-report.js +1 -1
- package/dist/telemetry/lib/track.js +1 -1
- package/dist/test-utils/knex.js +1 -1
- package/dist/types/collection.d.ts +1 -1
- package/dist/utils/async-handler.d.ts +1 -1
- package/dist/utils/calculate-field-depth.js +1 -1
- package/dist/utils/compress.js +1 -1
- package/dist/utils/deep-map-response.js +2 -2
- package/dist/utils/get-cache-key.js +1 -1
- package/dist/utils/get-field-system-rows.js +1 -1
- package/dist/utils/get-ip-from-req.d.ts +1 -1
- package/dist/utils/get-ip-from-req.js +1 -1
- package/dist/utils/get-local-type.js +7 -3
- package/dist/utils/get-service.js +1 -3
- package/dist/utils/get-snapshot-diff.js +1 -1
- package/dist/utils/is-url-allowed.js +1 -1
- package/dist/utils/jwt.js +1 -1
- package/dist/utils/sanitize-schema.d.ts +1 -1
- package/dist/utils/should-clear-cache.d.ts +1 -1
- package/dist/utils/should-skip-cache.js +2 -2
- package/dist/utils/validate-diff.js +1 -1
- package/dist/utils/validate-snapshot.js +3 -3
- package/dist/utils/validate-storage.js +2 -2
- package/dist/utils/verify-session-jwt.js +1 -1
- package/dist/utils/versioning/deep-map-with-schema.js +2 -2
- package/dist/websocket/controllers/base.d.ts +2 -2
- package/dist/websocket/controllers/base.js +3 -3
- package/dist/websocket/controllers/graphql.d.ts +1 -1
- package/dist/websocket/controllers/graphql.js +1 -1
- package/dist/websocket/controllers/logs.d.ts +1 -1
- package/dist/websocket/controllers/rest.d.ts +1 -1
- package/dist/websocket/controllers/rest.js +2 -2
- package/dist/websocket/handlers/heartbeat.js +1 -1
- package/dist/websocket/handlers/items.js +2 -2
- package/dist/websocket/handlers/subscribe.js +1 -1
- package/dist/websocket/types.d.ts +1 -1
- package/dist/websocket/utils/wait-for-message.js +1 -1
- package/package.json +24 -24
- package/dist/controllers/webhooks.d.ts +0 -2
- package/dist/controllers/webhooks.js +0 -74
- package/dist/services/webhooks.d.ts +0 -14
- package/dist/services/webhooks.js +0 -32
- package/dist/utils/is-login-redirect-allowed.d.ts +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LanguageModelUsage, type
|
|
1
|
+
import { type LanguageModelUsage, type StreamTextResult, type Tool, type UIMessage } from 'ai';
|
|
2
2
|
export interface CreateUiStreamOptions {
|
|
3
3
|
provider: 'openai' | 'anthropic';
|
|
4
4
|
model: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UnsupportedMediaTypeError } from '@directus/errors';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { UnsupportedMediaTypeError } from '@directus/errors';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { AssetsService } from '../../../services/assets.js';
|
|
6
6
|
import { FilesService } from '../../../services/files.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InvalidPayloadError } from '@directus/errors';
|
|
2
|
-
import { isObject, toArray } from '@directus/utils';
|
|
3
1
|
import { dirname, resolve } from 'node:path';
|
|
4
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
4
|
+
import { isObject, toArray } from '@directus/utils';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { CollectionsService } from '../../../services/collections.js';
|
|
7
7
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InvalidPayloadError } from '@directus/errors';
|
|
2
|
-
import { toArray } from '@directus/utils';
|
|
3
1
|
import { dirname, resolve } from 'node:path';
|
|
4
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
4
|
+
import { toArray } from '@directus/utils';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { clearSystemCache } from '../../../cache.js';
|
|
7
7
|
import getDatabase from '../../../database/index.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isObject } from '@directus/utils';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { isObject } from '@directus/utils';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { FilesService } from '../../../services/files.js';
|
|
6
6
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isObject } from '@directus/utils';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { isObject } from '@directus/utils';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { FlowsService } from '../../../services/flows.js';
|
|
6
6
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { toArray } from '@directus/utils';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { toArray } from '@directus/utils';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { FoldersService } from '../../../services/folders.js';
|
|
6
6
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
1
3
|
import { ForbiddenError, InvalidPayloadError } from '@directus/errors';
|
|
2
4
|
import { isSystemCollection } from '@directus/system-data';
|
|
3
5
|
import { toArray } from '@directus/utils';
|
|
4
6
|
import { isObject } from 'graphql-compose';
|
|
5
|
-
import { dirname, resolve } from 'node:path';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import { ItemsService } from '../../../services/items.js';
|
|
9
9
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvalidPayloadError } from '@directus/errors';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { RelationsService } from '../../../services/relations.js';
|
|
6
6
|
import { requireText } from '../../../utils/require-text.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvalidPayloadError } from '@directus/errors';
|
|
2
1
|
import { dirname, resolve } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { getFlowManager } from '../../../flows.js';
|
|
6
6
|
import { FlowsService } from '../../../services/flows.js';
|
package/dist/app.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'path';
|
|
1
4
|
import { useEnv } from '@directus/env';
|
|
2
5
|
import { InvalidPayloadError, ServiceUnavailableError } from '@directus/errors';
|
|
3
6
|
import { handlePressure } from '@directus/pressure';
|
|
@@ -5,10 +8,8 @@ import { toBoolean } from '@directus/utils';
|
|
|
5
8
|
import cookieParser from 'cookie-parser';
|
|
6
9
|
import express from 'express';
|
|
7
10
|
import { merge } from 'lodash-es';
|
|
8
|
-
import { readFile } from 'node:fs/promises';
|
|
9
|
-
import { createRequire } from 'node:module';
|
|
10
|
-
import path from 'path';
|
|
11
11
|
import qs from 'qs';
|
|
12
|
+
import { aiChatRouter } from './ai/chat/router.js';
|
|
12
13
|
import { registerAuthProviders } from './auth.js';
|
|
13
14
|
import accessRouter from './controllers/access.js';
|
|
14
15
|
import activityRouter from './controllers/activity.js';
|
|
@@ -45,7 +46,6 @@ import tusRouter from './controllers/tus.js';
|
|
|
45
46
|
import usersRouter from './controllers/users.js';
|
|
46
47
|
import utilsRouter from './controllers/utils.js';
|
|
47
48
|
import versionsRouter from './controllers/versions.js';
|
|
48
|
-
import webhooksRouter from './controllers/webhooks.js';
|
|
49
49
|
import { isInstalled, validateDatabaseConnection, validateDatabaseExtensions, validateMigrations, } from './database/index.js';
|
|
50
50
|
import emitter from './emitter.js';
|
|
51
51
|
import { getExtensionManager } from './extensions/index.js';
|
|
@@ -61,14 +61,13 @@ import rateLimiter from './middleware/rate-limiter-ip.js';
|
|
|
61
61
|
import sanitizeQuery from './middleware/sanitize-query.js';
|
|
62
62
|
import schema from './middleware/schema.js';
|
|
63
63
|
import metricsSchedule from './schedules/metrics.js';
|
|
64
|
+
import projectSchedule from './schedules/project.js';
|
|
64
65
|
import retentionSchedule from './schedules/retention.js';
|
|
65
66
|
import telemetrySchedule from './schedules/telemetry.js';
|
|
66
67
|
import tusSchedule from './schedules/tus.js';
|
|
67
|
-
import projectSchedule from './schedules/project.js';
|
|
68
68
|
import { getConfigFromEnv } from './utils/get-config-from-env.js';
|
|
69
69
|
import { Url } from './utils/url.js';
|
|
70
70
|
import { validateStorage } from './utils/validate-storage.js';
|
|
71
|
-
import { aiChatRouter } from './ai/chat/router.js';
|
|
72
71
|
const require = createRequire(import.meta.url);
|
|
73
72
|
export default async function createApp() {
|
|
74
73
|
const env = useEnv();
|
|
@@ -235,7 +234,9 @@ export default async function createApp() {
|
|
|
235
234
|
if (toBoolean(env['MCP_ENABLED']) === true) {
|
|
236
235
|
app.use('/mcp', mcpRouter);
|
|
237
236
|
}
|
|
238
|
-
|
|
237
|
+
if (toBoolean(env['AI_ENABLED']) === true) {
|
|
238
|
+
app.use('/ai/chat', aiChatRouter);
|
|
239
|
+
}
|
|
239
240
|
if (env['METRICS_ENABLED'] === true) {
|
|
240
241
|
app.use('/metrics', metricsRouter);
|
|
241
242
|
}
|
|
@@ -256,7 +257,6 @@ export default async function createApp() {
|
|
|
256
257
|
app.use('/users', usersRouter);
|
|
257
258
|
app.use('/utils', utilsRouter);
|
|
258
259
|
app.use('/versions', versionsRouter);
|
|
259
|
-
app.use('/webhooks', webhooksRouter);
|
|
260
260
|
// Register custom endpoints
|
|
261
261
|
await emitter.emitInit('routes.custom.before', { app });
|
|
262
262
|
app.use(extensionManager.getEndpointRouter());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEnv } from '@directus/env';
|
|
2
|
-
import { ErrorCode, InvalidCredentialsError, InvalidPayloadError, InvalidProviderConfigError, InvalidProviderError, ServiceUnavailableError, UnexpectedResponseError,
|
|
2
|
+
import { ErrorCode, InvalidCredentialsError, InvalidPayloadError, InvalidProviderConfigError, InvalidProviderError, isDirectusError, ServiceUnavailableError, UnexpectedResponseError, } from '@directus/errors';
|
|
3
3
|
import { Router } from 'express';
|
|
4
4
|
import Joi from 'joi';
|
|
5
5
|
import ldap from 'ldapjs';
|
|
@@ -12,8 +12,8 @@ import { createDefaultAccountability } from '../../permissions/utils/create-defa
|
|
|
12
12
|
import { AuthenticationService } from '../../services/authentication.js';
|
|
13
13
|
import asyncHandler from '../../utils/async-handler.js';
|
|
14
14
|
import { getIPFromReq } from '../../utils/get-ip-from-req.js';
|
|
15
|
-
import { AuthDriver } from '../auth.js';
|
|
16
15
|
import { getSchema } from '../../utils/get-schema.js';
|
|
16
|
+
import { AuthDriver } from '../auth.js';
|
|
17
17
|
// 0x2: ACCOUNTDISABLE
|
|
18
18
|
// 0x10: LOCKOUT
|
|
19
19
|
// 0x800000: PASSWORD_EXPIRED
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { performance } from 'perf_hooks';
|
|
1
2
|
import { useEnv } from '@directus/env';
|
|
2
3
|
import { InvalidCredentialsError, InvalidPayloadError } from '@directus/errors';
|
|
3
4
|
import argon2 from 'argon2';
|
|
4
5
|
import { Router } from 'express';
|
|
5
6
|
import Joi from 'joi';
|
|
6
|
-
import { performance } from 'perf_hooks';
|
|
7
7
|
import { REFRESH_COOKIE_OPTIONS, SESSION_COOKIE_OPTIONS } from '../../constants.js';
|
|
8
8
|
import { respond } from '../../middleware/respond.js';
|
|
9
9
|
import { createDefaultAccountability } from '../../permissions/utils/create-default-accountability.js';
|
|
@@ -5,12 +5,11 @@ import type { RoleMap } from '../../types/rolemap.js';
|
|
|
5
5
|
import { LocalAuthDriver } from './local.js';
|
|
6
6
|
export declare class OAuth2AuthDriver extends LocalAuthDriver {
|
|
7
7
|
client: Client;
|
|
8
|
-
redirectUrl: string;
|
|
9
8
|
config: Record<string, any>;
|
|
10
9
|
roleMap: RoleMap;
|
|
11
10
|
constructor(options: AuthDriverOptions, config: Record<string, any>);
|
|
12
11
|
generateCodeVerifier(): string;
|
|
13
|
-
generateAuthUrl(codeVerifier: string, prompt?: boolean): string;
|
|
12
|
+
generateAuthUrl(codeVerifier: string, prompt?: boolean, callbackUrl?: string): string;
|
|
14
13
|
private fetchUserId;
|
|
15
14
|
getUserID(payload: Record<string, any>): Promise<string>;
|
|
16
15
|
login(user: User): Promise<void>;
|
|
@@ -16,40 +16,37 @@ import { AuthenticationService } from '../../services/authentication.js';
|
|
|
16
16
|
import asyncHandler from '../../utils/async-handler.js';
|
|
17
17
|
import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
|
|
18
18
|
import { getIPFromReq } from '../../utils/get-ip-from-req.js';
|
|
19
|
+
import { getSchema } from '../../utils/get-schema.js';
|
|
19
20
|
import { getSecret } from '../../utils/get-secret.js';
|
|
20
|
-
import { isLoginRedirectAllowed } from '../../utils/is-login-redirect-allowed.js';
|
|
21
21
|
import { verifyJWT } from '../../utils/jwt.js';
|
|
22
22
|
import { Url } from '../../utils/url.js';
|
|
23
|
+
import { generateCallbackUrl } from '../utils/generate-callback-url.js';
|
|
24
|
+
import { isLoginRedirectAllowed } from '../utils/is-login-redirect-allowed.js';
|
|
23
25
|
import { LocalAuthDriver } from './local.js';
|
|
24
|
-
import { getSchema } from '../../utils/get-schema.js';
|
|
25
26
|
export class OAuth2AuthDriver extends LocalAuthDriver {
|
|
26
27
|
client;
|
|
27
|
-
redirectUrl;
|
|
28
28
|
config;
|
|
29
29
|
roleMap;
|
|
30
30
|
constructor(options, config) {
|
|
31
31
|
super(options, config);
|
|
32
|
-
const env = useEnv();
|
|
33
32
|
const logger = useLogger();
|
|
34
33
|
const { authorizeUrl, accessUrl, profileUrl, clientId, clientSecret, ...additionalConfig } = config;
|
|
35
34
|
if (!authorizeUrl || !accessUrl || !profileUrl || !clientId || !clientSecret || !additionalConfig['provider']) {
|
|
36
35
|
logger.error('Invalid provider config');
|
|
37
36
|
throw new InvalidProviderConfigError({ provider: additionalConfig['provider'] });
|
|
38
37
|
}
|
|
39
|
-
const redirectUrl = new Url(env['PUBLIC_URL']).addPath('auth', 'login', additionalConfig['provider'], 'callback');
|
|
40
|
-
this.redirectUrl = redirectUrl.toString();
|
|
41
38
|
this.config = additionalConfig;
|
|
42
39
|
this.roleMap = {};
|
|
43
40
|
const roleMapping = this.config['roleMapping'];
|
|
44
|
-
if (roleMapping) {
|
|
45
|
-
this.roleMap = roleMapping;
|
|
46
|
-
}
|
|
47
41
|
// role mapping will fail on login if AUTH_<provider>_ROLE_MAPPING is an array instead of an object.
|
|
48
42
|
// This happens if the 'json:' prefix is missing from the variable declaration. To save the user from exhaustive debugging, we'll try to fail early here.
|
|
49
43
|
if (roleMapping instanceof Array) {
|
|
50
44
|
logger.error("[OAuth2] Expected a JSON-Object as role mapping, got an Array instead. Make sure you declare the variable with 'json:' prefix.");
|
|
51
45
|
throw new InvalidProviderError();
|
|
52
46
|
}
|
|
47
|
+
if (roleMapping) {
|
|
48
|
+
this.roleMap = roleMapping;
|
|
49
|
+
}
|
|
53
50
|
const issuer = new Issuer({
|
|
54
51
|
authorization_endpoint: authorizeUrl,
|
|
55
52
|
token_endpoint: accessUrl,
|
|
@@ -67,7 +64,6 @@ export class OAuth2AuthDriver extends LocalAuthDriver {
|
|
|
67
64
|
this.client = new issuer.Client({
|
|
68
65
|
client_id: clientId,
|
|
69
66
|
client_secret: clientSecret,
|
|
70
|
-
redirect_uris: [this.redirectUrl],
|
|
71
67
|
response_types: ['code'],
|
|
72
68
|
...clientOptionsOverrides,
|
|
73
69
|
});
|
|
@@ -75,7 +71,7 @@ export class OAuth2AuthDriver extends LocalAuthDriver {
|
|
|
75
71
|
generateCodeVerifier() {
|
|
76
72
|
return generators.codeVerifier();
|
|
77
73
|
}
|
|
78
|
-
generateAuthUrl(codeVerifier, prompt = false) {
|
|
74
|
+
generateAuthUrl(codeVerifier, prompt = false, callbackUrl) {
|
|
79
75
|
const { plainCodeChallenge } = this.config;
|
|
80
76
|
try {
|
|
81
77
|
const codeChallenge = plainCodeChallenge ? codeVerifier : generators.codeChallenge(codeVerifier);
|
|
@@ -89,6 +85,7 @@ export class OAuth2AuthDriver extends LocalAuthDriver {
|
|
|
89
85
|
code_challenge_method: plainCodeChallenge ? 'plain' : 'S256',
|
|
90
86
|
// Some providers require state even with PKCE
|
|
91
87
|
state: codeChallenge,
|
|
88
|
+
redirect_uri: callbackUrl,
|
|
92
89
|
});
|
|
93
90
|
}
|
|
94
91
|
catch (e) {
|
|
@@ -116,7 +113,7 @@ export class OAuth2AuthDriver extends LocalAuthDriver {
|
|
|
116
113
|
const codeChallenge = plainCodeChallenge
|
|
117
114
|
? payload['codeVerifier']
|
|
118
115
|
: generators.codeChallenge(payload['codeVerifier']);
|
|
119
|
-
tokenSet = await this.client.oauthCallback(
|
|
116
|
+
tokenSet = await this.client.oauthCallback(payload['callbackUrl'], { code: payload['code'], state: payload['state'] }, { code_verifier: payload['codeVerifier'], state: codeChallenge });
|
|
120
117
|
userInfo = await this.client.userinfo(tokenSet.access_token);
|
|
121
118
|
}
|
|
122
119
|
catch (e) {
|
|
@@ -275,12 +272,19 @@ export function createOAuth2AuthRouter(providerName) {
|
|
|
275
272
|
const provider = getAuthProvider(providerName);
|
|
276
273
|
const codeVerifier = provider.generateCodeVerifier();
|
|
277
274
|
const prompt = !!req.query['prompt'];
|
|
278
|
-
const redirect = req.query['redirect'];
|
|
279
275
|
const otp = req.query['otp'];
|
|
280
|
-
|
|
276
|
+
const redirect = req.query['redirect'];
|
|
277
|
+
if (!isLoginRedirectAllowed(providerName, redirect)) {
|
|
281
278
|
throw new InvalidPayloadError({ reason: `URL "${redirect}" can't be used to redirect after login` });
|
|
282
279
|
}
|
|
283
|
-
const
|
|
280
|
+
const callbackUrl = generateCallbackUrl(providerName, `${req.protocol}://${req.get('host')}`);
|
|
281
|
+
const token = jwt.sign({
|
|
282
|
+
verifier: codeVerifier,
|
|
283
|
+
redirect,
|
|
284
|
+
prompt,
|
|
285
|
+
otp,
|
|
286
|
+
callbackUrl,
|
|
287
|
+
}, getSecret(), {
|
|
284
288
|
expiresIn: '5m',
|
|
285
289
|
issuer: 'directus',
|
|
286
290
|
});
|
|
@@ -288,7 +292,7 @@ export function createOAuth2AuthRouter(providerName) {
|
|
|
288
292
|
httpOnly: true,
|
|
289
293
|
sameSite: 'lax',
|
|
290
294
|
});
|
|
291
|
-
return res.redirect(provider.generateAuthUrl(codeVerifier, prompt));
|
|
295
|
+
return res.redirect(provider.generateAuthUrl(codeVerifier, prompt, callbackUrl));
|
|
292
296
|
}, respond);
|
|
293
297
|
router.post('/callback', express.urlencoded({ extended: false }), (req, res) => {
|
|
294
298
|
res.redirect(303, `./callback?${new URLSearchParams(req.body)}`);
|
|
@@ -303,7 +307,7 @@ export function createOAuth2AuthRouter(providerName) {
|
|
|
303
307
|
logger.warn(e, `[OAuth2] Couldn't verify OAuth2 cookie`);
|
|
304
308
|
throw new InvalidCredentialsError();
|
|
305
309
|
}
|
|
306
|
-
const { verifier, prompt, otp } = tokenData;
|
|
310
|
+
const { verifier, prompt, otp, callbackUrl } = tokenData;
|
|
307
311
|
let { redirect } = tokenData;
|
|
308
312
|
const accountability = createDefaultAccountability({
|
|
309
313
|
ip: getIPFromReq(req),
|
|
@@ -326,6 +330,7 @@ export function createOAuth2AuthRouter(providerName) {
|
|
|
326
330
|
code: req.query['code'],
|
|
327
331
|
codeVerifier: verifier,
|
|
328
332
|
state: req.query['state'],
|
|
333
|
+
callbackUrl,
|
|
329
334
|
}, { session: authMode === 'session', ...(otp ? { otp: String(otp) } : {}) });
|
|
330
335
|
}
|
|
331
336
|
catch (error) {
|
|
@@ -5,13 +5,12 @@ import type { RoleMap } from '../../types/rolemap.js';
|
|
|
5
5
|
import { LocalAuthDriver } from './local.js';
|
|
6
6
|
export declare class OpenIDAuthDriver extends LocalAuthDriver {
|
|
7
7
|
client: null | Client;
|
|
8
|
-
redirectUrl: string;
|
|
9
8
|
config: Record<string, any>;
|
|
10
9
|
roleMap: RoleMap;
|
|
11
10
|
constructor(options: AuthDriverOptions, config: Record<string, any>);
|
|
12
11
|
private getClient;
|
|
13
12
|
generateCodeVerifier(): string;
|
|
14
|
-
generateAuthUrl(codeVerifier: string, prompt?: boolean): Promise<string>;
|
|
13
|
+
generateAuthUrl(codeVerifier: string, prompt?: boolean, callbackUrl?: string): Promise<string>;
|
|
15
14
|
private fetchUserId;
|
|
16
15
|
getUserID(payload: Record<string, any>): Promise<string>;
|
|
17
16
|
login(user: User): Promise<void>;
|
|
@@ -16,20 +16,19 @@ import { AuthenticationService } from '../../services/authentication.js';
|
|
|
16
16
|
import asyncHandler from '../../utils/async-handler.js';
|
|
17
17
|
import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
|
|
18
18
|
import { getIPFromReq } from '../../utils/get-ip-from-req.js';
|
|
19
|
+
import { getSchema } from '../../utils/get-schema.js';
|
|
19
20
|
import { getSecret } from '../../utils/get-secret.js';
|
|
20
|
-
import { isLoginRedirectAllowed } from '../../utils/is-login-redirect-allowed.js';
|
|
21
21
|
import { verifyJWT } from '../../utils/jwt.js';
|
|
22
22
|
import { Url } from '../../utils/url.js';
|
|
23
|
+
import { generateCallbackUrl } from '../utils/generate-callback-url.js';
|
|
24
|
+
import { isLoginRedirectAllowed } from '../utils/is-login-redirect-allowed.js';
|
|
23
25
|
import { LocalAuthDriver } from './local.js';
|
|
24
|
-
import { getSchema } from '../../utils/get-schema.js';
|
|
25
26
|
export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
26
27
|
client;
|
|
27
|
-
redirectUrl;
|
|
28
28
|
config;
|
|
29
29
|
roleMap;
|
|
30
30
|
constructor(options, config) {
|
|
31
31
|
super(options, config);
|
|
32
|
-
const env = useEnv();
|
|
33
32
|
const logger = useLogger();
|
|
34
33
|
const { issuerUrl, clientId, clientSecret, clientPrivateKeys, clientTokenEndpointAuthMethod, provider, issuerDiscoveryMustSucceed, } = config;
|
|
35
34
|
const isPrivateKeyJwtAuthMethod = clientTokenEndpointAuthMethod === 'private_key_jwt';
|
|
@@ -37,8 +36,6 @@ export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
37
36
|
logger.error('Invalid provider config');
|
|
38
37
|
throw new InvalidProviderConfigError({ provider });
|
|
39
38
|
}
|
|
40
|
-
const redirectUrl = new Url(env['PUBLIC_URL']).addPath('auth', 'login', provider, 'callback');
|
|
41
|
-
this.redirectUrl = redirectUrl.toString();
|
|
42
39
|
this.config = config;
|
|
43
40
|
this.roleMap = {};
|
|
44
41
|
const roleMapping = this.config['roleMapping'];
|
|
@@ -98,7 +95,6 @@ export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
98
95
|
const client = new issuer.Client({
|
|
99
96
|
client_id: clientId,
|
|
100
97
|
...(!isPrivateKeyJwtAuthMethod && { client_secret: clientSecret }),
|
|
101
|
-
redirect_uris: [this.redirectUrl],
|
|
102
98
|
response_types: ['code'],
|
|
103
99
|
...clientOptionsOverrides,
|
|
104
100
|
}, isPrivateKeyJwtAuthMethod ? { keys: clientPrivateKeys } : undefined);
|
|
@@ -116,7 +112,7 @@ export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
116
112
|
generateCodeVerifier() {
|
|
117
113
|
return generators.codeVerifier();
|
|
118
114
|
}
|
|
119
|
-
async generateAuthUrl(codeVerifier, prompt = false) {
|
|
115
|
+
async generateAuthUrl(codeVerifier, prompt = false, callbackUrl) {
|
|
120
116
|
const { plainCodeChallenge } = this.config;
|
|
121
117
|
try {
|
|
122
118
|
const client = await this.getClient();
|
|
@@ -132,6 +128,7 @@ export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
132
128
|
// Some providers require state even with PKCE
|
|
133
129
|
state: codeChallenge,
|
|
134
130
|
nonce: codeChallenge,
|
|
131
|
+
redirect_uri: callbackUrl,
|
|
135
132
|
});
|
|
136
133
|
}
|
|
137
134
|
catch (e) {
|
|
@@ -160,7 +157,7 @@ export class OpenIDAuthDriver extends LocalAuthDriver {
|
|
|
160
157
|
const codeChallenge = plainCodeChallenge
|
|
161
158
|
? payload['codeVerifier']
|
|
162
159
|
: generators.codeChallenge(payload['codeVerifier']);
|
|
163
|
-
tokenSet = await client.callback(
|
|
160
|
+
tokenSet = await client.callback(payload['callbackUrl'], { code: payload['code'], state: payload['state'], iss: payload['iss'] }, { code_verifier: payload['codeVerifier'], state: codeChallenge, nonce: codeChallenge });
|
|
164
161
|
userInfo = tokenSet.claims();
|
|
165
162
|
if (client.issuer.metadata['userinfo_endpoint']) {
|
|
166
163
|
userInfo = {
|
|
@@ -329,10 +326,17 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
329
326
|
const prompt = !!req.query['prompt'];
|
|
330
327
|
const redirect = req.query['redirect'];
|
|
331
328
|
const otp = req.query['otp'];
|
|
332
|
-
if (isLoginRedirectAllowed(
|
|
329
|
+
if (!isLoginRedirectAllowed(providerName, redirect)) {
|
|
333
330
|
throw new InvalidPayloadError({ reason: `URL "${redirect}" can't be used to redirect after login` });
|
|
334
331
|
}
|
|
335
|
-
const
|
|
332
|
+
const callbackUrl = generateCallbackUrl(providerName, `${req.protocol}://${req.get('host')}`);
|
|
333
|
+
const token = jwt.sign({
|
|
334
|
+
verifier: codeVerifier,
|
|
335
|
+
redirect,
|
|
336
|
+
prompt,
|
|
337
|
+
otp,
|
|
338
|
+
callbackUrl,
|
|
339
|
+
}, getSecret(), {
|
|
336
340
|
expiresIn: (env[`AUTH_${providerName.toUpperCase()}_LOGIN_TIMEOUT`] ?? '5m'),
|
|
337
341
|
issuer: 'directus',
|
|
338
342
|
});
|
|
@@ -341,7 +345,7 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
341
345
|
sameSite: 'lax',
|
|
342
346
|
});
|
|
343
347
|
try {
|
|
344
|
-
return res.redirect(await provider.generateAuthUrl(codeVerifier, prompt));
|
|
348
|
+
return res.redirect(await provider.generateAuthUrl(codeVerifier, prompt, callbackUrl));
|
|
345
349
|
}
|
|
346
350
|
catch {
|
|
347
351
|
return res.redirect(new Url(env['PUBLIC_URL'])
|
|
@@ -365,7 +369,7 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
365
369
|
const url = new Url(env['PUBLIC_URL']).addPath('admin', 'login');
|
|
366
370
|
return res.redirect(`${url.toString()}?reason=${ErrorCode.InvalidCredentials}`);
|
|
367
371
|
}
|
|
368
|
-
const { verifier, prompt, otp } = tokenData;
|
|
372
|
+
const { verifier, prompt, otp, callbackUrl } = tokenData;
|
|
369
373
|
let { redirect } = tokenData;
|
|
370
374
|
const accountability = createDefaultAccountability({ ip: getIPFromReq(req) });
|
|
371
375
|
const userAgent = req.get('user-agent')?.substring(0, 1024);
|
|
@@ -387,6 +391,7 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
387
391
|
codeVerifier: verifier,
|
|
388
392
|
state: req.query['state'],
|
|
389
393
|
iss: req.query['iss'],
|
|
394
|
+
callbackUrl,
|
|
390
395
|
}, { session: authMode === 'session', ...(otp ? { otp: String(otp) } : {}) });
|
|
391
396
|
}
|
|
392
397
|
catch (error) {
|
|
@@ -13,7 +13,7 @@ import { AuthenticationService } from '../../services/authentication.js';
|
|
|
13
13
|
import asyncHandler from '../../utils/async-handler.js';
|
|
14
14
|
import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
|
|
15
15
|
import { getSchema } from '../../utils/get-schema.js';
|
|
16
|
-
import { isLoginRedirectAllowed } from '
|
|
16
|
+
import { isLoginRedirectAllowed } from '../utils/is-login-redirect-allowed.js';
|
|
17
17
|
import { LocalAuthDriver } from './local.js';
|
|
18
18
|
// Register the samlify schema validator
|
|
19
19
|
samlify.setSchemaValidator(validator);
|
|
@@ -95,7 +95,7 @@ export function createSAMLAuthRouter(providerName) {
|
|
|
95
95
|
const parsedUrl = new URL(url);
|
|
96
96
|
if (req.query['redirect']) {
|
|
97
97
|
const redirect = req.query['redirect'];
|
|
98
|
-
if (isLoginRedirectAllowed(
|
|
98
|
+
if (!isLoginRedirectAllowed(providerName, redirect)) {
|
|
99
99
|
throw new InvalidPayloadError({ reason: `URL "${redirect}" can't be used to redirect after login` });
|
|
100
100
|
}
|
|
101
101
|
parsedUrl.searchParams.append('RelayState', redirect);
|
|
@@ -117,7 +117,7 @@ export function createSAMLAuthRouter(providerName) {
|
|
|
117
117
|
const logger = useLogger();
|
|
118
118
|
const relayState = req.body?.RelayState;
|
|
119
119
|
const authMode = (env[`AUTH_${providerName.toUpperCase()}_MODE`] ?? 'session');
|
|
120
|
-
if (relayState && isLoginRedirectAllowed(
|
|
120
|
+
if (relayState && isLoginRedirectAllowed(providerName, relayState) === false) {
|
|
121
121
|
throw new InvalidPayloadError({ reason: `URL "${relayState}" can't be used to redirect after login` });
|
|
122
122
|
}
|
|
123
123
|
try {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamically generate the callback URL for OAuth2/OpenID SSO providers
|
|
3
|
+
*
|
|
4
|
+
* Uses AUTH_ALLOWED_PUBLIC_URLS to find an alternate PUBLIC_URL based on the origins protocol and host.
|
|
5
|
+
* Defaults to the PUBLIC_URL if no match is found.
|
|
6
|
+
*
|
|
7
|
+
* @param providerName SSO provider name
|
|
8
|
+
* @param requestOrigin Origin of the request (protocol + host)
|
|
9
|
+
* @returns Callback URL
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateCallbackUrl(providerName: string, requestOrigin: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEnv } from '@directus/env';
|
|
2
|
+
import { toArray } from '@directus/utils';
|
|
3
|
+
import { Url } from '../../utils/url.js';
|
|
4
|
+
/**
|
|
5
|
+
* Find a matching public URL based on the request origins protocol and host
|
|
6
|
+
*
|
|
7
|
+
* @param requestOrigin - The origin of the request
|
|
8
|
+
* @param allowedPublicUrls - The allowed public URLs from AUTH_ALLOWED_PUBLIC_URLS
|
|
9
|
+
* @returns The matching public URL
|
|
10
|
+
*/
|
|
11
|
+
function findMatchingPublicUrl(requestOrigin, allowedPublicUrls) {
|
|
12
|
+
for (const allowedUrl of allowedPublicUrls) {
|
|
13
|
+
if (!URL.canParse(allowedUrl))
|
|
14
|
+
continue;
|
|
15
|
+
const { protocol, host } = new URL(allowedUrl);
|
|
16
|
+
const allowedUrlOrigin = `${protocol}//${host}`;
|
|
17
|
+
if (requestOrigin === allowedUrlOrigin) {
|
|
18
|
+
return allowedUrl;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Dynamically generate the callback URL for OAuth2/OpenID SSO providers
|
|
25
|
+
*
|
|
26
|
+
* Uses AUTH_ALLOWED_PUBLIC_URLS to find an alternate PUBLIC_URL based on the origins protocol and host.
|
|
27
|
+
* Defaults to the PUBLIC_URL if no match is found.
|
|
28
|
+
*
|
|
29
|
+
* @param providerName SSO provider name
|
|
30
|
+
* @param requestOrigin Origin of the request (protocol + host)
|
|
31
|
+
* @returns Callback URL
|
|
32
|
+
*/
|
|
33
|
+
export function generateCallbackUrl(providerName, requestOrigin) {
|
|
34
|
+
const env = useEnv();
|
|
35
|
+
const publicUrl = env['PUBLIC_URL'];
|
|
36
|
+
const allowedPublicUrls = env['AUTH_ALLOWED_PUBLIC_URLS'] ? toArray(env['AUTH_ALLOWED_PUBLIC_URLS']) : [];
|
|
37
|
+
const matchedUrl = findMatchingPublicUrl(requestOrigin, allowedPublicUrls);
|
|
38
|
+
// Use matched public URL or fallback to PUBLIC_URL for backward compatibility
|
|
39
|
+
return new Url(matchedUrl || publicUrl).addPath('auth', 'login', providerName, 'callback').toString();
|
|
40
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the defined redirect after successful SSO login is in the allow list
|
|
3
|
+
* @param provider SSO provider name
|
|
4
|
+
* @param redirect URL to redirect to after login
|
|
5
|
+
* @returns True if the redirect is allowed, false otherwise
|
|
6
|
+
*/
|
|
7
|
+
export declare function isLoginRedirectAllowed(provider: string, redirect: unknown): boolean;
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { useEnv } from '@directus/env';
|
|
2
2
|
import { toArray } from '@directus/utils';
|
|
3
|
-
import { useLogger } from '
|
|
4
|
-
import isUrlAllowed from '
|
|
3
|
+
import { useLogger } from '../../logger/index.js';
|
|
4
|
+
import isUrlAllowed from '../../utils/is-url-allowed.js';
|
|
5
5
|
/**
|
|
6
6
|
* Checks if the defined redirect after successful SSO login is in the allow list
|
|
7
|
+
* @param provider SSO provider name
|
|
8
|
+
* @param redirect URL to redirect to after login
|
|
9
|
+
* @returns True if the redirect is allowed, false otherwise
|
|
7
10
|
*/
|
|
8
|
-
export function isLoginRedirectAllowed(
|
|
11
|
+
export function isLoginRedirectAllowed(provider, redirect) {
|
|
9
12
|
if (!redirect)
|
|
10
13
|
return true; // empty redirect
|
|
11
14
|
if (typeof redirect !== 'string')
|
|
12
15
|
return false; // invalid type
|
|
13
16
|
const env = useEnv();
|
|
14
17
|
const publicUrl = env['PUBLIC_URL'];
|
|
15
|
-
if (URL.canParse(redirect)
|
|
16
|
-
if (redirect.startsWith('//')
|
|
18
|
+
if (!URL.canParse(redirect)) {
|
|
19
|
+
if (!redirect.startsWith('//')) {
|
|
17
20
|
// should be a relative path like `/admin/test`
|
|
18
21
|
return true;
|
|
19
22
|
}
|
|
20
23
|
// domain without protocol `//example.com/test`
|
|
21
24
|
return false;
|
|
22
25
|
}
|
|
23
|
-
const { protocol: redirectProtocol, hostname: redirectDomain } = new URL(redirect);
|
|
24
26
|
const envKey = `AUTH_${provider.toUpperCase()}_REDIRECT_ALLOW_LIST`;
|
|
25
27
|
if (envKey in env) {
|
|
26
28
|
if (isUrlAllowed(redirect, [...toArray(env[envKey]), publicUrl]))
|
|
@@ -30,7 +32,8 @@ export function isLoginRedirectAllowed(redirect, provider) {
|
|
|
30
32
|
useLogger().error('Invalid PUBLIC_URL for login redirect');
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
const { protocol: publicProtocol,
|
|
35
|
-
|
|
35
|
+
const { protocol: redirectProtocol, host: redirectHost } = new URL(redirect);
|
|
36
|
+
const { protocol: publicProtocol, host: publicHost } = new URL(publicUrl);
|
|
37
|
+
// allow redirects to the defined PUBLIC_URL (protocol + host including port)
|
|
38
|
+
return `${redirectProtocol}//${redirectHost}` === `${publicProtocol}//${publicHost}`;
|
|
36
39
|
}
|
package/dist/cache.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { useEnv } from '@directus/env';
|
|
2
3
|
import Keyv, {} from 'keyv';
|
|
3
4
|
import { useBus } from './bus/index.js';
|
|
@@ -5,11 +6,10 @@ import { useLogger } from './logger/index.js';
|
|
|
5
6
|
import { clearCache as clearPermissionCache } from './permissions/cache.js';
|
|
6
7
|
import { redisConfigAvailable } from './redis/index.js';
|
|
7
8
|
import { compress, decompress } from './utils/compress.js';
|
|
9
|
+
import { freezeSchema, unfreezeSchema } from './utils/freeze-schema.js';
|
|
8
10
|
import { getConfigFromEnv } from './utils/get-config-from-env.js';
|
|
9
11
|
import { getMilliseconds } from './utils/get-milliseconds.js';
|
|
10
12
|
import { validateEnv } from './utils/validate-env.js';
|
|
11
|
-
import { createRequire } from 'node:module';
|
|
12
|
-
import { freezeSchema, unfreezeSchema } from './utils/freeze-schema.js';
|
|
13
13
|
const logger = useLogger();
|
|
14
14
|
const env = useEnv();
|
|
15
15
|
const require = createRequire(import.meta.url);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useEnv } from '@directus/env';
|
|
2
|
+
import { email } from 'zod';
|
|
2
3
|
import getDatabase, { hasDatabaseConnection, isInstalled, validateDatabaseConnection, } from '../../../database/index.js';
|
|
3
4
|
import runMigrations from '../../../database/migrations/run.js';
|
|
4
5
|
import installDatabase from '../../../database/seeds/run.js';
|
|
5
6
|
import { useLogger } from '../../../logger/index.js';
|
|
6
7
|
import { SettingsService } from '../../../services/settings.js';
|
|
7
|
-
import { getSchema } from '../../../utils/get-schema.js';
|
|
8
8
|
import { createAdmin } from '../../../utils/create-admin.js';
|
|
9
|
-
import {
|
|
9
|
+
import { getSchema } from '../../../utils/get-schema.js';
|
|
10
10
|
export default async function bootstrap({ skipAdminInit }) {
|
|
11
11
|
const logger = useLogger();
|
|
12
12
|
logger.info('Initializing bootstrap...');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import installSeeds from '../../../database/seeds/run.js';
|
|
2
1
|
import getDatabase from '../../../database/index.js';
|
|
2
|
+
import installSeeds from '../../../database/seeds/run.js';
|
|
3
3
|
import { useLogger } from '../../../logger/index.js';
|
|
4
4
|
export default async function start() {
|
|
5
5
|
const database = getDatabase();
|