-
-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Add protections for loop-bound injections #5849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ac8a988
b76bccc
99a659d
b0eae70
3602b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,14 +72,31 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str | |
| const row = appServer.AppDataSource.getRepository(Evaluation).create(newEval) | ||
| row.average_metrics = JSON.stringify({}) | ||
|
|
||
| // Parse and validate evaluator arrays to prevent DoS attacks | ||
| const chatflowTypes = body.chatflowType ? JSON.parse(body.chatflowType) : [] | ||
| if (!Array.isArray(chatflowTypes)) { | ||
| throw new Error('chatflowType must be a valid array') | ||
| } | ||
|
|
||
| const simpleEvaluators = body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : [] | ||
|
christopherholland-workday marked this conversation as resolved.
Outdated
|
||
| if (!Array.isArray(simpleEvaluators)) { | ||
| throw new Error('selectedSimpleEvaluators must be a valid array') | ||
| } | ||
|
|
||
| const additionalConfig: ICommonObject = { | ||
| chatflowTypes: body.chatflowType ? JSON.parse(body.chatflowType) : [], | ||
| chatflowTypes: chatflowTypes, | ||
| datasetAsOneConversation: body.datasetAsOneConversation, | ||
| simpleEvaluators: body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : [] | ||
| simpleEvaluators: simpleEvaluators | ||
| } | ||
|
|
||
| if (body.evaluationType === 'llm') { | ||
| additionalConfig.lLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : [] | ||
| const lLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : [] | ||
|
christopherholland-workday marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (!Array.isArray(lLMEvaluators)) { | ||
| throw new Error('selectedLLMEvaluators must be a valid array') | ||
| } | ||
|
|
||
| additionalConfig.lLMEvaluators = lLMEvaluators | ||
|
Comment on lines
+75
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's repetition in parsing and validating arrays from the request body ( Example: References
|
||
| additionalConfig.llmConfig = { | ||
| credentialId: body.credentialId, | ||
| llm: body.llm, | ||
|
|
@@ -123,6 +140,12 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str | |
| // When chatflow has an APIKey | ||
| const apiKeys: { chatflowId: string; apiKey: string }[] = [] | ||
| const chatflowIds = JSON.parse(body.chatflowId) | ||
|
|
||
| // Validate chatflowIds is an actual array to prevent DoS attacks | ||
| if (!Array.isArray(chatflowIds)) { | ||
| throw new Error('chatflowId must be a valid array') | ||
| } | ||
|
|
||
| for (let i = 0; i < chatflowIds.length; i++) { | ||
| const chatflowId = chatflowIds[i] | ||
| const cFlow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({ | ||
|
|
@@ -246,7 +269,7 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str | |
| metricsArray, | ||
| actualOutputArray, | ||
| errorArray, | ||
| body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : [], | ||
| additionalConfig.simpleEvaluators, | ||
| workspaceId | ||
| ) | ||
|
|
||
|
|
@@ -257,7 +280,7 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str | |
|
|
||
| if (body.evaluationType === 'llm') { | ||
| resultRow.llmConfig = additionalConfig.llmConfig | ||
| resultRow.LLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : [] | ||
| resultRow.LLMEvaluators = additionalConfig.lLMEvaluators | ||
| const llmEvaluatorMap: { evaluatorId: string; evaluator: any }[] = [] | ||
| for (let i = 0; i < resultRow.LLMEvaluators.length; i++) { | ||
| const evaluatorId = resultRow.LLMEvaluators[i] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.