Summary
A code injection vulnerability in LiteLLM's pass-through endpoint handling can allow an authenticated attacker to execute arbitrary code. The risk arises when input is not properly validated before it is executed through module import.
Affected context
The issue occurs in LiteLLM's handling of pass-through endpoints, where code is executed via module import without adequate validation. Exploitation requires authentication and may affect deployments where an attacker can reach the relevant endpoint and provide input that reaches this code path.
Exploit preconditions
- Attack surface: LiteLLM pass-through endpoint handling
- Required access: Authentication to the affected service
- Trigger point: Processing input through the vulnerable endpoint path
- Why exploitation is possible: Code is not adequately validated before execution via module import
Why this happens
The underlying flaw is improper control over code generation or execution, mapped to CWE-94: Improper Control of Generation of Code. The application allows input to influence code executed through module import without sufficient validation or restrictions.
Potential impact
- An authenticated attacker could execute arbitrary code in the context of the LiteLLM service account.
- The attacker may be able to access data or resources available to that account.
- Depending on the service account's permissions and deployment boundaries, compromise could affect connected systems or services.
General mitigation guidance
Defensive approaches focus on preventing untrusted input from influencing executable code.
- Prefer fixed, explicit module mappings over dynamically importing modules based on request-controlled values.
- Validate inputs against strict allowlists and reject values outside the expected schema.
- Separate data handling from code execution and avoid evaluating or importing request-derived content.
- Limit the service account's permissions and restrict its access to sensitive resources.
- Reduce exposure of authenticated endpoints and apply authorization checks appropriate to the operation.
How teams detect issues like this
- Use static analysis to identify dynamic imports or execution paths influenced by request data.
- Review pass-through endpoint code for validation performed only after import or execution.
- Check whether module names, paths, or other import parameters can be derived from user-controlled input.
- Apply code-review and CI policies that flag dynamic execution and require documented validation and authorization.

