Summary
txtai exposes a /reindex API endpoint whose function parameter is dynamically imported and invoked based on a caller-supplied dotted path, without any allowlist or validation.
When the API is reachable without authentication and the index is writable, a remote attacker can bind this parameter to arbitrary callables like subprocess utilities and execute code as the server process during reindexing.
Affected context
This vulnerability manifests in txtai deployments where:
- The HTTP API, including the /reindex endpoint, is exposed to untrusted networks
- No TOKEN-based authentication is configured (authentication is opt-in)
- The index is configured as writable, allowing reindex operations
Under these non-default conditions, user-supplied function paths provided to the /reindex endpoint are treated as trusted code and imported dynamically.
Exploit preconditions
- Attack surface: Network-exposed txtai API, specifically the /reindex endpoint
- Required access: Ability to send HTTP requests to the /reindex endpoint when no TOKEN is configured
- Configuration conditions: Writable index and /reindex enabled so that reindex operations are permitted
- Trigger point: Invocation of /reindex with a function body parameter containing an attacker-controlled dotted path
- Why exploitation is possible: txtai.util.Resolver performs __import__ and getattr on the supplied path without an allowlist or validation, allowing arbitrary callables to be resolved and executed during reindexing.
Why this happens
The core issue is a dynamic code resolution pattern that treats user input as a trusted reference to executable code.
The /reindex endpoint passes a caller-supplied dotted path into txtai.util.Resolver, which uses __import__ and getattr to resolve the path into a callable.
Because there is no allowlist, scoping, or validation of the modules and attributes that can be targeted, attackers can select powerful built-in or standard library functions, effectively injecting arbitrary behavior.
This aligns with CWE-94 (Improper Control of Generation of Code), where untrusted input directly influences what code is loaded and executed in the application context.
Potential impact
- Remote execution of arbitrary OS commands under the txtai server's privileges
- Full compromise of the txtai process and associated data
- Unauthorized modification or destruction of indexed content
- Use of the txtai host as a pivot for lateral movement inside the network
- Deployment of backdoors or persistence mechanisms in the hosting environment
General mitigation guidance
Effective mitigation focuses on eliminating the ability for user input to select arbitrary executable code and tightening exposure of sensitive administrative endpoints.
Recommended defensive patterns include:
- Restricting dynamic code resolution to a small, explicit allowlist of safe, internally defined functions
- Avoiding the use of __import__ and getattr on untrusted strings and favoring static mappings or configuration-driven registries
- Treating administrative endpoints like /reindex as privileged operations, gated by configuration flags, authentication, and authorization checks
- Running the txtai service with least privilege so that, if compromised, the process has minimal OS-level capabilities
- Limiting write access to the index to trusted components and using network segmentation to keep the API away from untrusted clients
How teams detect issues like this
Organizations can detect similar issues and potential exploitation through a combination of code-focused and runtime signals:
- Static analysis rules that flag use of __import__, getattr, or dynamic module loading where parameters originate from request data or other untrusted sources
- Code review practices that scrutinize administrative endpoints and configuration-driven execution paths, looking for places where user input influences callable selection
- Logging and monitoring of /reindex usage, alerting on unusual function values, unexpected modules, or high-risk standard library callables
- Security policies in CI/CD that require explicit allowlists for dynamic function registries and that block deployment when unsafe patterns are detected

