Summary
Dynaconf's @Jinja resolver evaluates Jinja2 template expressions inside configuration values without sandboxing, leading to a Server-Side Template Injection (SSTI) condition.
When untrusted configuration data can reach these templates and the jinja2 package is installed, an attacker may abuse template evaluation to execute arbitrary code or access sensitive data on the server.
Affected context
This vulnerability affects Python applications that:
- Use Dynaconf for configuration management
- Enable or rely on the @Jinja resolver to process template-like configuration values
- Have the
jinja2package installed in the runtime environment - Allow user-controlled or otherwise untrusted data to be stored in, or influence, Dynaconf-managed configuration values
In such setups, template expressions embedded in configuration entries are evaluated with powerful capabilities instead of being treated as inert data.
Exploit preconditions
- Attack surface: Any code path where Dynaconf loads and resolves configuration values annotated for Jinja processing (e.g., values using @Jinja or equivalent mechanisms).
- Required access: Ability to influence or control configuration data consumed by Dynaconf (e.g., configuration files, environment variables, dynamic settings, or external sources wired into Dynaconf).
- Trigger point: The moment Dynaconf resolves configuration values and invokes the Jinja2 engine to render template expressions.
- Why exploitation is possible: The template engine is invoked without a sandboxed or restricted environment, exposing powerful Jinja2 features to attacker-controlled expressions and enabling arbitrary expression evaluation in a server-side context.
Why this happens
The underlying flaw aligns with CWE-94: Improper Control of Generation of Code ('Code Injection') and CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine.
Dynaconf's @Jinja resolver treats configuration values as templates and evaluates them using Jinja2 without adequately constraining what templates can do or which inputs are trusted.
This pattern effectively promotes configuration data into executable template logic and fails to enforce a strict separation between data and code.
In environments where configuration sources may be influenced by end users or external systems, this unbounded template evaluation creates a direct path from untrusted input to server-side expression execution.
Potential impact
- Execution of arbitrary code in the context of the affected Python process
- Access to sensitive configuration values, secrets, and environment variables
- Unauthorized file reads or interaction with local resources accessible to the application
- Escalation from configuration tampering to full application or host compromise
- Lateral movement within the environment if the compromised process has network privileges
General mitigation guidance
Mitigations typically focus on removing or strictly constraining the ability of untrusted data to become executable template content:
- Avoid using dynamic template evaluation for configuration values unless absolutely necessary; prefer static or literal configuration data.
- Treat all configuration sources as untrusted by default and avoid routing them through powerful template engines.
- If template resolution is required, restrict it to trusted, curated inputs and disable template processing for user- or externally-controlled values.
- Use sandboxed or restricted template environments that limit available functions, builtins, and environment access when processing configuration templates.
- Apply least-privilege principles to the runtime process so that, even if templates are abused, accessible resources and system impact are constrained.
How teams detect issues like this
Detection can combine code-level analysis with configuration and deployment reviews:
- Static analysis: Search for uses of Dynaconf's @Jinja resolver or any code paths that call Jinja2 render methods on configuration-derived values; flag cases where input can originate from external sources.
- Code review: Examine configuration loading pipelines, paying attention to decorators, resolvers, or hooks that transform configuration values using template engines; look for mixing of user-influenced data with template evaluation.
- Configuration review: Audit how configuration is supplied (files, environment variables, remote stores) and identify fields that may embed Jinja expressions; verify whether those sources are controlled or validated.
- Policy enforcement: Enforce internal guidelines that prohibit server-side template evaluation of data originating from untrusted sources, and use automated checks in CI to detect new instances of unsafe template evaluation.

