Repository navigation
Conversation
The FreeMarker guidance hook peeks at every Reader passed to a Template constructor, but peekMarkableReader fails for readers that don't support mark(). FreeMarker's TemplateCache reads template files through such readers, so Configuration.getTemplate threw an IllegalStateException from the hook. Only peek at markable readers. libFuzzer only uses the needle, so other templates are still guided. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guide all source that FreeMarker parses (templates, ?interpret and ?eval) towards a reference to a canary variable and report a finding when FreeMarker looks it up while rendering. This replaces guiding templates towards an OS command payload. Unlike the OS command payload, this also detects injections in configurations that block ?new (e.g. TemplateClassResolver.SAFER_RESOLVER), into comments and noparse blocks, into strings evaluated with ?eval and with the square bracket tag and interpolation syntax. Findings are reported as FuzzerSecurityIssueHigh. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guide template strings passed to ITemplateEngine.process and expressions that Thymeleaf preprocesses, such as Spring view names, towards a canary variable expression and report a finding when Thymeleaf evaluates it. Updates the OGNL test dependency to 3.4.17, the version Thymeleaf 3.1.7 depends on. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guide all template source that Velocity parses (templates from resource loaders, Velocity.evaluate and the #evaluate directive) towards a canary variable reference and report a finding when Velocity looks up the canary in its context while rendering. The Velocity test dependency updates commons-lang3 from 3.11 to 3.17.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guide all template source that Pebble tokenizes (getTemplate with any loader, getLiteralTemplate, include and extends) towards a canary variable reference and report a finding when Pebble looks up the canary while rendering. This works regardless of the configured method access validator. Covers both the io.pebbletemplates.pebble package and the com.mitchellbosecke.pebble package used before Pebble 3.2. As both share Maven coordinates, the tests fetch Pebble 3.1.6 as a plain jar. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guide all template text that Jinjava parses towards a canary variable reference and report a finding when Jinjava resolves the canary while rendering. With Jinjava's default configuration, this also reports printed values that contain template code, as nested interpretation renders them again. Jinjava 2.8 and later require Java 17, so the tests use 2.7.7 from a list that Renovate doesn't update. Jinjava's Jackson modules are pinned to the version of the intentionally vulnerable jackson-databind, as the current YAML module isn't compatible with it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Right now
TemplateInjectiononly has the FreeMarker hook from #1007. It nudges templates towards${"freemarker.template.utility.Execute"?new()("jazze")}and leaves the reporting to the OS command injection detector. That only works if?newis allowed and the input lands somewhere FreeMarker evaluates${...}. WithTemplateClassResolver.SAFER_RESOLVERthe payload can't run at all, inside a comment it does nothing, and strings passed to?evalnever go through theTemplateconstructor, so they aren't guided.This PR switches to a canary and uses it for FreeMarker, Thymeleaf, Velocity, Pebble and Jinjava. Each engine gets a guidance hook on the method all template source goes through. It adds hints that reference a variable called
jazzerSstiin that engine's syntax, and some of them close a comment, string literal or raw block first, since user input ends up there a lot. A second hook on the engine's variable lookup reports aFuzzerSecurityIssueHighwhen anything asks forjazzerSsti.The canary only gets looked up if fuzzer data was parsed as template code, and regardless of whether the engine's sandbox would have stopped an RCE payload.
FMParser.<init>(all templates,?interpret,?eval)Environment.getVariableITemplateEngine.process,StandardExpressionPreprocessor.preprocess(__${...}__, e.g. Spring view names)IStandardVariableExpressionEvaluator.evaluateRuntimeServices.parse(loaders,Velocity.evaluate,#evaluate)Context.getLexer.tokenizeScopeChain.getTreeParser.<init>JinjavaInterpreter.retraceVariableNote: Jinjava renders printed values a second time if they contain template syntax ("nested interpretation", on by default). So
{{ name }}with a user-controllednameis injectable, and the sanitizer reports it. That's correct, but expect new findings in projects that use Jinjava's defaults. The app-side fix iswithNestedInterpretationEnabled(false).