mirror of
https://github.com/outline/outline.git
synced 2026-11-29 16:40:27 +03:00
fix: Tighten guest access to integration data (#14434)
This commit is contained in:
1 parent
5b13e915d8
commit
4f2d186004
7 files changed
+109
-10
No files matched your search
@@ -118,6 +118,11 @@ class Integration<T = unknown> extends ParanoidModel<
|
||||
case IntegrationType.Embed: {
|
||||
const settings = this
|
||||
.settings as IntegrationSettings<IntegrationType.Embed>;
|
||||
|
||||
// Guests only need the URLs used to render and edit embeds.
|
||||
if (viewer?.isGuest) {
|
||||
return { url: settings?.url, diagrams: settings?.diagrams };
|
||||
}
|
||||
return {
|
||||
url: settings?.url,
|
||||
github: settings?.github,
|
||||
|
||||
@@ -14,7 +14,14 @@ allow(User, "createIntegration", Team, (actor, team) =>
|
||||
and(isTeamAdmin(actor, team), isTeamMutable(actor))
|
||||
);
|
||||
|
||||
allow(User, "read", Integration, isTeamModel);
|
||||
allow(User, "read", Integration, (actor, integration) =>
|
||||
and(
|
||||
isTeamModel(actor, integration),
|
||||
integration?.type === IntegrationType.LinkedAccount
|
||||
? isOwner(actor, integration)
|
||||
: !actor.isGuest || integration?.type === IntegrationType.Embed
|
||||
)
|
||||
);
|
||||
|
||||
allow(User, ["update", "delete"], Integration, (actor, integration) =>
|
||||
and(
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
buildAdmin,
|
||||
buildTeam,
|
||||
buildUser,
|
||||
buildGuestUser,
|
||||
buildIntegration,
|
||||
} from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
@@ -274,6 +275,47 @@ describe("#integrations.list", () => {
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].settings.url).toEqual("https://example.com");
|
||||
});
|
||||
|
||||
it("should only expose embed urls to guests", async () => {
|
||||
const team = await buildTeam();
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const guest = await buildGuestUser({ teamId: team.id });
|
||||
await buildIntegration({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
service: IntegrationService.GitHub,
|
||||
type: IntegrationType.Embed,
|
||||
settings: {
|
||||
url: "https://example.com",
|
||||
github: {
|
||||
installation: {
|
||||
id: 123,
|
||||
account: { id: 456, name: "acme", avatarUrl: "" },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
await buildIntegration({
|
||||
userId: admin.id,
|
||||
teamId: team.id,
|
||||
service: IntegrationService.Slack,
|
||||
type: IntegrationType.Post,
|
||||
settings: {
|
||||
url: "https://hooks.slack.com/services/secret",
|
||||
channel: "#general",
|
||||
channelId: "C123",
|
||||
} as IntegrationSettings<IntegrationType.Post>,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/integrations.list", guest);
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].type).toEqual(IntegrationType.Embed);
|
||||
expect(body.data[0].settings.url).toEqual("https://example.com");
|
||||
expect(body.data[0].settings.github).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#integrations.info", () => {
|
||||
@@ -308,7 +350,7 @@ describe("#integrations.info", () => {
|
||||
expect(body.data.settings.figma.account.email).toEqual("owner@example.com");
|
||||
});
|
||||
|
||||
it("should not expose linked account settings to other users", async () => {
|
||||
it("should not allow other users to read a linked account", async () => {
|
||||
const owner = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: owner.teamId });
|
||||
const integration = await buildFigmaAccount(owner);
|
||||
@@ -316,9 +358,29 @@ describe("#integrations.info", () => {
|
||||
const res = await server.post("/api/integrations.info", admin, {
|
||||
body: { id: integration.id },
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.settings).toBeUndefined();
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
|
||||
it("should not allow guests to read workspace integrations", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const guest = await buildGuestUser({ teamId: admin.teamId });
|
||||
const integration = await buildIntegration({
|
||||
userId: admin.id,
|
||||
teamId: admin.teamId,
|
||||
service: IntegrationService.Slack,
|
||||
type: IntegrationType.Post,
|
||||
settings: {
|
||||
url: "https://hooks.slack.com/services/secret",
|
||||
channel: "#general",
|
||||
channelId: "C123",
|
||||
} as IntegrationSettings<IntegrationType.Post>,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/integrations.info", guest, {
|
||||
body: { id: integration.id },
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
});
|
||||
@@ -35,15 +35,16 @@ router.post(
|
||||
where = { ...where, service };
|
||||
}
|
||||
|
||||
// Linked account is special as these are user-specific, other integrations are workspace-wide.
|
||||
// Linked account is special as these are user-specific, other integrations
|
||||
// are workspace-wide. Guests only receive embeds, which the editor needs.
|
||||
where = {
|
||||
...where,
|
||||
[Op.or]: [
|
||||
{ userId: user.id, type: IntegrationType.LinkedAccount },
|
||||
{
|
||||
type: {
|
||||
[Op.not]: IntegrationType.LinkedAccount,
|
||||
},
|
||||
type: user.isGuest
|
||||
? IntegrationType.Embed
|
||||
: { [Op.not]: IntegrationType.LinkedAccount },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
buildDocument,
|
||||
buildShare,
|
||||
buildTeam,
|
||||
buildGuestUser,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import Redis from "@server/storage/redis";
|
||||
@@ -559,6 +560,22 @@ Install instructions here.`
|
||||
);
|
||||
});
|
||||
|
||||
it("should not unfurl external urls for guests", async () => {
|
||||
const guest = await buildGuestUser({ teamId: user.teamId });
|
||||
const callCount = (Iframely.requestResource as Mock).mock.calls.length;
|
||||
|
||||
const res = await server.post("/api/urls.unfurl", guest, {
|
||||
body: {
|
||||
url: "https://github.com/acme/private/issues/1",
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(204);
|
||||
expect((Iframely.requestResource as Mock).mock.calls.length).toEqual(
|
||||
callCount
|
||||
);
|
||||
});
|
||||
|
||||
it("should succeed with status 204 no content for a non-existing external url", async () => {
|
||||
(Iframely.requestResource as Mock).mockResolvedValue(
|
||||
Promise.resolve({
|
||||
|
||||
@@ -190,7 +190,12 @@ router.post(
|
||||
return;
|
||||
}
|
||||
|
||||
// External resources
|
||||
// External resources are unfurled with workspace credentials
|
||||
if (actor.isGuest) {
|
||||
ctx.response.status = 204;
|
||||
return;
|
||||
}
|
||||
|
||||
// Use getDataOrSet which handles distributed locking to prevent thundering herd
|
||||
// when multiple clients request the same URL simultaneously
|
||||
const cacheKey = RedisPrefixHelper.getUnfurlKey(
|
||||
|
||||
@@ -221,6 +221,7 @@
|
||||
"{{ count }} share link revoked_plural": "{{ count }} share links revoked",
|
||||
"Could not revoke {{ count }} share link": "Could not revoke {{ count }} share link",
|
||||
"Could not revoke {{ count }} share link_plural": "Could not revoke {{ count }} share links",
|
||||
"{{ name }} (Logged out)": "{{ name }} (Logged out)",
|
||||
"Switch workspace": "Switch workspace",
|
||||
"Select a workspace": "Select a workspace",
|
||||
"New workspace": "New workspace",
|
||||
@@ -1149,6 +1150,7 @@
|
||||
"This doesn’t appear to be a valid installation": "This doesn’t appear to be a valid installation",
|
||||
"Choose a workspace": "Choose a workspace",
|
||||
"Choose an {{ appName }} workspace or log in to continue connecting this app": "Choose an {{ appName }} workspace or log in to continue connecting this app",
|
||||
"Logged out": "Logged out",
|
||||
"Create workspace": "Create workspace",
|
||||
"Set up your workspace by providing a name and details for admin login. You can change these later.": "Set up your workspace by providing a name and details for admin login. You can change these later.",
|
||||
"Workspace name": "Workspace name",
|
||||
|
||||
Reference in new issue
Block a user