| 234 | } |
| 235 | |
| 236 | fn 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 | |
| 264 | async fn run_quickjs_script( |
| 265 | source: &str, |