Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/server/src/Interface.DocumentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ export class DocumentStoreDTO {

static toEntity(body: any): DocumentStore {
const docStore = new DocumentStore()
Object.assign(docStore, body)
// Explicit allowlist — never accept id or timestamps from client
docStore.name = body.name
docStore.description = body.description ?? null
docStore.loaders = body.loaders ?? '[]'
docStore.whereUsed = body.whereUsed ?? '[]'
docStore.vectorStoreConfig = body.vectorStoreConfig ?? null
docStore.embeddingConfig = body.embeddingConfig ?? null
docStore.recordManagerConfig = body.recordManagerConfig ?? null
// when a new document store is created, it is empty and in sync
docStore.status = DocumentStoreStatus.EMPTY_SYNC
return docStore
Expand Down
14 changes: 11 additions & 3 deletions packages/server/src/controllers/documentstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ const createDocumentStore = async (req: Request, res: Response, next: NextFuncti
}

const body = req.body
body.workspaceId = req.user?.activeWorkspaceId
if (!body.workspaceId) {
const workspaceId = req.user?.activeWorkspaceId
if (!workspaceId) {
throw new InternalFlowiseError(
StatusCodes.PRECONDITION_FAILED,
`Error: documentStoreController.createDocumentStore - workspaceId not provided!`
)
}
const docStore = DocumentStoreDTO.toEntity(body)
docStore.workspaceId = workspaceId
const apiResponse = await documentStoreService.createDocumentStore(docStore, orgId)
return res.json(apiResponse)
} catch (error) {
Expand Down Expand Up @@ -355,7 +356,14 @@ const updateDocumentStore = async (req: Request, res: Response, next: NextFuncti
}
const body = req.body
const updateDocStore = new DocumentStore()
Object.assign(updateDocStore, body)
// Explicit allowlist — id/workspaceId/timestamps must not be overrideable by client
if (body.name !== undefined) updateDocStore.name = body.name
if (body.description !== undefined) updateDocStore.description = body.description
if (body.vectorStoreConfig !== undefined) updateDocStore.vectorStoreConfig = body.vectorStoreConfig
if (body.embeddingConfig !== undefined) updateDocStore.embeddingConfig = body.embeddingConfig
if (body.recordManagerConfig !== undefined) updateDocStore.recordManagerConfig = body.recordManagerConfig
if (body.loaders !== undefined) updateDocStore.loaders = body.loaders
if (body.whereUsed !== undefined) updateDocStore.whereUsed = body.whereUsed
const apiResponse = await documentStoreService.updateDocumentStore(store, updateDocStore)
return res.json(DocumentStoreDTO.fromEntity(apiResponse))
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/services/documentstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ const upsertDocStore = async (
const docStoreBody = typeof data.docStore === 'string' ? JSON.parse(data.docStore) : data.docStore
const newDocumentStore = docStoreBody ?? { name: `Document Store ${Date.now().toString()}` }
const docStore = DocumentStoreDTO.toEntity(newDocumentStore)
docStore.workspaceId = workspaceId // enforce trusted server-side value, never from user input
const documentStore = appDataSource.getRepository(DocumentStore).create(docStore)
const dbResponse = await appDataSource.getRepository(DocumentStore).save(documentStore)
storeId = dbResponse.id
Expand Down