fix(interpreter security): functions from the builtins module must be explicitely added so as to prevent the dangerous ones from being indirectly available (compile, exec, eval, breakpoint, __import__, open, ...) (#299)
This commit is contained in:
		
							parent
							
								
									398c932250
								
							
						
					
					
						commit
						83ecd572fc
					
				|  | @ -17,6 +17,7 @@ | ||||||
| import ast | import ast | ||||||
| import builtins | import builtins | ||||||
| import difflib | import difflib | ||||||
|  | import inspect | ||||||
| import math | import math | ||||||
| import re | import re | ||||||
| from collections.abc import Mapping | from collections.abc import Mapping | ||||||
|  | @ -643,8 +644,14 @@ def evaluate_call( | ||||||
|             # cap the number of lines |             # cap the number of lines | ||||||
|             return None |             return None | ||||||
|         else:  # Assume it's a callable object |         else:  # Assume it's a callable object | ||||||
|             if (func in [eval, compile, exec]) and (func not in static_tools.values()): |             if ( | ||||||
|                 raise InterpreterError(f"Invoking eval, compile or exec is not allowed ({func_name}).") |                 (inspect.getmodule(func) == builtins) | ||||||
|  |                 and inspect.isbuiltin(func) | ||||||
|  |                 and (func not in static_tools.values()) | ||||||
|  |             ): | ||||||
|  |                 raise InterpreterError( | ||||||
|  |                     f"Invoking a builtin function that has not been explicitly added as a tool is not allowed ({func_name})." | ||||||
|  |                 ) | ||||||
|             return func(*args, **kwargs) |             return func(*args, **kwargs) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue