# Go Template SSTI > Template injection in Go's `text/template` and `html/template`. There is no generic object-model escape, so impact depends on the methods and functions exposed by the data and `FuncMap` passed in. ## How it works - **Sink.** `template.New(...).Parse(userInput)` followed by `Execute`. "Safe by default" only holds while templates are static (Oligo). - **No universal gadget.** Unlike Jinja2, a Go template cannot walk to arbitrary packages. It can only access fields and call **exported methods** on the passed data, plus registered functions. - **Method confusion (OnSecurity).** Templates can call exported methods with attacker-chosen arguments. If the context object exposes a method that runs commands or touches files, SSTI turns into RCE or file read. The documented example is a web framework context (`echo.Context`) whose `File` method reads arbitrary local files. - **`text/template` vs `html/template`.** They share the same evaluation model. `html/template` adds contextual escaping, which limits XSS, not server-side method calls. `text/template` exposes more directly callable functions. - **Leaks.** `FuncMap` helpers and error channels leak internals (Oligo). In the HTB *Takeoff* box, `text/template` SSTI read environment variables (a validation token and an n8n API key), which led to forged QR tickets and RCE. - **Chained impact.** In CSC 2026's payslip portal, template preview (rendered via wkhtmltopdf) allowed file write. That overwrote a Go source file interpreted at runtime by `yaegi`, giving code exec. ## Testing notes - Arithmetic probes like `{{7*7}}` don't apply, because Go templates have no infix operators. Confirm by referencing fields of the passed data and observing their rendering. - Then enumerate exported methods of the context type. Source access helps a lot, since gadget value depends on the app. ## Defenses - Parse templates only from trusted sources at startup. Pass user data only as `Execute` data. - Keep context structs minimal: no framework context or objects with side-effecting exported methods. Keep `FuncMap` small. ## Related - [[Server-Side Template Injection]] · [[SSTI Detection]] · [[Cross-Site Scripting]] ## Sources - [[raw/onsecurity.io/method-confusion-in-go-sstis-lead-to-rce-4141|Method Confusion in Go SSTIs Lead to RCE]] - [[raw/oligo.security/golang-ssti-safe-by-default-or-vulnerable-by-design-4143|Golang SSTI: Safe by Default or Vulnerable by Design]] - [[raw/blog.intigriti.com/bug-bytes-124-ssti-to-rce-in-go-apps-intigriti-4595|Bug Bytes #124: SSTI to RCE in Go apps]] - [[raw/mindsecurity.org/htb-takeoff-ssti-forged-qr-and-root-via-n8n-15794|HTB Takeoff: SSTI, forged QR and root via n8n]] - [[raw/surajitsen.in/htb-takeoff-go-ssti-and-n8n-privilege-escalation-14026|HTB Takeoff: Go SSTI and n8n privilege escalation]] - [[raw/tranlynhathao.github.io/csc-2026-payslip-portal-go-template-ssti-to-file-write-12656|CSC 2026 Payslip Portal: Go template SSTI to file write]]