SKY-D349 · Security in code
Server-side template injection
A template engine such as Jinja or Velocity turns template text into code and runs it. Server-side template injection (SSTI) happens when outside text becomes part of the template itself instead of a value passed to it. Skylos reports SKY-D349 when request data reaches the template source of render_template_string(), a Jinja from_string() or a Java or PHP equivalent.
- Languages
- Python, Java, PHP
- Quality gate
- counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
- Finding type
- review
Why it matters
Template syntax can reach Python or Java objects. A visitor who sends {{ cycler.__init__.__globals__.os.popen('id').read() }} as their name runs a shell command on the server, with the application's files, keys and network access.
What Skylos flags
from flask import Flask, render_template_string, request app = Flask(__name__) @app.get("/hello")def hello(): name = request.args.get("name", "guest") return render_template_string(f"<h1>Hello {name}!</h1>")What Skylos leaves alone
from flask import Flask, render_template_string, request app = Flask(__name__) @app.get("/hello")def hello(): name = request.args.get("name", "guest") return render_template_string("<h1>Hello {{ name }}!</h1>", name=name)Why Skylos leaves it alone
The template text is a fixed literal and the name is passed as a template variable. Jinja inserts it as escaped text and never reads it as template syntax, so {{ ... }} in the name is shown, not run.
More languages
Java
Flagged
package com.example; import java.io.StringWriter;import org.apache.velocity.VelocityContext;import org.apache.velocity.app.Velocity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class GreetingController { @GetMapping("/greet") public String greet(@RequestParam String template) { VelocityContext context = new VelocityContext(); context.put("site", "Example Shop"); StringWriter out = new StringWriter(); Velocity.evaluate(context, out, "greeting", template); return out.toString(); }}Not flagged
package com.example; import java.io.StringWriter;import org.apache.velocity.VelocityContext;import org.apache.velocity.app.Velocity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class GreetingController { @GetMapping("/greet") public String greet(@RequestParam String name) { VelocityContext context = new VelocityContext(); context.put("name", name); StringWriter out = new StringWriter(); Velocity.evaluate(context, out, "greeting", "Hello, $name!"); return out.toString(); }}Why Skylos leaves it alone
The request value goes into the VelocityContext as data. The template text, the fourth argument of evaluate(), is a fixed string, which is the only argument Skylos checks there.
How Skylos decides
- In Python, finds
render_template_string()andfrom_string()calls. Afrom_string()counts only when its receiver's name containsenvorjinja, as inenv.from_string(src)orjinja2.Environment().from_string(src). - Reads the template source: the first argument or
source=. A string literal is skipped. - Reports CRITICAL when an untrusted source reaches that source text: request data, a route or MCP tool argument,
input()or standard input, directly or through assignments and f-strings. A source made only of environment variables is configuration and is not reported. - Java: request data in the template argument of Velocity
evaluate(), FreeMarkernew Template(name, source, ...),StringTemplateLoader.putTemplate()or GroovyTemplateEngine.createTemplate(). PHP: request data in a Drupal#type => 'inline_template'render array.
How to fix it
Keep templates in files or fixed strings, and pass outside values as template variables. Never build template text from input.
Removed: from flask import Flask, render_template_string, requestAdded: from flask import Flask, render_template, request app = Flask(__name__) @app.get("/hello")def hello(): name = request.args.get("name", "guest")Removed: return render_template_string(f"<h1>Hello {name}!</h1>")Added: return render_template("hello.html", name=name)When it can be wrong
- A tool that lets trusted administrators edit templates through a web form is reported, because the template text comes from request data. Render such templates in Jinja's
SandboxedEnvironmentand keep the form behind authentication. - A
from_string()method on an object whose name happens to containenvis treated as a Jinja environment.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a reviewed call and say why. A bare
# noqadoes not hide HIGH or CRITICAL security findings.Python return env.from_string(source) # skylos: ignore[SKY-D349] admin-only, sandboxedAccept the findings you already have with
skylos baseline ., then scan with--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D349"]turns the rule off for the whole project.