Skip to content

Commit 8ce06c7

Browse files
authored
Refactor/Update endpoint routing configuration (#5645)
refactor(server): update endpoint routing configuration
1 parent ae98706 commit 8ce06c7

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

packages/server/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { RedisEventSubscriber } from './queue/RedisEventSubscriber'
2626
import flowiseApiV1Router from './routes'
2727
import { UsageCacheManager } from './UsageCacheManager'
2828
import { getEncryptionKey, getNodeModulesPackagePath } from './utils'
29-
import { WHITELIST_URLS } from './utils/constants'
29+
import { API_KEY_BLACKLIST_URLS, WHITELIST_URLS } from './utils/constants'
3030
import logger, { expressRequestLogger } from './utils/logger'
3131
import { RateLimiterManager } from './utils/rateLimit'
3232
import { SSEStreamer } from './utils/SSEStreamer'
@@ -224,6 +224,11 @@ export class App {
224224
} else if (req.headers['x-request-from'] === 'internal') {
225225
verifyToken(req, res, next)
226226
} else {
227+
const isAPIKeyBlacklistedURLS = API_KEY_BLACKLIST_URLS.some((url) => req.path.startsWith(url))
228+
if (isAPIKeyBlacklistedURLS) {
229+
return res.status(401).json({ error: 'Unauthorized Access' })
230+
}
231+
227232
// Only check license validity for non-open-source platforms
228233
if (this.identityManager.getPlatformType() !== Platform.OPEN_SOURCE) {
229234
if (!this.identityManager.isLicenseValid()) {

packages/server/src/utils/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const WHITELIST_URLS = [
1010
'/api/v1/public-chatbotConfig',
1111
'/api/v1/public-executions',
1212
'/api/v1/prediction/',
13-
'/api/v1/vector/upsert/',
1413
'/api/v1/node-icon/',
1514
'/api/v1/components-credentials-icon/',
1615
'/api/v1/chatflows-streaming',
@@ -23,7 +22,6 @@ export const WHITELIST_URLS = [
2322
'/api/v1/ping',
2423
'/api/v1/version',
2524
'/api/v1/attachments',
26-
'/api/v1/nvidia-nim',
2725
'/api/v1/auth/resolve',
2826
'/api/v1/auth/login',
2927
'/api/v1/auth/refreshToken',
@@ -56,6 +54,8 @@ export const WHITELIST_URLS = [
5654
GithubSSO.CALLBACK_URI
5755
]
5856

57+
export const API_KEY_BLACKLIST_URLS = ['/api/v1/nvidia-nim']
58+
5959
export const enum GeneralErrorMessage {
6060
UNAUTHORIZED = 'Unauthorized',
6161
UNHANDLED_EDGE_CASE = 'Unhandled Edge Case',

packages/server/src/utils/upsertVector.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
import { Request } from 'express'
2-
import * as path from 'path'
3-
import { cloneDeep, omit } from 'lodash'
42
import {
5-
IMessage,
63
addArrayFilesToStorage,
7-
mapMimeTypeToInputField,
8-
mapExtToInputField,
94
getFileFromUpload,
5+
IMessage,
6+
mapExtToInputField,
7+
mapMimeTypeToInputField,
108
removeSpecificFileFromUpload
119
} from 'flowise-components'
12-
import logger from '../utils/logger'
10+
import { StatusCodes } from 'http-status-codes'
11+
import { cloneDeep, omit } from 'lodash'
12+
import * as path from 'path'
13+
import { v4 as uuidv4 } from 'uuid'
14+
import { ChatType, IExecuteFlowParams, IncomingInput, INodeDirectedGraph, IReactFlowObject, MODE } from '../Interface'
15+
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../Interface.Metrics'
16+
import { ChatFlow } from '../database/entities/ChatFlow'
17+
import { UpsertHistory } from '../database/entities/UpsertHistory'
18+
import { Variable } from '../database/entities/Variable'
19+
import { Organization } from '../enterprise/database/entities/organization.entity'
20+
import { Workspace } from '../enterprise/database/entities/workspace.entity'
21+
import { getWorkspaceSearchOptions } from '../enterprise/utils/ControllerServiceUtils'
22+
import { InternalFlowiseError } from '../errors/internalFlowiseError'
23+
import { getErrorMessage } from '../errors/utils'
1324
import {
1425
buildFlow,
1526
constructGraphs,
16-
getAllConnectedNodes,
1727
findMemoryNode,
18-
getMemorySessionId,
28+
getAllConnectedNodes,
29+
getAPIOverrideConfig,
1930
getAppVersion,
20-
getTelemetryFlowObj,
31+
getMemorySessionId,
2132
getStartingNodes,
22-
getAPIOverrideConfig
33+
getTelemetryFlowObj
2334
} from '../utils'
24-
import { validateFlowAPIKey } from './validateKey'
25-
import { IncomingInput, INodeDirectedGraph, IReactFlowObject, ChatType, IExecuteFlowParams, MODE } from '../Interface'
26-
import { ChatFlow } from '../database/entities/ChatFlow'
2735
import { getRunningExpressApp } from '../utils/getRunningExpressApp'
28-
import { UpsertHistory } from '../database/entities/UpsertHistory'
29-
import { InternalFlowiseError } from '../errors/internalFlowiseError'
30-
import { StatusCodes } from 'http-status-codes'
31-
import { checkStorage, updateStorageUsage } from './quotaUsage'
32-
import { validateFileMimeTypeAndExtensionMatch } from './fileValidation'
33-
import { getErrorMessage } from '../errors/utils'
34-
import { v4 as uuidv4 } from 'uuid'
35-
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../Interface.Metrics'
36-
import { Variable } from '../database/entities/Variable'
37-
import { getWorkspaceSearchOptions } from '../enterprise/utils/ControllerServiceUtils'
36+
import logger from '../utils/logger'
3837
import { OMIT_QUEUE_JOB_DATA } from './constants'
39-
import { Workspace } from '../enterprise/database/entities/workspace.entity'
40-
import { Organization } from '../enterprise/database/entities/organization.entity'
38+
import { validateFileMimeTypeAndExtensionMatch } from './fileValidation'
39+
import { checkStorage, updateStorageUsage } from './quotaUsage'
40+
import { validateFlowAPIKey } from './validateKey'
4141

4242
export const executeUpsert = async ({
4343
componentNodes,
@@ -262,7 +262,6 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
262262
}
263263
}
264264

265-
// This can be public API, so we can only get orgId from the chatflow
266265
const chatflowWorkspaceId = chatflow.workspaceId
267266
const workspace = await appServer.AppDataSource.getRepository(Workspace).findOneBy({
268267
id: chatflowWorkspaceId
@@ -272,6 +271,8 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
272271
}
273272
const workspaceId = workspace.id
274273

274+
if (workspaceId !== req.user?.activeWorkspaceId) throw new InternalFlowiseError(StatusCodes.UNAUTHORIZED, 'Unauthorized')
275+
275276
const org = await appServer.AppDataSource.getRepository(Organization).findOneBy({
276277
id: workspace.organizationId
277278
})

0 commit comments

Comments
 (0)