Repository navigation
FIX: Detect multi-engine RCE gadgets in SSTIOutputScorer - #3541
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Conversation
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
[P2] Limit the Velocity scan to its template statement. In pyrit/score/true_false/regex/ssti_output_scorer.py, the new #set alternative uses [\s\S]*? with no statement boundary. A harmless response such as #set($count = 10) followed by a new line containing Documentation: ProcessBuilder is therefore classified as a Velocity gadget: the scan passes the closing parenthesis and takes ProcessBuilder from ordinary text. Please constrain the match to the relevant expression and require an actual gadget use rather than a bare class-name substring. Add a negative case with a harmless #set followed by unrelated prose, alongside the genuine gadget cases.
Review based on code inspection; tests were not run. AI-assisted review (GitHub Copilot).
Detect canonical remote code execution gadgets for Apache FreeMarker, Apache Velocity, Twig, and Spring/SpEL in SSTIOutputScorer. Fixes microsoft#3540
c98f4f6 to
9d4b22d
Compare
|
Richard Lundeen (@richlundeen) Thanks for the review! Updated:
|
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.