Skip to content

Commit 0c8236a

Browse files
christopherholland-workdaychristopherholland-workday
andauthored
Sanitize Code Ran in Pyodide in CSVAgent (#5836)
* Stop axios from throwing error on non-2xx response * Sanitize Code Ran in Pyodide in CSVAgents --------- Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
1 parent 8c2b2ff commit 0c8236a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

packages/components/nodes/agents/CSVAgent/CSVAgent.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ class CSV_Agents implements INode {
144144
// For example using titanic.csv: {'PassengerId': 'int64', 'Survived': 'int64', 'Pclass': 'int64', 'Name': 'object', 'Sex': 'object', 'Age': 'float64', 'SibSp': 'int64', 'Parch': 'int64', 'Ticket': 'object', 'Fare': 'float64', 'Cabin': 'object', 'Embarked': 'object'}
145145
let dataframeColDict = ''
146146
let customReadCSVFunc = _customReadCSV ? _customReadCSV : 'read_csv(csv_data)'
147+
const csvReadValidation = validatePythonCodeForDataFrame(customReadCSVFunc)
148+
if (!csvReadValidation.valid) {
149+
throw new Error(
150+
`Custom read_csv code was rejected for security reasons (${
151+
csvReadValidation.reason ?? 'unsafe construct'
152+
}). Please use only safe pandas read_csv operations.`
153+
)
154+
}
147155
try {
148156
const code = `import pandas as pd
149157
import base64

packages/components/src/httpSecurity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function secureAxiosRequest(config: AxiosRequestConfig, maxRedirect
104104
}
105105

106106
let redirects = 0
107-
let currentConfig = { ...config, maxRedirects: 0 } // Disable automatic redirects
107+
let currentConfig = { ...config, maxRedirects: 0, validateStatus: () => true } // Disable automatic redirects, accept all status codes
108108

109109
while (redirects <= maxRedirects) {
110110
const target = await resolveAndValidate(currentUrl)

0 commit comments

Comments
 (0)