Skip to content

feat: add G708 rule for server-side template injection via text/template - #1597

Merged
ccojocar merged 1 commit into
masterfrom
feat/g708-ssti-detection
Mar 11, 2026
Merged

ccojocar merged 1 commit into
masterfrom
feat/g708-ssti-detection

Conversation

@ccojocar

Copy link
Copy Markdown
Member

feat: add G708 rule for server-side template injection via text/template

Summary

Add taint analysis rule G708 to detect Server-Side Template Injection (SSTI) vulnerabilities when using Go's text/template package.

The text/template package performs no auto-escaping and allows calling any exported method on the data object passed to Execute. This enables:

  • Remote code execution when user input controls the template string
  • Cross-site scripting when tainted data is rendered to HTTP responses

Detection

Covers two attack vectors via taint analysis:

  1. User input flowing into Template.Parse() (SSTI/RCE, critical)
  2. Tainted data passed to Execute/ExecuteTemplate writing to http.ResponseWriter (XSS, high)

CWE-94: Improper Control of Generation of Code (Code Injection)

Sanitizers

  • html.EscapeString, html/template escape functions
  • url.QueryEscape, url.PathEscape
  • strconv numeric conversions

Tests

6 test samples (3 positive, 3 negative) covering:

  • Parse injection, Execute XSS, ExecuteTemplate XSS
  • html/template safe usage, non-HTTP writer, sanitized input

Files Changed

  • analyzers/ssti.go (new) — taint config
  • analyzers/analyzerslist.go — registration
  • cwe/data.go — CWE-94 entry
  • issue/issue.go — G708→CWE-94 mapping
  • testutils/g708_samples.go (new) — test samples
  • analyzers/analyzerslist_test.go, analyzers/analyzers_test.go — tests
  • RULES.md, README.md — docs

Add taint analysis rule G708 to detect SSTI vulnerabilities when using
Go text/template package. Covers two attack vectors:
- User input flowing into Template.Parse() (SSTI/RCE)
- Tainted data passed to Execute/ExecuteTemplate with http.ResponseWriter (XSS)

CWE-94. Includes 6 test samples (3 positive, 3 negative).
@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.00%. Comparing base (8895462) to head (05e0ad6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1597      +/-   ##
==========================================
+ Coverage   80.90%   81.00%   +0.09%     
==========================================
  Files         104      105       +1     
  Lines        9947     9997      +50     
==========================================
+ Hits         8048     8098      +50     
  Misses       1408     1408              
  Partials      491      491              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ccojocar
ccojocar merged commit e7ea237 into master Mar 11, 2026
10 checks passed
@ccojocar
ccojocar deleted the feat/g708-ssti-detection branch March 11, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant