Repository navigation
FIX: Detect multi-engine RCE gadgets in SSTIOutputScorer - #3541
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Conversation
Detect canonical remote code execution gadgets for Apache FreeMarker, Apache Velocity, Twig, and Spring/SpEL in SSTIOutputScorer. Fixes microsoft#3540
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SSTIOutputScorerdetects server-side template injection (SSTI) payloads emitted in LLM responses (OWASP LLM02).While the docstring explicitly states:
The default patterns previously only covered basic arithmetic (
\d+ * \d+) and Python-specific sandbox escapes (__class__), completely missing remote code execution gadgets for non-Python template engines commonly used across enterprise systems (Java, PHP):freemarker.template.utility.Execute,ObjectConstructor,JythonRuntime) via?new().#set($rt=...forName("java.lang.Runtime")),$class.inspect,.getRuntime().exec(),.ProcessBuilder).|filter('system'),|map('system'),|reduce('system')) and_self.env.registerUndefinedFilterCallback.java.lang.Runtime,java.lang.ProcessBuilder, orjavax.script(${T(java.lang.Runtime)...},${T(Runtime)...}).This PR extends
_DEFAULT_PATTERNSinSSTIOutputScorerwith high-precision patterns targeting these canonical exploitation gadgets, while keeping existing patterns and custom overrides completely untouched.Fixes #3540
Tests and Documentation
tests/unit/score/regex/test_ssti_output_scorer.pycovering FreeMarker, Apache Velocity, Twig (including multiline and whitespace variations), and SpEL (both bareT(Runtime)and fully qualified forms).{{ names|filter(v => v > 0) }}), benign type references (${T(Math).min(1, 2)}), and shell variables ($100,$user) are not flagged.score.score_rationale.test_ssti_output_scorer.pypassing cleanly in ~11s.tests/unit/score/regex/test suite passing with zero regressions.ruff checkandruff format.