mirror of
https://github.com/outline/outline.git
synced 2026-12-02 09:42:07 +03:00
feat: Add OAUTH_DISABLE_CIMD to turn off client ID metadata documents (#14410)
This commit is contained in:
1 parent
fdac2bf913
commit
e5b1ade40d
5 files changed
+50
-3
No files matched your search
@@ -834,6 +834,16 @@ export class Environment {
|
||||
environment.OAUTH_DISABLE_DCR ?? "false"
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether to disable OAuth Client ID Metadata Documents (CIMD). When set to
|
||||
* true, clients must use Dynamic Client Registration instead. Use this when
|
||||
* the server cannot fetch metadata documents from client hosts.
|
||||
*/
|
||||
@IsBoolean()
|
||||
public OAUTH_DISABLE_CIMD = this.toBoolean(
|
||||
environment.OAUTH_DISABLE_CIMD ?? "false"
|
||||
);
|
||||
|
||||
/**
|
||||
* Enable unsafe-inline in script-src CSP directive
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,8 @@ router.get("/.well-known/oauth-authorization-server", async (ctx) => {
|
||||
mcpEnabled && {
|
||||
registration_endpoint: `${origin}/oauth/register`,
|
||||
}),
|
||||
client_id_metadata_document_supported: mcpEnabled,
|
||||
client_id_metadata_document_supported:
|
||||
mcpEnabled && !env.OAUTH_DISABLE_CIMD,
|
||||
response_types_supported: OAuthHelper.responseTypes,
|
||||
response_modes_supported: ["query"],
|
||||
grant_types_supported: OAuthHelper.grantTypes,
|
||||
|
||||
@@ -613,6 +613,23 @@ describe("GET /.well-known/oauth-authorization-server", () => {
|
||||
expect(body.client_id_metadata_document_supported).toBe(false);
|
||||
});
|
||||
|
||||
it("should not advertise metadata documents when they are disabled", async () => {
|
||||
const team = await buildTeam({ subdomain: buildSubdomain() });
|
||||
env.OAUTH_DISABLE_CIMD = true;
|
||||
|
||||
try {
|
||||
const res = await server.get("/.well-known/oauth-authorization-server", {
|
||||
headers: { host: `${team.subdomain}.outline.dev` },
|
||||
});
|
||||
|
||||
const body = await res.json();
|
||||
expect(body.registration_endpoint).toContain("/oauth/register");
|
||||
expect(body.client_id_metadata_document_supported).toBe(false);
|
||||
} finally {
|
||||
env.OAUTH_DISABLE_CIMD = false;
|
||||
}
|
||||
});
|
||||
|
||||
it("should not serve OAuth metadata at /mcp suffix path", async () => {
|
||||
const res = await server.get("/.well-known/oauth-authorization-server/mcp");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { Minute, Day } from "@shared/utils/time";
|
||||
import { TeamPreference } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import type { Team } from "@server/models";
|
||||
import { OAuthClient } from "@server/models";
|
||||
import UploadOAuthClientLogoTask from "@server/queues/tasks/UploadOAuthClientLogoTask";
|
||||
@@ -326,6 +327,21 @@ describe("ClientMetadataHelper", () => {
|
||||
expect(mock.requests()).toEqual(0);
|
||||
});
|
||||
|
||||
it("should not fetch when metadata documents are disabled", async () => {
|
||||
const clientId = buildClientId();
|
||||
const mock = mockDocument(clientId, buildDocument(clientId));
|
||||
env.OAUTH_DISABLE_CIMD = true;
|
||||
|
||||
try {
|
||||
expect(
|
||||
await ClientMetadataHelper.findOrFetchByClientId(clientId, team)
|
||||
).toBeNull();
|
||||
expect(mock.requests()).toEqual(0);
|
||||
} finally {
|
||||
env.OAUTH_DISABLE_CIMD = false;
|
||||
}
|
||||
});
|
||||
|
||||
it("should find a generated client without fetching", async () => {
|
||||
const client = await buildOAuthClient();
|
||||
const found = await ClientMetadataHelper.findOrFetchByClientId(
|
||||
|
||||
@@ -107,8 +107,8 @@ export class ClientMetadataHelper {
|
||||
*
|
||||
* @param clientId The public client identifier.
|
||||
* @param team The team of the user that requests the client.
|
||||
* @returns The OAuth client, or null if it is not found or the client_id is
|
||||
* not a valid metadata document URL.
|
||||
* @returns The OAuth client, or null if it is not found, the client_id is
|
||||
* not a valid metadata document URL, or metadata documents are disabled.
|
||||
* @throws AuthorizationError if the client is a metadata document and the
|
||||
* team has turned MCP off.
|
||||
* @throws InvalidClientMetadataError if the metadata document cannot be
|
||||
@@ -121,6 +121,9 @@ export class ClientMetadataHelper {
|
||||
if (!OAuthClient.isMetadataDocumentClientId(clientId)) {
|
||||
return OAuthClient.findByClientId(clientId);
|
||||
}
|
||||
if (env.OAUTH_DISABLE_CIMD) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Metadata documents only serve MCP, so do not fetch one for a team that
|
||||
// has turned it off.
|
||||
|
||||
Reference in new issue
Block a user