● Zion Boggan
repos/Cyclops V2/brain/semgrep-rules/template-injection.yaml
zionboggan.com ↗
76 lines · yaml
History for this file →
1
rules:
2
 
3
  - id: cyc-py-jinja-from-string
4
    languages: [python]
5
    severity: ERROR
6
    message: >
7
      render_template_string / Environment.from_string / Template(...) builds a template from a
8
      string; if that string is attacker-controlled it is SSTI -> RCE. IMPACT GATE: Family 1.
9
    metadata:
10
      cwe: ["CWE-1336: Server-Side Template Injection", "CWE-94: Code Injection"]
11
      confidence: HIGH
12
      archetype: [ai-agent-mcp, devops-infra]
13
      impact: rce
14
    patterns:
15
      - pattern-either:
16
          - pattern: render_template_string(...)
17
          - pattern: flask.render_template_string(...)
18
          - pattern: $ENV.from_string(...)
19
          - pattern: jinja2.Template(...)
20
          - pattern: Template(...).render(...)
21
 
22
  - id: cyc-py-mako-tornado
23
    languages: [python]
24
    severity: ERROR
25
    message: >
26
      Mako / Tornado Template built from a tainted string is SSTI -> RCE (Mako allows arbitrary
27
      Python in `<% %>`). IMPACT GATE: Family 1.
28
    metadata:
29
      cwe: ["CWE-1336: Server-Side Template Injection"]
30
      confidence: MEDIUM
31
      archetype: [devops-infra]
32
      impact: rce
33
    patterns:
34
      - pattern-either:
35
          - pattern: mako.template.Template(...)
36
          - pattern: tornado.template.Template(...)
37
 
38
  - id: cyc-js-template-compile
39
    languages: [javascript, typescript]
40
    severity: ERROR
41
    message: >
42
      Handlebars.compile / ejs.render / pug.compile / lodash _.template / nunjucks.renderString on a
43
      tainted template string is SSTI -> RCE in Node. IMPACT GATE: Family 1.
44
    metadata:
45
      cwe: ["CWE-1336: Server-Side Template Injection"]
46
      confidence: HIGH
47
      archetype: [ai-agent-mcp, devops-infra, electron-desktop]
48
      impact: rce
49
    patterns:
50
      - pattern-either:
51
          - pattern: Handlebars.compile(...)
52
          - pattern: Handlebars.precompile(...)
53
          - pattern: ejs.render($T, ...)
54
          - pattern: ejs.compile($T, ...)
55
          - pattern: pug.compile($T, ...)
56
          - pattern: pug.render($T, ...)
57
          - pattern: jade.compile($T, ...)
58
          - pattern: _.template($T, ...)
59
          - pattern: nunjucks.renderString($T, ...)
60
 
61
  - id: cyc-java-template-injection
62
    languages: [java]
63
    severity: ERROR
64
    message: >
65
      Freemarker Template / Velocity.evaluate / Thymeleaf processed from a tainted string is SSTI ->
66
      RCE. IMPACT GATE: Family 1.
67
    metadata:
68
      cwe: ["CWE-1336: Server-Side Template Injection"]
69
      confidence: MEDIUM
70
      archetype: [devops-infra]
71
      impact: rce
72
    patterns:
73
      - pattern-either:
74
          - pattern: new Template($N, $R, ...)
75
          - pattern: Velocity.evaluate(...)
76
          - pattern: $VE.evaluate(...)