MCPcopy Index your code
hub / github.com/AI45Lab/Code / validate_script_source

Function validate_script_source

core/src/tools/program_tool.rs:236–262  ·  view source on GitHub ↗
(source: &str)

Source from the content-addressed store, hash-verified

234}
235
236fn validate_script_source(source: &str) -> std::result::Result<(), String> {
237 let forbidden = [
238 ("import ", "imports are not allowed inside PTC scripts"),
239 (
240 "import(",
241 "dynamic imports are not allowed inside PTC scripts",
242 ),
243 ("eval(", "eval is not allowed inside PTC scripts"),
244 (
245 "Function(",
246 "Function constructor is not allowed inside PTC scripts",
247 ),
248 ("Worker(", "Worker is not allowed inside PTC scripts"),
249 ("WebSocket", "WebSocket is not allowed inside PTC scripts"),
250 (
251 "fetch(",
252 "fetch is not allowed inside PTC scripts; use ctx tools instead",
253 ),
254 ];
255
256 for (needle, message) in forbidden {
257 if source.contains(needle) {
258 return Err(message.to_string());
259 }
260 }
261 Ok(())
262}
263
264async fn run_quickjs_script(
265 source: &str,

Calls 1

containsMethod · 0.80

Tested by 1