Skip to content

Commit 188bc09

Browse files
authored
Audit / Removal / Auth check of all dataSource related endpoint (#9750)
* Add canAdministrate to connector config setter * remove unused table post/delete * remove unused table endpoints * add canAdministrate on managed/update * remove configuration endpoint * auth audit on connector * add isUser to request_access * remove unused search endpoint * canRead for usage endpoint * restrict data_sources/dsId POST * remove legacy managed endpoint * nit
1 parent 668c871 commit 188bc09

File tree

17 files changed

+57
-1201
lines changed

17 files changed

+57
-1201
lines changed

front/components/data_source/TableUploadOrEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
2727

2828
import { useFileUploaderService } from "@app/hooks/useFileUploaderService";
2929
import {
30-
useCreateDataSourceViewTable,
30+
useCreateDataSourceTable,
3131
useDataSourceViewTable,
3232
useUpdateDataSourceViewTable,
3333
} from "@app/lib/swr/data_source_view_tables";
@@ -126,7 +126,7 @@ export const TableUploadOrEditModal = ({
126126
dataSourceView,
127127
initialId ?? ""
128128
);
129-
const doCreate = useCreateDataSourceViewTable(owner, dataSourceView);
129+
const doCreate = useCreateDataSourceTable(owner, dataSourceView);
130130

131131
const handleTableUpload = useCallback(
132132
async (table: Table) => {

front/components/spaces/SpaceResourcesList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ export const SpaceResourcesList = ({
439439
.map(
440440
(v) => v.dataSource
441441
) as DataSourceWithConnectorDetailsType[]
442-
// We need to filter and then cast because useSpaceDataSourceViewsWithDetails can return dataSources with connectorProvider as null
442+
// We need to filter and then cast because useSpaceDataSourceViewsWithDetails can
443+
// return dataSources with connectorProvider as null
443444
}
444445
setIsProviderLoading={(provider, isLoading) => {
445446
setIsNewConnectorLoading(isLoading);

front/lib/swr/data_source_view_tables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function useUpdateDataSourceViewTable(
134134
return doUpdate;
135135
}
136136

137-
export function useCreateDataSourceViewTable(
137+
export function useCreateDataSourceTable(
138138
owner: LightWorkspaceType,
139139
dataSourceView: DataSourceViewType
140140
) {

front/pages/api/w/[wId]/data_sources/[dsId]/configuration.ts

Lines changed: 0 additions & 187 deletions
This file was deleted.

front/pages/api/w/[wId]/data_sources/[dsId]/connector.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ async function handler(
2929
});
3030
}
3131

32+
// This endpoint can be access by non admin to get the connector chip status. Ensure that no
33+
// specific data other than the connection state is returned.
34+
3235
const dataSource = await DataSourceResource.fetchById(auth, dsId);
33-
if (!dataSource) {
36+
if (!dataSource || !auth.isUser()) {
3437
return apiError(req, res, {
3538
status_code: 404,
3639
api_error: {
@@ -81,4 +84,5 @@ async function handler(
8184
}
8285
}
8386

87+
// Ensure the user is authenticated hand has at least the user role.
8488
export default withSessionAuthenticationForWorkspace(handler);

front/pages/api/w/[wId]/data_sources/[dsId]/index.ts

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type { DataSourceType, WithAPIErrorResponse } from "@dust-tt/types";
2-
import { MANAGED_DS_DELETABLE } from "@dust-tt/types";
32
import type { NextApiRequest, NextApiResponse } from "next";
43

54
import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers";
6-
import { softDeleteDataSourceAndLaunchScrubWorkflow } from "@app/lib/api/data_sources";
75
import type { Authenticator } from "@app/lib/auth";
86
import { DataSourceResource } from "@app/lib/resources/data_source_resource";
97
import { apiError } from "@app/logger/withlogging";
@@ -42,12 +40,6 @@ async function handler(
4240
}
4341

4442
switch (req.method) {
45-
case "GET":
46-
res.status(200).json({
47-
dataSource: dataSource.toJSON(),
48-
});
49-
return;
50-
5143
case "POST":
5244
if (!auth.isBuilder()) {
5345
return apiError(req, res, {
@@ -60,100 +52,28 @@ async function handler(
6052
});
6153
}
6254

63-
if (dataSource.connectorId) {
64-
// managed data source
65-
if (
66-
!req.body ||
67-
typeof req.body.assistantDefaultSelected !== "boolean" ||
68-
Object.keys(req.body).length !== 1
69-
) {
70-
return apiError(req, res, {
71-
status_code: 400,
72-
api_error: {
73-
type: "invalid_request_error",
74-
message:
75-
"Only the assistantDefaultSelected setting can be updated for managed data sources, which must be boolean.",
76-
},
77-
});
78-
}
79-
80-
await dataSource.setDefaultSelectedForAssistant(
81-
req.body.assistantDefaultSelected
82-
);
83-
} else {
84-
// non-managed data source
85-
if (
86-
!req.body ||
87-
(typeof req.body.description !== "string" &&
88-
typeof req.body.assistantDefaultSelected !== "boolean")
89-
) {
90-
return apiError(req, res, {
91-
status_code: 400,
92-
api_error: {
93-
type: "invalid_request_error",
94-
message: "The request body is missing",
95-
},
96-
});
97-
}
98-
99-
if (typeof req.body.description === "string") {
100-
await dataSource.setDescription(req.body.description);
101-
}
102-
103-
if (typeof req.body.assistantDefaultSelected === "boolean") {
104-
await dataSource.setDefaultSelectedForAssistant(
105-
req.body.assistantDefaultSelected
106-
);
107-
}
108-
}
109-
110-
return res.status(200).json({
111-
dataSource: dataSource.toJSON(),
112-
});
113-
114-
case "DELETE":
115-
if (!auth.isBuilder()) {
116-
return apiError(req, res, {
117-
status_code: 403,
118-
api_error: {
119-
type: "data_source_auth_error",
120-
message:
121-
"Only the users that are `builders` for the current workspace can delete a data source.",
122-
},
123-
});
124-
}
125-
126-
// We only allow deleteing selected managed data sources as builder.
12755
if (
128-
dataSource.connectorId &&
129-
dataSource.connectorProvider &&
130-
!MANAGED_DS_DELETABLE.includes(dataSource.connectorProvider)
56+
!req.body ||
57+
typeof req.body.assistantDefaultSelected !== "boolean" ||
58+
Object.keys(req.body).length !== 1
13159
) {
13260
return apiError(req, res, {
13361
status_code: 400,
13462
api_error: {
13563
type: "invalid_request_error",
136-
message: "Managed data sources cannot be deleted.",
64+
message:
65+
"Only the assistantDefaultSelected setting can be updated for managed data sources, which must be boolean.",
13766
},
13867
});
13968
}
14069

141-
const dRes = await softDeleteDataSourceAndLaunchScrubWorkflow(
142-
auth,
143-
dataSource
70+
await dataSource.setDefaultSelectedForAssistant(
71+
req.body.assistantDefaultSelected
14472
);
145-
if (dRes.isErr()) {
146-
return apiError(req, res, {
147-
status_code: 500,
148-
api_error: {
149-
type: "internal_server_error",
150-
message: dRes.error.message,
151-
},
152-
});
153-
}
15473

155-
res.status(204).end();
156-
return;
74+
return res.status(200).json({
75+
dataSource: dataSource.toJSON(),
76+
});
15777

15878
default:
15979
return apiError(req, res, {

front/pages/api/w/[wId]/data_sources/[dsId]/managed/config/[key]/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ async function handler(
115115
return;
116116

117117
case "POST":
118-
if (!auth.isAdmin()) {
118+
if (!auth.isAdmin() || !dataSource.canAdministrate(auth)) {
119119
return apiError(req, res, {
120120
status_code: 403,
121121
api_error: {
122122
type: "data_source_auth_error",
123123
message:
124-
"Only the users that are `admins` for the current workspace can edit the configuration of a data source.",
124+
"Only the users that are `admins` for the current workspace " +
125+
"can edit the configuration of a data source.",
125126
},
126127
});
127128
}

0 commit comments

Comments
 (0)