Summary
DocsGPT's custom prompt feature renders user-controlled prompt content as a Jinja template without sufficient sanitization or sandboxing. An unauthenticated attacker may inject template expressions that execute server-side, potentially resulting in remote code execution and compromise of the application host.
Affected context
The vulnerability occurs in DocsGPT deployments that expose the custom prompt functionality and process user-defined prompt content through a Jinja template engine. Risk is highest when prompt data can be submitted without authentication and is rendered with access to server-side objects, functions, or operating-system capabilities.
Exploit preconditions
- Attack surface: The application's custom prompt feature and associated chatbot interaction endpoint
- Required access: No authentication may be required when the affected functionality is publicly accessible
- Trigger point: Server-side rendering of attacker-controlled prompt content as a Jinja template
- Why exploitation is possible: Template expressions are evaluated without adequate input isolation, sanitization, or sandbox restrictions
Why this happens
The underlying issue is the treatment of user-controlled prompt text as executable template source rather than inert data. When a template engine evaluates untrusted content with access to a powerful execution context, attacker-supplied expressions may traverse objects or invoke capabilities beyond the intended prompt-rendering behavior. This is consistent with CWE-94: Improper Control of Generation of Code, because externally influenced input can affect server-side code or expression execution.
Potential impact
- An attacker may execute arbitrary commands on the DocsGPT server
- The application process could be fully compromised
- Sensitive files, credentials, or environment data may be exposed
- The attacker could alter chatbot behavior or stored application data
- The vulnerable host could be used for lateral movement or further attacks
General mitigation guidance
Mitigation generally focuses on ensuring that user-provided prompt content remains data and cannot become executable template source.
Common defensive patterns include:
- Rendering untrusted values through fixed, developer-controlled templates
- Using a restricted template environment with minimal objects, filters, and capabilities
- Avoiding evaluation of user-supplied template syntax whenever possible
- Applying strict allowlists and contextual validation to custom prompt fields
- Separating prompt composition from server-side expression evaluation
- Running the application with least-privilege operating-system and service permissions
- Limiting access to secrets, filesystems, subprocess interfaces, and network resources
- Applying authentication and authorization controls to prompt-management functionality
How teams detect issues like this
Detection approaches can include:
- Static analysis rules that identify template rendering of request parameters or user-controlled fields
- Code review checks for dynamic template compilation and unrestricted Jinja environments
- Tests that submit template metacharacters and verify they remain inert data
- Runtime monitoring for unexpected template errors, process launches, or outbound connections from the application
- Policy enforcement preventing untrusted input from reaching template-compilation APIs
- Automated security review tools that flag server-side template injection patterns

