From 7b8d823b55ecbbc9ecef5718078646aa20350f22 Mon Sep 17 00:00:00 2001 From: ChethanUK Date: Wed, 15 Jul 2026 10:05:47 +0200 Subject: [PATCH] feat(rules): add FreeMarker (.ftl/.ftlh/.ftlx) review support Adds the FreeMarker template extensions to the supported-file-type allowlist and introduces a freemarker.md system rule layer (glob **/*.{ftl,ftlh,ftlx}) covering SSTI (?new()/Execute/ObjectConstructor, ?eval/?api), output escaping vs the ftlh/ftlx auto-escape formats, null/missing-value handling, logic-in-template smells, include/import hygiene, and locale-sensitive formatting. Extends the allowlist and system-rules tests and documents the new mapping in the en/ja/zh pages. Closes #371 --- internal/config/allowlist/allowed_ext_test.go | 6 ++++ .../allowlist/supported_file_types.json | 3 ++ internal/config/rules/rule_docs/freemarker.md | 36 +++++++++++++++++++ internal/config/rules/system_rules.json | 1 + internal/config/rules/system_rules_test.go | 4 +++ pages/src/content/docs/en/review-rules.md | 1 + pages/src/content/docs/ja/review-rules.md | 1 + pages/src/content/docs/zh/review-rules.md | 1 + 8 files changed, 53 insertions(+) create mode 100644 internal/config/rules/rule_docs/freemarker.md diff --git a/internal/config/allowlist/allowed_ext_test.go b/internal/config/allowlist/allowed_ext_test.go index 79b9891a..0d128468 100644 --- a/internal/config/allowlist/allowed_ext_test.go +++ b/internal/config/allowlist/allowed_ext_test.go @@ -22,6 +22,12 @@ func TestIsAllowedExt(t *testing.T) { {".ETS", true}, {".json5", true}, {".JSON5", true}, + {".ftl", true}, + {".FTL", true}, + {".ftlh", true}, + {".FTLH", true}, + {".ftlx", true}, + {".FTLX", true}, {".txt", false}, {".md", false}, {".png", false}, diff --git a/internal/config/allowlist/supported_file_types.json b/internal/config/allowlist/supported_file_types.json index 2c75bded..69b9b416 100644 --- a/internal/config/allowlist/supported_file_types.json +++ b/internal/config/allowlist/supported_file_types.json @@ -43,6 +43,9 @@ ".less", ".html", ".htm", + ".ftl", + ".ftlh", + ".ftlx", ".astro", ".vue", ".svelte", diff --git a/internal/config/rules/rule_docs/freemarker.md b/internal/config/rules/rule_docs/freemarker.md new file mode 100644 index 00000000..07e1d040 --- /dev/null +++ b/internal/config/rules/rule_docs/freemarker.md @@ -0,0 +1,36 @@ +#### Obvious Typos or Spelling Errors +- Spelling errors in macro names, assigned variable names, or user-facing text at their declaration sites; do not report at reference sites +- Typos in `<#assign>`/`<#macro>`/`<#function>` names that surface only at render time (`InvalidReferenceException` / macro not found), or that are silently masked by `!` defaults and `??` guards + +#### Output Escaping and XSS +- Interpolations (`${...}`) that reach HTML without escaping: flag only when auto-escaping is not already active — i.e. the template lacks `<#ftl output_format="HTML">` (FreeMarker 2.3.24+) AND does not use the `.ftlh`/`.ftlx` extension (which auto-activate HTML/XML escaping via `recognize_standard_file_extensions`, on by default since 2.3.24) — and the value is not passed through `?html`/`?url`/`?js_string` appropriate to its sink (HTML body, attribute, URL, JS, CSS) +- Explicit `?no_esc` or `<#noautoesc>` on values that carry user-controlled data — treat as a high-risk escape hatch; flag unless the source is clearly trusted or already sanitized +- Escaping with the wrong context builtin (e.g. `?html` for a value placed inside a URL or inline `