Summary
Datart v1.0.0-rc.3 contains a Server-Side Template Injection (SSTI) flaw in its Freemarker template engine integration, where user-controlled data is processed as executable template code within the SQL script field.
An authenticated attacker who can submit or modify SQL scripts may inject malicious Freemarker syntax that the server evaluates, potentially leading to arbitrary code execution on the Datart server.
Affected context
The vulnerability arises in Datart v1.0.0-rc.3 where SQL scripts or similar query definitions are passed through the Freemarker template engine.
Any deployment that:
- Enables dynamic SQL or query configuration through the UI or APIs, and
- Uses Freemarker to process those SQL scripts, and
- Does not strictly separate untrusted data from template logic
is exposed to this issue when authenticated users can influence the SQL script field.
Exploit preconditions
- Attack surface: Application endpoints (UI or API) that accept or update SQL script definitions processed by Freemarker.
- Required access: Valid authenticated account with permission to create or edit SQL script configurations or similar templated content.
- Trigger point: Server-side rendering of the Freemarker template containing the attacker-controlled SQL script field (e.g., when executing or previewing the query).
- Why exploitation is possible: The application passes user-controlled SQL script content directly into the Freemarker engine as template code instead of treating it as plain data, allowing attackers to inject Freemarker directives and expressions that the server executes.
Why this happens
This vulnerability is caused by treating untrusted or semi-trusted input as executable template code in the Freemarker engine.
Instead of passing only controlled template definitions and binding user input strictly as data-model variables, Datart allows content from the SQL script field—partially or fully under user control—to influence the Freemarker template itself.
This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because user input is incorporated into a server-side template that is interpreted as code, giving attackers a way to execute expressions, access server-side objects, or invoke methods exposed through Freemarker.
Potential impact
- Execution of arbitrary code or expressions on the server within the Freemarker execution context.
- Access to sensitive application data, configuration values, or environment variables available to the template engine.
- Lateral movement by interacting with server-side APIs, file system, or network resources accessible to the Datart process.
- Full compromise of the Datart instance and potential access to connected databases or data sources.
- Use of the compromised server as a foothold for further attacks within the hosting environment.
General mitigation guidance
Effective mitigation focuses on strictly separating template logic from user-controlled content and reducing the power of the template engine:
- Treat all user-provided or user-editable fields (including SQL scripts) as data, not as Freemarker template code.
- Use a fixed, vetted Freemarker template layer and bind user input only via variables in the data model, disallowing user control over directives, macros, or expressions.
- Configure Freemarker in a locked-down mode:
- Restrict or disable access to arbitrary Java objects, reflection, or method invocations.
- Limit template capabilities to simple value interpolation when used with partially untrusted content.
- Apply rigorous server-side validation and allowlisting on templated fields, ensuring only expected syntax or patterns are accepted.
- Follow least-privilege principles for the Datart process and underlying runtime so that, if template misuse occurs, the execution environment has minimal privileges.
How teams detect issues like this
Detection can combine static and dynamic approaches:
- Static analysis & code review:
- Identify all code paths where Freemarker templates are constructed or evaluated.
- Flag any usage where user-supplied strings (e.g., SQL scripts, configuration text) are concatenated into template bodies or passed directly to Freemarker parsing/evaluation APIs.
- Look for generic "evaluate template from string" patterns that do not clearly separate template definitions from user data.
- Configuration and policy checks:
- Verify that Freemarker is configured with restricted object wrapping and disabled or limited access to system-level classes.
- Enforce policies that prohibit dynamic template creation from user input.
- Runtime monitoring:
- Monitor for unusual template errors, template evaluation timeouts, or unexpected method invocation from within templates.
- Use application security tooling (SAST/IAST/DAST) capable of recognizing SSTI patterns and untrusted template evaluation flows.

