Validate a deserialized function reference. This hook is called after a function has been deserialized (either by importing from a module or reconstructing from serialized code), but before it is used. When Called ----------- - After importing global functio
(self, func, is_local: bool, **kwargs)
| 236 | return None |
| 237 | |
| 238 | def validate_function(self, func, is_local: bool, **kwargs): |
| 239 | """Validate a deserialized function reference. |
| 240 | |
| 241 | This hook is called after a function has been deserialized (either by importing |
| 242 | from a module or reconstructing from serialized code), but before it is used. |
| 243 | |
| 244 | When Called |
| 245 | ----------- |
| 246 | - After importing global functions via importlib |
| 247 | - After reconstructing local functions/lambdas from marshalled code |
| 248 | - Before the function is stored or called |
| 249 | |
| 250 | Security Use Cases |
| 251 | ------------------ |
| 252 | - Block dangerous built-in functions (eval, exec, compile, __import__) |
| 253 | - Validate that reconstructed functions have expected signatures |
| 254 | - Audit function imports for security logging |
| 255 | |
| 256 | Args: |
| 257 | func (function): The deserialized function object. |
| 258 | is_local (bool): True if the function is local (defined in __main__ or |
| 259 | within a function scope), False if it's a global function. |
| 260 | **kwargs: Reserved for future extensions. |
| 261 | |
| 262 | Raises: |
| 263 | Exception: Raise any exception to reject the function. |
| 264 | |
| 265 | Example: |
| 266 | >>> class SafeFunctionChecker(DeserializationPolicy): |
| 267 | ... BLOCKED = {'eval', 'exec', 'compile', '__import__'} |
| 268 | ... |
| 269 | ... def validate_function(self, func, is_local, **kwargs): |
| 270 | ... if func.__name__ in self.BLOCKED: |
| 271 | ... raise ValueError(f"Function {func.__name__} is forbidden") |
| 272 | |
| 273 | Note: |
| 274 | `check_function` is an alias for this hook. |
| 275 | """ |
| 276 | return None |
| 277 | |
| 278 | def validate_method(self, method, is_local: bool, **kwargs): |
| 279 | """Validate a deserialized method reference. |
no outgoing calls
no test coverage detected