diff --git a/MODULE.bazel b/MODULE.bazel index a759ec2c1..b5206a675 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -82,12 +82,14 @@ TEST_MAVEN_ARTIFACTS = [ "com.google.truth.extensions:truth-liteproto-extension:1.4.5", "com.google.truth.extensions:truth-proto-extension:1.4.5", "com.google.truth:truth:1.4.5", + "io.pebbletemplates:pebble:4.2.0", "jakarta.el:jakarta.el-api:6.0.1", "jakarta.validation:jakarta.validation-api:3.1.1", "javax.persistence:javax.persistence-api:2.2", "junit:junit:4.13.2", - "ognl:ognl:3.4.10", + "ognl:ognl:3.4.17", "org.apache.commons:commons-jexl:2.1.1", + "org.apache.velocity:velocity-engine-core:2.4.1", "org.assertj:assertj-core:3.27.7", "org.freemarker:freemarker:2.3.34", "org.jacoco:org.jacoco.core:0.8.14", @@ -95,6 +97,16 @@ TEST_MAVEN_ARTIFACTS = [ "org.mvel:mvel2:2.5.2.Final", "org.openjdk.jmh:jmh-core:1.37", "org.openjdk.jmh:jmh-generator-annprocess:1.37", + "org.slf4j:slf4j-api:2.0.20", # Runtime dependency of @pebble_legacy_jar + "org.thymeleaf:thymeleaf:3.1.7.RELEASE", + "org.unbescape:unbescape:1.1.8.RELEASE", # Runtime dependency of @pebble_legacy_jar +] + +# Dependencies used to support Jazzer's own tests whose later versions require a newer Java version +# than Jazzer's tests run on. Not updated by Renovate. +TEST_MAVEN_ARTIFACTS_JAVA8 = [ + # keep sorted + "com.hubspot.jinjava:jinjava:2.7.7", # 2.8 and later require Java 17 ] # **WARNING**: These Maven dependencies may have known vulnerabilities that Jazzer is supposed to @@ -104,9 +116,12 @@ VULNERABLE_TEST_MAVEN_ARTIFACTS = [ # keep sorted "com.alibaba:fastjson:1.2.75", "com.beust:klaxon:5.5", + "com.fasterxml.jackson.core:jackson-annotations:2.12.1", # Must match jackson-databind "com.fasterxml.jackson.core:jackson-core:2.12.1", "com.fasterxml.jackson.core:jackson-databind:2.12.1", "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.12.1", + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.1", # Must match jackson-databind (used by Jinjava) + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.1", # Must match jackson-databind (used by Jinjava) "com.h2database:h2:2.1.212", "com.mikesamuel:json-sanitizer:1.2.1", "com.unboundid:unboundid-ldapsdk:6.0.3", @@ -161,7 +176,7 @@ maven.override( group = coordinate.split(":")[0], version = coordinate.split(":")[2], ) - for coordinate in TEST_MAVEN_ARTIFACTS + TEST_MAVEN_ARTIFACTS_FIXED + VULNERABLE_TEST_MAVEN_ARTIFACTS + for coordinate in TEST_MAVEN_ARTIFACTS + TEST_MAVEN_ARTIFACTS_FIXED + TEST_MAVEN_ARTIFACTS_JAVA8 + VULNERABLE_TEST_MAVEN_ARTIFACTS ] maven.install( @@ -290,6 +305,14 @@ http_jar( url = "https://repo1.maven.org/maven2/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar", ) +# Pebble releases before 3.2 use the com.mitchellbosecke.pebble package. They share their Maven +# coordinates with the current release, so the last such release is fetched as a plain jar. +http_jar( + name = "pebble_legacy_jar", + sha256 = "e9ff32ac26759798f440cd3241b2d398fc041a9d6d024b3c0a8d3fde38ca4927", + url = "https://repo1.maven.org/maven2/io/pebbletemplates/pebble/3.1.6/pebble-3.1.6.jar", +) + http_jar( name = "clojure_core_specs_alpha_jar", sha256 = "06eea8c070bbe45c158567e443439681bc8c46e9123414f81bfa32ba42d6cbc8", diff --git a/maven_install.json b/maven_install.json index 1791202f0..035caca73 100755 --- a/maven_install.json +++ b/maven_install.json @@ -3,9 +3,12 @@ "__INPUT_ARTIFACTS_HASH": { "com.alibaba:fastjson": 1817768268, "com.beust:klaxon": 338175087, + "com.fasterxml.jackson.core:jackson-annotations": -1579035903, "com.fasterxml.jackson.core:jackson-core": 723971516, "com.fasterxml.jackson.core:jackson-databind": 1657199092, "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor": 524096757, + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": 1502968880, + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": 1379952144, "com.github.jsqlparser:jsqlparser": -85077207, "com.google.code.findbugs:jsr305": 495355163, "com.google.code.gson:gson": -2119346406, @@ -17,9 +20,11 @@ "com.google.truth.extensions:truth-proto-extension": -362698248, "com.google.truth:truth": -252459521, "com.h2database:h2": -342409218, + "com.hubspot.jinjava:jinjava": -412124955, "com.mikesamuel:json-sanitizer": -1840608028, "com.unboundid:unboundid-ldapsdk": -1036201052, "io.github.classgraph:classgraph": -1461122240, + "io.pebbletemplates:pebble": 1545301986, "jakarta.el:jakarta.el-api": 171705473, "jakarta.validation:jakarta.validation-api": -186402049, "javax.el:javax.el-api": -2068634010, @@ -29,12 +34,13 @@ "junit:junit": -652553691, "net.bytebuddy:byte-buddy-agent": -1065427230, "net.jodah:typetools": 1676712931, - "ognl:ognl": 2052829285, + "ognl:ognl": -2009417364, "org.apache.commons:commons-imaging": -1220018277, "org.apache.commons:commons-jexl": 813523241, "org.apache.commons:commons-text": -1377889016, "org.apache.logging.log4j:log4j-api": -1645212456, "org.apache.logging.log4j:log4j-core": -521037129, + "org.apache.velocity:velocity-engine-core": 890011617, "org.apache.xmlgraphics:batik-anim": 1816317577, "org.apache.xmlgraphics:batik-awt-util": -243562583, "org.apache.xmlgraphics:batik-bridge": 2092183121, @@ -69,21 +75,28 @@ "org.ow2.asm:asm": 1206815935, "org.ow2.asm:asm-commons": 1607605466, "org.ow2.asm:asm-tree": -1365652182, + "org.slf4j:slf4j-api": -1656080080, "org.springframework.cloud:spring-cloud-function-context": 191971828, "org.springframework.cloud:spring-cloud-function-core": -1854900684, "org.springframework:spring-messaging": 328550982, + "org.thymeleaf:thymeleaf": 2089867911, + "org.unbescape:unbescape": -404718364, "repositories": -1949687017 }, "__RESOLVED_ARTIFACTS_HASH": { + "ch.obermuhlner:big-math": -315761188, "com.alibaba:fastjson": -46287576, "com.beust:klaxon": 692624817, "com.fasterxml.jackson.core:jackson-annotations": -1954247452, "com.fasterxml.jackson.core:jackson-core": 1941349742, "com.fasterxml.jackson.core:jackson-databind": 150569930, "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor": -541232238, + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": 821503392, + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": 1851013445, "com.fasterxml:classmate": -1940972411, "com.github.jsqlparser:jsqlparser": 130367484, "com.google.auto.value:auto-value-annotations": 641018093, + "com.google.code.findbugs:annotations": 139434451, "com.google.code.findbugs:jsr305": 870839855, "com.google.code.gson:gson": -2092238571, "com.google.errorprone:error_prone_annotations": 213918278, @@ -92,16 +105,22 @@ "com.google.guava:listenablefuture": 1079558157, "com.google.j2objc:j2objc-annotations": -1008747351, "com.google.protobuf:protobuf-java": 1555861032, + "com.google.re2j:re2j": -1278890506, "com.google.truth.extensions:truth-java8-extension": 1186293162, "com.google.truth.extensions:truth-liteproto-extension": 2044092816, "com.google.truth.extensions:truth-proto-extension": -194966365, "com.google.truth:truth": -1359112801, + "com.googlecode.java-ipv6:java-ipv6": -1927917311, "com.h2database:h2": 475457751, + "com.hubspot.immutables:immutables-exceptions": -1773321844, + "com.hubspot.jinjava:jinjava": 890803315, "com.mikesamuel:json-sanitizer": 1715785415, "com.unboundid:unboundid-ldapsdk": -911278373, "commons-io:commons-io": -666806869, "commons-logging:commons-logging": -2131529292, + "commons-net:commons-net": 469450022, "io.github.classgraph:classgraph": 1394841189, + "io.pebbletemplates:pebble": 2056335635, "io.projectreactor:reactor-core": 1200961785, "jakarta.el:jakarta.el-api": -78449182, "jakarta.validation:jakarta.validation-api": -1708329466, @@ -116,14 +135,15 @@ "net.bytebuddy:byte-buddy-agent": 1350687472, "net.jodah:typetools": -1869254284, "net.sf.jopt-simple:jopt-simple": -1677351973, - "ognl:ognl": 1948208138, + "ognl:ognl": 283904971, "org.apache.commons:commons-imaging": -1061935142, "org.apache.commons:commons-jexl": -336898056, - "org.apache.commons:commons-lang3": 510221269, + "org.apache.commons:commons-lang3": 1415496185, "org.apache.commons:commons-math3": -1383243934, - "org.apache.commons:commons-text": -1906378778, + "org.apache.commons:commons-text": 201188438, "org.apache.logging.log4j:log4j-api": -1814016300, "org.apache.logging.log4j:log4j-core": -938085786, + "org.apache.velocity:velocity-engine-core": -987000962, "org.apache.xmlgraphics:batik-anim": -2098269098, "org.apache.xmlgraphics:batik-awt-util": 462854305, "org.apache.xmlgraphics:batik-bridge": -467983036, @@ -144,12 +164,13 @@ "org.apache.xmlgraphics:xmlgraphics-commons": -1151421338, "org.apiguardian:apiguardian-api": 1279798469, "org.assertj:assertj-core": -313838767, + "org.attoparser:attoparser": -672082190, "org.freemarker:freemarker": -1834118444, "org.glassfish:javax.el": 631698101, "org.hamcrest:hamcrest-core": 649657847, "org.hibernate:hibernate-validator": 1029552718, "org.jacoco:org.jacoco.core": -1495664227, - "org.javassist:javassist": 1095674094, + "org.javassist:javassist": 940731595, "org.jboss.logging:jboss-logging": 197007362, "org.jetbrains.kotlin:kotlin-reflect": -1292560044, "org.jetbrains.kotlin:kotlin-stdlib": 89537549, @@ -174,6 +195,7 @@ "org.ow2.asm:asm-commons": 33716409, "org.ow2.asm:asm-tree": -1173653421, "org.reactivestreams:reactive-streams": -164947187, + "org.slf4j:slf4j-api": -736053657, "org.springframework.boot:spring-boot": 2047288717, "org.springframework.boot:spring-boot-autoconfigure": 1133681824, "org.springframework.cloud:spring-cloud-function-context": -1370136668, @@ -185,6 +207,9 @@ "org.springframework:spring-expression": 2025602550, "org.springframework:spring-jcl": -962998374, "org.springframework:spring-messaging": -1462145322, + "org.thymeleaf:thymeleaf": -400591794, + "org.unbescape:unbescape": 1014161983, + "org.yaml:snakeyaml": -87186372, "xalan:serializer": 1423473969, "xalan:xalan": 393750935, "xml-apis:xml-apis": 632917632, @@ -194,6 +219,12 @@ "com.google.j2objc:j2objc-annotations:2.8": "com.google.j2objc:j2objc-annotations:3.1" }, "artifacts": { + "ch.obermuhlner:big-math": { + "shasums": { + "jar": "e7673cb7d116e4de2a42a483f1f16d91a19228a0a6b3e167cff897934ed68ef6" + }, + "version": "2.0.0" + }, "com.alibaba:fastjson": { "shasums": { "jar": "9ba58edc4473ee813eca9b8dd4a066378023b7b7e2e605823c07a16abfade189" @@ -230,6 +261,18 @@ }, "version": "2.12.1" }, + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": { + "shasums": { + "jar": "58c9db6c379a7ab0bd4f5722a0695b812fdd698d073a8aaa24fae74d3b802f7a" + }, + "version": "2.12.1" + }, + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": { + "shasums": { + "jar": "d19fdd14c35bc2501657dc14374106b5c5593ee9e1319737a371bd49ad6d3d7b" + }, + "version": "2.12.1" + }, "com.fasterxml:classmate": { "shasums": { "jar": "610d23db8ece7268e93930562d89b91546c79fc80f3966baf433e5e93110b118" @@ -248,6 +291,12 @@ }, "version": "1.11.0" }, + "com.google.code.findbugs:annotations": { + "shasums": { + "jar": "6b47ff0a6de0ce17cbedc3abb0828ca5bce3009d53ea47b3723ff023c4742f79" + }, + "version": "3.0.1" + }, "com.google.code.findbugs:jsr305": { "shasums": { "jar": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7" @@ -296,6 +345,12 @@ }, "version": "4.32.0" }, + "com.google.re2j:re2j": { + "shasums": { + "jar": "e9dc705fd4c570344b54a7146b2e3a819cdc271a29793f4acc1a93b56a388e59" + }, + "version": "1.2" + }, "com.google.truth.extensions:truth-java8-extension": { "shasums": { "jar": "917671963d545be65c8f4e821e8a2794d0f24ffd1d33187a1c022a2e21556d2e" @@ -320,12 +375,30 @@ }, "version": "1.4.5" }, + "com.googlecode.java-ipv6:java-ipv6": { + "shasums": { + "jar": "37cf71baf707041cb494834c559ad12b631f5c7747c804ec19598bc0e0f01162" + }, + "version": "0.17" + }, "com.h2database:h2": { "shasums": { "jar": "db9284c6ff9bf3bc0087851edbd34563f1180df3ae87c67c5fe2203c0e67a536" }, "version": "2.1.212" }, + "com.hubspot.immutables:immutables-exceptions": { + "shasums": { + "jar": "6f5ea03fbaf1a3852034f25e6ff55549995b0ad1aba19c569d2f925d8dfb8992" + }, + "version": "1.9" + }, + "com.hubspot.jinjava:jinjava": { + "shasums": { + "jar": "a86d707307baaa5b33a5bfae40132bb8f5acdd4bc7bb365f7bac3030a74d8486" + }, + "version": "2.7.7" + }, "com.mikesamuel:json-sanitizer": { "shasums": { "jar": "0f7d702ba2cdfebac1d4f1154d4b107f508d5920c268263087a5f4b80ddb7446" @@ -350,12 +423,24 @@ }, "version": "1.1.1" }, + "commons-net:commons-net": { + "shasums": { + "jar": "e3c1566f821b84489308cd933f57e8c00dd8714dc96b898bef844386510d3461" + }, + "version": "3.9.0" + }, "io.github.classgraph:classgraph": { "shasums": { "jar": "6e564e29cec95a392268a609f09071d56199383d906ac70e91753a7998d1a3e8" }, "version": "4.8.184" }, + "io.pebbletemplates:pebble": { + "shasums": { + "jar": "01835bac1de7fba72047dda09c2f8451d4d7f300186f7dcc7bda08c47bf97db6" + }, + "version": "4.2.0" + }, "io.projectreactor:reactor-core": { "shasums": { "jar": "12ff3eae092bf07f6651a93b9292a87fbee7f5b9ad4c9cc01189b1a4f0979973" @@ -442,9 +527,9 @@ }, "ognl:ognl": { "shasums": { - "jar": "c69d04d378394ca0cc6a9dcde629555e34a1fa9540ac8ca5d07128d5ed52f491" + "jar": "9929910f6352a6bbc188e945ca88342964b55a1b956296bf65df55565b45f0e8" }, - "version": "3.4.10" + "version": "3.4.17" }, "org.apache.commons:commons-imaging": { "shasums": { @@ -460,9 +545,9 @@ }, "org.apache.commons:commons-lang3": { "shasums": { - "jar": "4ee380259c068d1dbe9e84ab52186f2acd65de067ec09beff731fca1697fdb16" + "jar": "6ee731df5c8e5a2976a1ca023b6bb320ea8d3539fbe64c8a1d5cb765127c33b4" }, - "version": "3.11" + "version": "3.17.0" }, "org.apache.commons:commons-math3": { "shasums": { @@ -488,6 +573,12 @@ }, "version": "2.14.1" }, + "org.apache.velocity:velocity-engine-core": { + "shasums": { + "jar": "1c19157d1171d560088e485be97c93a7a2f7e9f56e517f0a30273c5c39df6231" + }, + "version": "2.4.1" + }, "org.apache.xmlgraphics:batik-anim": { "shasums": { "jar": "a1953099e04c202ee32d8e13912326d15cc488538051c691e897b0b7d2523b40" @@ -608,6 +699,12 @@ }, "version": "3.27.7" }, + "org.attoparser:attoparser": { + "shasums": { + "jar": "8e85ebd7cd6a3e894c8745fe30779943c1d0a6214201f9a053238fc82e9893fa" + }, + "version": "2.0.10.RELEASE" + }, "org.freemarker:freemarker": { "shasums": { "jar": "9a9fb91cd64199232eb1ca9766148a5d30ef8944be5fac051018f96c70c8f6a3" @@ -640,9 +737,9 @@ }, "org.javassist:javassist": { "shasums": { - "jar": "eba37290994b5e4868f3af98ff113f6244a6b099385d9ad46881307d3cb01aaf" + "jar": "1620478adc5f4d2eccd356e59513c270f1508bed53ce75deffb3107b7b43db2c" }, - "version": "3.30.2-GA" + "version": "3.33.0-GA" }, "org.jboss.logging:jboss-logging": { "shasums": { @@ -788,6 +885,12 @@ }, "version": "1.0.3" }, + "org.slf4j:slf4j-api": { + "shasums": { + "jar": "7e1446499b359675d8aabe6af2de86b85e72ae8a2a932c0b40d0e5ba57097439" + }, + "version": "2.0.20" + }, "org.springframework.boot:spring-boot": { "shasums": { "jar": "fca95eb7a9547b89f9722010eceae9604a098dfbfb4cf37f80ed16354bcfdaba" @@ -854,6 +957,24 @@ }, "version": "6.1.4" }, + "org.thymeleaf:thymeleaf": { + "shasums": { + "jar": "3b10820d4b81f227c26a77426b376197fe2d2572dbae8007a7c48227a3cb5c02" + }, + "version": "3.1.7.RELEASE" + }, + "org.unbescape:unbescape": { + "shasums": { + "jar": "b02195dca9c3b83dcc74234f25ed7eedceacf8f75904f984bc54fc4bb0e926d0" + }, + "version": "1.1.8.RELEASE" + }, + "org.yaml:snakeyaml": { + "shasums": { + "jar": "7e7cce6740ed705bfdfaac7b442c1375d2986d2f2935936a5bd40c14e18fd736" + }, + "version": "1.27" + }, "xalan:serializer": { "shasums": { "jar": "e8f5b4340d3b12a0cfa44ac2db4be4e0639e479ae847df04c4ed8b521734bb4a" @@ -892,6 +1013,18 @@ "com.fasterxml.jackson.core:jackson-core", "com.fasterxml.jackson.core:jackson-databind" ], + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": [ + "com.fasterxml.jackson.core:jackson-core", + "com.fasterxml.jackson.core:jackson-databind", + "org.yaml:snakeyaml" + ], + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": [ + "com.fasterxml.jackson.core:jackson-core", + "com.fasterxml.jackson.core:jackson-databind" + ], + "com.google.code.findbugs:annotations": [ + "com.google.code.findbugs:jsr305" + ], "com.google.code.gson:gson": [ "com.google.errorprone:error_prone_annotations" ], @@ -929,6 +1062,31 @@ "org.jspecify:jspecify", "org.ow2.asm:asm" ], + "com.hubspot.immutables:immutables-exceptions": [ + "com.google.code.findbugs:annotations", + "com.google.guava:guava" + ], + "com.hubspot.jinjava:jinjava": [ + "ch.obermuhlner:big-math", + "com.fasterxml.jackson.core:jackson-annotations", + "com.fasterxml.jackson.core:jackson-core", + "com.fasterxml.jackson.core:jackson-databind", + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8", + "com.google.code.findbugs:annotations", + "com.google.guava:guava", + "com.google.re2j:re2j", + "com.googlecode.java-ipv6:java-ipv6", + "com.hubspot.immutables:immutables-exceptions", + "commons-net:commons-net", + "org.apache.commons:commons-lang3", + "org.javassist:javassist", + "org.slf4j:slf4j-api" + ], + "io.pebbletemplates:pebble": [ + "org.slf4j:slf4j-api", + "org.unbescape:unbescape" + ], "io.projectreactor:reactor-core": [ "org.reactivestreams:reactive-streams" ], @@ -950,6 +1108,10 @@ "org.apache.logging.log4j:log4j-core": [ "org.apache.logging.log4j:log4j-api" ], + "org.apache.velocity:velocity-engine-core": [ + "org.apache.commons:commons-lang3", + "org.slf4j:slf4j-api" + ], "org.apache.xmlgraphics:batik-anim": [ "org.apache.xmlgraphics:batik-awt-util", "org.apache.xmlgraphics:batik-css", @@ -1181,6 +1343,12 @@ "org.springframework:spring-beans", "org.springframework:spring-core" ], + "org.thymeleaf:thymeleaf": [ + "ognl:ognl", + "org.attoparser:attoparser", + "org.slf4j:slf4j-api", + "org.unbescape:unbescape" + ], "xalan:serializer": [ "xml-apis:xml-apis" ], @@ -1189,6 +1357,11 @@ ] }, "packages": { + "ch.obermuhlner:big-math": [ + "ch.obermuhlner.math.big", + "ch.obermuhlner.math.big.internal", + "ch.obermuhlner.math.big.stream" + ], "com.alibaba:fastjson": [ "com.alibaba.fastjson", "com.alibaba.fastjson.annotation", @@ -1259,6 +1432,14 @@ "com.fasterxml.jackson.dataformat.cbor", "com.fasterxml.jackson.dataformat.cbor.databind" ], + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": [ + "com.fasterxml.jackson.dataformat.yaml", + "com.fasterxml.jackson.dataformat.yaml.snakeyaml.error", + "com.fasterxml.jackson.dataformat.yaml.util" + ], + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": [ + "com.fasterxml.jackson.datatype.jdk8" + ], "com.fasterxml:classmate": [ "com.fasterxml.classmate", "com.fasterxml.classmate.members", @@ -1314,6 +1495,14 @@ "com.google.auto.value.extension.serializable", "com.google.auto.value.extension.toprettystring" ], + "com.google.code.findbugs:annotations": [ + "edu.umd.cs.findbugs", + "edu.umd.cs.findbugs.annotations", + "javax.annotation", + "javax.annotation.concurrent", + "javax.annotation.meta", + "net.jcip.annotations" + ], "com.google.code.findbugs:jsr305": [ "javax.annotation", "javax.annotation.concurrent", @@ -1364,6 +1553,9 @@ "com.google.protobuf", "com.google.protobuf.compiler" ], + "com.google.re2j:re2j": [ + "com.google.re2j" + ], "com.google.truth.extensions:truth-liteproto-extension": [ "com.google.common.truth.extensions.proto" ], @@ -1373,6 +1565,9 @@ "com.google.truth:truth": [ "com.google.common.truth" ], + "com.googlecode.java-ipv6:java-ipv6": [ + "com.googlecode.ipv6" + ], "com.h2database:h2": [ "org.h2", "org.h2.api", @@ -1433,6 +1628,56 @@ "org.h2.value", "org.h2.value.lob" ], + "com.hubspot.immutables:immutables-exceptions": [ + "com.hubspot.immutables.validation" + ], + "com.hubspot.jinjava:jinjava": [ + "com.hubspot.jinjava", + "com.hubspot.jinjava.doc", + "com.hubspot.jinjava.doc.annotations", + "com.hubspot.jinjava.el", + "com.hubspot.jinjava.el.ext", + "com.hubspot.jinjava.el.ext.eager", + "com.hubspot.jinjava.features", + "com.hubspot.jinjava.interpret", + "com.hubspot.jinjava.interpret.errorcategory", + "com.hubspot.jinjava.lib", + "com.hubspot.jinjava.lib.expression", + "com.hubspot.jinjava.lib.exptest", + "com.hubspot.jinjava.lib.filter", + "com.hubspot.jinjava.lib.filter.time", + "com.hubspot.jinjava.lib.fn", + "com.hubspot.jinjava.lib.fn.eager", + "com.hubspot.jinjava.lib.tag", + "com.hubspot.jinjava.lib.tag.eager", + "com.hubspot.jinjava.lib.tag.eager.importing", + "com.hubspot.jinjava.loader", + "com.hubspot.jinjava.mode", + "com.hubspot.jinjava.objects", + "com.hubspot.jinjava.objects.collections", + "com.hubspot.jinjava.objects.date", + "com.hubspot.jinjava.objects.serialization", + "com.hubspot.jinjava.random", + "com.hubspot.jinjava.tree", + "com.hubspot.jinjava.tree.output", + "com.hubspot.jinjava.tree.parse", + "com.hubspot.jinjava.util", + "jinjava.de.odysseus.el", + "jinjava.de.odysseus.el.misc", + "jinjava.de.odysseus.el.tree", + "jinjava.de.odysseus.el.tree.impl", + "jinjava.de.odysseus.el.tree.impl.ast", + "jinjava.de.odysseus.el.util", + "jinjava.javax.el", + "jinjava.org.jsoup", + "jinjava.org.jsoup.helper", + "jinjava.org.jsoup.internal", + "jinjava.org.jsoup.nodes", + "jinjava.org.jsoup.parser", + "jinjava.org.jsoup.safety", + "jinjava.org.jsoup.select", + "org.jsoup.helper" + ], "com.mikesamuel:json-sanitizer": [ "com.google.json" ], @@ -1479,6 +1724,28 @@ "org.apache.commons.logging", "org.apache.commons.logging.impl" ], + "commons-net:commons-net": [ + "org.apache.commons.net", + "org.apache.commons.net.bsd", + "org.apache.commons.net.chargen", + "org.apache.commons.net.daytime", + "org.apache.commons.net.discard", + "org.apache.commons.net.echo", + "org.apache.commons.net.finger", + "org.apache.commons.net.ftp", + "org.apache.commons.net.ftp.parser", + "org.apache.commons.net.imap", + "org.apache.commons.net.io", + "org.apache.commons.net.nntp", + "org.apache.commons.net.ntp", + "org.apache.commons.net.pop3", + "org.apache.commons.net.smtp", + "org.apache.commons.net.telnet", + "org.apache.commons.net.tftp", + "org.apache.commons.net.time", + "org.apache.commons.net.util", + "org.apache.commons.net.whois" + ], "io.github.classgraph:classgraph": [ "io.github.classgraph", "nonapi.io.github.classgraph.classloaderhandler", @@ -1494,6 +1761,31 @@ "nonapi.io.github.classgraph.types", "nonapi.io.github.classgraph.utils" ], + "io.pebbletemplates:pebble": [ + "io.pebbletemplates.pebble", + "io.pebbletemplates.pebble.attributes", + "io.pebbletemplates.pebble.attributes.methodaccess", + "io.pebbletemplates.pebble.cache", + "io.pebbletemplates.pebble.cache.tag", + "io.pebbletemplates.pebble.cache.template", + "io.pebbletemplates.pebble.error", + "io.pebbletemplates.pebble.extension", + "io.pebbletemplates.pebble.extension.core", + "io.pebbletemplates.pebble.extension.debug", + "io.pebbletemplates.pebble.extension.escaper", + "io.pebbletemplates.pebble.extension.i18n", + "io.pebbletemplates.pebble.extension.writer", + "io.pebbletemplates.pebble.lexer", + "io.pebbletemplates.pebble.loader", + "io.pebbletemplates.pebble.node", + "io.pebbletemplates.pebble.node.expression", + "io.pebbletemplates.pebble.node.fornode", + "io.pebbletemplates.pebble.operator", + "io.pebbletemplates.pebble.parser", + "io.pebbletemplates.pebble.template", + "io.pebbletemplates.pebble.tokenParser", + "io.pebbletemplates.pebble.utils" + ], "io.projectreactor:reactor-core": [ "reactor.adapter", "reactor.core", @@ -1719,7 +2011,8 @@ "org.apache.commons.lang3.text", "org.apache.commons.lang3.text.translate", "org.apache.commons.lang3.time", - "org.apache.commons.lang3.tuple" + "org.apache.commons.lang3.tuple", + "org.apache.commons.lang3.util" ], "org.apache.commons:commons-math3": [ "org.apache.commons.math3", @@ -1870,6 +2163,26 @@ "org.apache.logging.log4j.core.util", "org.apache.logging.log4j.core.util.datetime" ], + "org.apache.velocity:velocity-engine-core": [ + "org.apache.velocity", + "org.apache.velocity.app", + "org.apache.velocity.app.event", + "org.apache.velocity.app.event.implement", + "org.apache.velocity.context", + "org.apache.velocity.exception", + "org.apache.velocity.io", + "org.apache.velocity.runtime", + "org.apache.velocity.runtime.directive", + "org.apache.velocity.runtime.directive.contrib", + "org.apache.velocity.runtime.parser", + "org.apache.velocity.runtime.parser.node", + "org.apache.velocity.runtime.resource", + "org.apache.velocity.runtime.resource.loader", + "org.apache.velocity.runtime.resource.util", + "org.apache.velocity.runtime.visitor", + "org.apache.velocity.util", + "org.apache.velocity.util.introspection" + ], "org.apache.xmlgraphics:batik-anim": [ "org.apache.batik.anim", "org.apache.batik.anim.dom", @@ -2034,6 +2347,20 @@ "org.assertj.core.util.introspection", "org.assertj.core.util.xml" ], + "org.attoparser:attoparser": [ + "org.attoparser", + "org.attoparser.config", + "org.attoparser.discard", + "org.attoparser.dom", + "org.attoparser.duplicate", + "org.attoparser.minimize", + "org.attoparser.output", + "org.attoparser.prettyhtml", + "org.attoparser.select", + "org.attoparser.simple", + "org.attoparser.trace", + "org.attoparser.util" + ], "org.freemarker:freemarker": [ "freemarker.cache", "freemarker.core", @@ -2151,9 +2478,6 @@ "javassist.runtime", "javassist.scopedpool", "javassist.tools", - "javassist.tools.reflect", - "javassist.tools.rmi", - "javassist.tools.web", "javassist.util", "javassist.util.proxy" ], @@ -2486,6 +2810,12 @@ "org.reactivestreams:reactive-streams": [ "org.reactivestreams" ], + "org.slf4j:slf4j-api": [ + "org.slf4j", + "org.slf4j.event", + "org.slf4j.helpers", + "org.slf4j.spi" + ], "org.springframework.boot:spring-boot": [ "org.springframework.boot", "org.springframework.boot.admin", @@ -2875,6 +3205,83 @@ "org.springframework.messaging.tcp", "org.springframework.messaging.tcp.reactor" ], + "org.thymeleaf:thymeleaf": [ + "org.thymeleaf", + "org.thymeleaf.cache", + "org.thymeleaf.context", + "org.thymeleaf.dialect", + "org.thymeleaf.engine", + "org.thymeleaf.exceptions", + "org.thymeleaf.expression", + "org.thymeleaf.inline", + "org.thymeleaf.linkbuilder", + "org.thymeleaf.messageresolver", + "org.thymeleaf.model", + "org.thymeleaf.postprocessor", + "org.thymeleaf.preprocessor", + "org.thymeleaf.processor", + "org.thymeleaf.processor.cdatasection", + "org.thymeleaf.processor.comment", + "org.thymeleaf.processor.doctype", + "org.thymeleaf.processor.element", + "org.thymeleaf.processor.processinginstruction", + "org.thymeleaf.processor.templateboundaries", + "org.thymeleaf.processor.text", + "org.thymeleaf.processor.xmldeclaration", + "org.thymeleaf.standard", + "org.thymeleaf.standard.expression", + "org.thymeleaf.standard.inline", + "org.thymeleaf.standard.processor", + "org.thymeleaf.standard.serializer", + "org.thymeleaf.standard.util", + "org.thymeleaf.templatemode", + "org.thymeleaf.templateparser", + "org.thymeleaf.templateparser.markup", + "org.thymeleaf.templateparser.markup.decoupled", + "org.thymeleaf.templateparser.raw", + "org.thymeleaf.templateparser.reader", + "org.thymeleaf.templateparser.text", + "org.thymeleaf.templateresolver", + "org.thymeleaf.templateresource", + "org.thymeleaf.util", + "org.thymeleaf.util.temporal", + "org.thymeleaf.web", + "org.thymeleaf.web.servlet" + ], + "org.unbescape:unbescape": [ + "org.unbescape", + "org.unbescape.css", + "org.unbescape.csv", + "org.unbescape.html", + "org.unbescape.java", + "org.unbescape.javascript", + "org.unbescape.json", + "org.unbescape.properties", + "org.unbescape.uri", + "org.unbescape.xml" + ], + "org.yaml:snakeyaml": [ + "org.yaml.snakeyaml", + "org.yaml.snakeyaml.composer", + "org.yaml.snakeyaml.constructor", + "org.yaml.snakeyaml.emitter", + "org.yaml.snakeyaml.env", + "org.yaml.snakeyaml.error", + "org.yaml.snakeyaml.events", + "org.yaml.snakeyaml.extensions.compactnotation", + "org.yaml.snakeyaml.external.biz.base64Coder", + "org.yaml.snakeyaml.external.com.google.gdata.util.common.base", + "org.yaml.snakeyaml.introspector", + "org.yaml.snakeyaml.nodes", + "org.yaml.snakeyaml.parser", + "org.yaml.snakeyaml.reader", + "org.yaml.snakeyaml.representer", + "org.yaml.snakeyaml.resolver", + "org.yaml.snakeyaml.scanner", + "org.yaml.snakeyaml.serializer", + "org.yaml.snakeyaml.tokens", + "org.yaml.snakeyaml.util" + ], "xalan:serializer": [ "org.apache.xml.serializer", "org.apache.xml.serializer.dom3", @@ -2971,15 +3378,19 @@ }, "repositories": { "https://repo1.maven.org/maven2/": [ + "ch.obermuhlner:big-math", "com.alibaba:fastjson", "com.beust:klaxon", "com.fasterxml.jackson.core:jackson-annotations", "com.fasterxml.jackson.core:jackson-core", "com.fasterxml.jackson.core:jackson-databind", "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor", + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8", "com.fasterxml:classmate", "com.github.jsqlparser:jsqlparser", "com.google.auto.value:auto-value-annotations", + "com.google.code.findbugs:annotations", "com.google.code.findbugs:jsr305", "com.google.code.gson:gson", "com.google.errorprone:error_prone_annotations", @@ -2988,16 +3399,22 @@ "com.google.guava:listenablefuture", "com.google.j2objc:j2objc-annotations", "com.google.protobuf:protobuf-java", + "com.google.re2j:re2j", "com.google.truth.extensions:truth-java8-extension", "com.google.truth.extensions:truth-liteproto-extension", "com.google.truth.extensions:truth-proto-extension", "com.google.truth:truth", + "com.googlecode.java-ipv6:java-ipv6", "com.h2database:h2", + "com.hubspot.immutables:immutables-exceptions", + "com.hubspot.jinjava:jinjava", "com.mikesamuel:json-sanitizer", "com.unboundid:unboundid-ldapsdk", "commons-io:commons-io", "commons-logging:commons-logging", + "commons-net:commons-net", "io.github.classgraph:classgraph", + "io.pebbletemplates:pebble", "io.projectreactor:reactor-core", "jakarta.el:jakarta.el-api", "jakarta.validation:jakarta.validation-api", @@ -3020,6 +3437,7 @@ "org.apache.commons:commons-text", "org.apache.logging.log4j:log4j-api", "org.apache.logging.log4j:log4j-core", + "org.apache.velocity:velocity-engine-core", "org.apache.xmlgraphics:batik-anim", "org.apache.xmlgraphics:batik-awt-util", "org.apache.xmlgraphics:batik-bridge", @@ -3040,6 +3458,7 @@ "org.apache.xmlgraphics:xmlgraphics-commons", "org.apiguardian:apiguardian-api", "org.assertj:assertj-core", + "org.attoparser:attoparser", "org.freemarker:freemarker", "org.glassfish:javax.el", "org.hamcrest:hamcrest-core", @@ -3070,6 +3489,7 @@ "org.ow2.asm:asm-commons", "org.ow2.asm:asm-tree", "org.reactivestreams:reactive-streams", + "org.slf4j:slf4j-api", "org.springframework.boot:spring-boot", "org.springframework.boot:spring-boot-autoconfigure", "org.springframework.cloud:spring-cloud-function-context", @@ -3081,6 +3501,9 @@ "org.springframework:spring-expression", "org.springframework:spring-jcl", "org.springframework:spring-messaging", + "org.thymeleaf:thymeleaf", + "org.unbescape:unbescape", + "org.yaml:snakeyaml", "xalan:serializer", "xalan:xalan", "xml-apis:xml-apis", @@ -3117,6 +3540,19 @@ "com.fasterxml.jackson.dataformat.cbor.CBORFactory" ] }, + "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml": { + "com.fasterxml.jackson.core.JsonFactory": [ + "com.fasterxml.jackson.dataformat.yaml.YAMLFactory" + ], + "com.fasterxml.jackson.core.ObjectCodec": [ + "com.fasterxml.jackson.dataformat.yaml.YAMLMapper" + ] + }, + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8": { + "com.fasterxml.jackson.databind.Module": [ + "com.fasterxml.jackson.datatype.jdk8.Jdk8Module" + ] + }, "com.h2database:h2": { "java.sql.Driver": [ "org.h2.Driver" diff --git a/sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/TemplateInjection.kt b/sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/TemplateInjection.kt index 4a43c09e6..fa7a9084b 100644 --- a/sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/TemplateInjection.kt +++ b/sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers/TemplateInjection.kt @@ -16,49 +16,423 @@ package com.code_intelligence.jazzer.sanitizers +import com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh import com.code_intelligence.jazzer.api.HookType import com.code_intelligence.jazzer.api.Jazzer import com.code_intelligence.jazzer.api.MethodHook +import com.code_intelligence.jazzer.api.MethodHooks import java.io.Reader import java.lang.invoke.MethodHandle /** - * Guides FreeMarker templates towards patterns that can trigger OS command injections. + * Detects server-side template injection (SSTI). * - * This does not report findings directly; it steers inputs towards OS command injections, - * which are detected by another bug detector. + * - FreeMarker: Guides parsed templates and `?eval` expressions towards a canary variable reference + * and reports a finding when FreeMarker looks up the canary while rendering. This works regardless + * of hardening settings such as the `?new` class resolver. + * - Thymeleaf: Guides templates and preprocessed expressions towards evaluating a canary variable + * expression and reports a finding when Thymeleaf evaluates it. + * - Velocity: Guides parsed templates towards a canary variable reference and reports a finding + * when Velocity looks up the canary while rendering. + * - Pebble: Guides tokenized templates towards a canary variable reference and reports a finding + * when Pebble looks up the canary while rendering. Covers both the current + * `io.pebbletemplates.pebble` package and the `com.mitchellbosecke.pebble` package used by + * releases before 3.2. + * - Jinjava: Guides parsed templates towards a canary variable reference and reports a finding + * when Jinjava looks up the canary while rendering. With Jinjava's default configuration, this also + * detects values that contain template code, as Jinjava renders the output of expressions again + * (nested interpretation). */ @Suppress("unused_parameter", "unused") object TemplateInjection { - private const val FREEMARKER_INJECTION_ATTACK: String = "\${\"freemarker.template.utility.Execute\"?new()(\"jazze\")}" + private const val SSTI_CANARY = "jazzerSsti" + private const val THYMELEAF_INLINE_ATTACK = "[[\${$SSTI_CANARY}]]" + private const val THYMELEAF_PREPROCESS_ATTACK = "__\${$SSTI_CANARY}__" + + // Velocity only evaluates the canary if it lands outside of comments, unparsed blocks and + // single-quoted strings, so all but the first entry break out of these contexts. + private val VELOCITY_ATTACKS = + listOf( + // Text and double-quoted (interpolated) strings + "\${$SSTI_CANARY}", + // Comments, unparsed blocks and single-quoted strings in #set and #if + "*#]]#\n'+\${$SSTI_CANARY}+'", + // Single-quoted method arguments and list literals + "',\${$SSTI_CANARY},'", + // Single-quoted macro arguments + "')\${$SSTI_CANARY}#set(\$x='", + ) + + // Pebble only evaluates the canary if it lands outside of comments, verbatim blocks and + // string literals. Double-quoted strings interpolate #{...}. + private val PEBBLE_ATTACKS = + listOf( + // Text; survives input filters that strip quotes + "{{$SSTI_CANARY}}", + // Text, single- and double-quoted strings and comments + "#{$SSTI_CANARY}'~$SSTI_CANARY~'#}{{$SSTI_CANARY}}", + // Verbatim blocks + "{% endverbatim %}{{$SSTI_CANARY}}{% verbatim %}", + ) + + private val JINJAVA_ATTACKS = + listOf( + // Text and printed strings (nested interpretation); survives input filters that strip quotes + "{{$SSTI_CANARY}}", + // Text, single- and double-quoted strings and comments + "\"~$SSTI_CANARY~\"'~$SSTI_CANARY~'#}{{$SSTI_CANARY}}", + // Raw blocks + "{% endraw %}{{$SSTI_CANARY}}{% raw %}", + ) + + private val FREEMARKER_ATTACKS = + listOf( + // Text and string literals, default syntax + "\${$SSTI_CANARY}", + // Text, all string literals and comments, in every tag and interpolation syntax + "-->--]\"+$SSTI_CANARY+\"'+$SSTI_CANARY+'\${$SSTI_CANARY}[=$SSTI_CANARY]", + // ?eval evaluates a single expression + SSTI_CANARY, + // noparse blocks (angle-bracket syntax) + "\${$SSTI_CANARY}<#noparse>", + ) init { - require(FREEMARKER_INJECTION_ATTACK.length <= 64) { + require(THYMELEAF_INLINE_ATTACK.length <= 64 && THYMELEAF_PREPROCESS_ATTACK.length <= 64) { + "Thymeleaf injection must fit in a table of recent compares entry (64 bytes)" + } + require(VELOCITY_ATTACKS.all { it.length <= 64 }) { + "Velocity injection must fit in a table of recent compares entry (64 bytes)" + } + require(PEBBLE_ATTACKS.all { it.length <= 64 }) { + "Pebble injection must fit in a table of recent compares entry (64 bytes)" + } + require(JINJAVA_ATTACKS.all { it.length <= 64 }) { + "Jinjava injection must fit in a table of recent compares entry (64 bytes)" + } + require(FREEMARKER_ATTACKS.all { it.length <= 64 }) { "FreeMarker injection must fit in a table of recent compares entry (64 bytes)" } } + /** + * Guides template strings passed to Thymeleaf (e.g. when using a `StringTemplateResolver`) + * towards an inlined expression. + */ + @MethodHooks( + MethodHook( + type = HookType.BEFORE, + targetClassName = "org.thymeleaf.ITemplateEngine", + targetMethod = "process", + ), + MethodHook( + type = HookType.BEFORE, + targetClassName = "org.thymeleaf.ITemplateEngine", + targetMethod = "processThrottled", + ), + ) + @JvmStatic + fun hookThymeleafProcess( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + val template = arguments.getOrNull(0) as? String ?: return + Jazzer.guideTowardsContainment(template, THYMELEAF_INLINE_ATTACK, hookId) + } + + /** + * Guides expressions that Thymeleaf preprocesses, e.g. Spring view names containing `::`, + * towards a nested `__${...}__` expression. + */ @MethodHook( type = HookType.BEFORE, - targetClassName = "freemarker.template.Template", - targetMethod = "", - additionalClassesToHook = ["freemarker.template.Template"], + targetClassName = "org.thymeleaf.standard.expression.StandardExpressionPreprocessor", + targetMethod = "preprocess", + additionalClassesToHook = [ + "org.thymeleaf.standard.expression.StandardExpressionParser", + "org.thymeleaf.standard.expression.AssignationUtils", + "org.thymeleaf.standard.expression.ExpressionSequenceUtils", + "org.thymeleaf.standard.expression.EachUtils", + ], + ) + @JvmStatic + fun hookThymeleafPreprocess( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + val input = arguments.getOrNull(1) as? String ?: return + Jazzer.guideTowardsContainment(input, THYMELEAF_PREPROCESS_ATTACK, hookId) + } + + /** + * Reports a finding when Thymeleaf evaluates the canary, which only appears in expressions + * if fuzzer-controlled data was parsed as an expression. + */ + @MethodHook( + type = HookType.BEFORE, + targetClassName = "org.thymeleaf.standard.expression.IStandardVariableExpressionEvaluator", + targetMethod = "evaluate", + additionalClassesToHook = [ + "org.thymeleaf.standard.expression.VariableExpression", + "org.thymeleaf.standard.expression.SelectionVariableExpression", + ], + ) + @JvmStatic + fun hookThymeleafEvaluate( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + val expression = arguments.getOrNull(1)?.toString() ?: return + if (SSTI_CANARY in expression) { + Jazzer.reportFindingFromHook( + FuzzerSecurityIssueHigh( + "Server Side Template Injection\n" + + "Fuzzer-controlled data was evaluated as a Thymeleaf expression: $expression", + ), + ) + } + } + + /** + * Reports a finding when Velocity looks up the canary variable, which only happens if + * fuzzer-controlled data was parsed as part of a template. + * + * Velocity 2.x looks up variables via InternalContextAdapter, which only inherits `get` from + * Context. Hooks on interfaces also apply to calls on interfaces extending them. + */ + @MethodHook( + type = HookType.BEFORE, + targetClassName = "org.apache.velocity.context.Context", + targetMethod = "get", + additionalClassesToHook = ["org.apache.velocity.runtime.parser.node.ASTReference"], + ) + @JvmStatic + fun hookVelocityContextGet( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + if (arguments.getOrNull(0) == SSTI_CANARY) { + Jazzer.reportFindingFromHook( + FuzzerSecurityIssueHigh( + "Server Side Template Injection\n" + + "Fuzzer-controlled data was evaluated as a Velocity context key: $SSTI_CANARY", + ), + ) + } + } + + /** + * Guides all template source that Velocity parses (templates from resource loaders, + * `Velocity.evaluate` and the `#evaluate` directive) towards a canary variable reference. + */ + @MethodHook( + type = HookType.BEFORE, + targetClassName = "org.apache.velocity.runtime.RuntimeServices", + targetMethod = "parse", + additionalClassesToHook = [ + "org.apache.velocity.runtime.RuntimeInstance", + "org.apache.velocity.runtime.RuntimeSingleton", + "org.apache.velocity.Template", + "org.apache.velocity.runtime.directive.Evaluate", + ], ) @JvmStatic - fun hookFreemarker( + fun hookVelocityParse( method: MethodHandle?, thisObject: Any?, arguments: Array, hookId: Int, ) { - (1..2) - .mapNotNull { idx -> (arguments.getOrNull(idx) as? Reader) } - .forEach { reader -> - Jazzer.guideTowardsContainment( - peekMarkableReader(reader, FREEMARKER_INJECTION_ATTACK.length), - FREEMARKER_INJECTION_ATTACK, - hookId, - ) + val source = + when (val src = arguments.getOrNull(0)) { + is String -> src + // libFuzzer only uses the needle, so readers that can't be peeked at are still guided. + is Reader -> if (src.markSupported()) peekMarkableReader(src, 64) else "" + else -> return } + VELOCITY_ATTACKS.forEach { Jazzer.guideTowardsContainment(source, it, hookId) } + } + + /** + * Guides all template source that Pebble compiles (`getTemplate` with any loader, + * `getLiteralTemplate`, `include` and `extends`) towards a canary variable reference. + */ + @MethodHooks( + MethodHook( + type = HookType.BEFORE, + targetClassName = "io.pebbletemplates.pebble.lexer.Lexer", + targetMethod = "tokenize", + additionalClassesToHook = ["io.pebbletemplates.pebble.PebbleEngine"], + ), + // Pebble 2.x tokenizes templates in an anonymous cache loader. + MethodHook( + type = HookType.BEFORE, + targetClassName = "com.mitchellbosecke.pebble.lexer.Lexer", + targetMethod = "tokenize", + additionalClassesToHook = [ + "com.mitchellbosecke.pebble.PebbleEngine", + "com.mitchellbosecke.pebble.PebbleEngine\$1", + ], + ), + ) + @JvmStatic + fun hookPebbleTokenize( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + // libFuzzer only uses the needle, so there's no need to peek at the Reader. + PEBBLE_ATTACKS.forEach { Jazzer.guideTowardsContainment("", it, hookId) } + } + + /** + * Reports a finding when Pebble looks up the canary variable, which only happens if + * fuzzer-controlled data was compiled as part of a template. This works regardless of the + * configured method access validator. + */ + @MethodHooks( + MethodHook( + type = HookType.BEFORE, + targetClassName = "io.pebbletemplates.pebble.template.ScopeChain", + targetMethod = "get", + additionalClassesToHook = ["io.pebbletemplates.pebble.node.expression.ContextVariableExpression"], + ), + MethodHook( + type = HookType.BEFORE, + targetClassName = "com.mitchellbosecke.pebble.template.ScopeChain", + targetMethod = "get", + additionalClassesToHook = ["com.mitchellbosecke.pebble.node.expression.ContextVariableExpression"], + ), + ) + @JvmStatic + fun hookPebbleVariableLookup( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + if (arguments.getOrNull(0) == SSTI_CANARY) { + Jazzer.reportFindingFromHook( + FuzzerSecurityIssueHigh( + "Server Side Template Injection\n" + + "Fuzzer-controlled data was evaluated as a Pebble template", + ), + ) + } + } + + // All template text (render, include, import, from, extends) is parsed by a TreeParser, + // which only JinjavaInterpreter.parse creates. + @MethodHook( + type = HookType.BEFORE, + targetClassName = "com.hubspot.jinjava.tree.TreeParser", + targetMethod = "", + additionalClassesToHook = ["com.hubspot.jinjava.interpret.JinjavaInterpreter"], + ) + @JvmStatic + fun hookJinjavaParse( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + JINJAVA_ATTACKS.forEach { Jazzer.guideTowardsContainment("", it, hookId) } + } + + // Template variables are resolved through retraceVariable; both overloads take the name first. + @MethodHook( + type = HookType.BEFORE, + targetClassName = "com.hubspot.jinjava.interpret.JinjavaInterpreter", + targetMethod = "retraceVariable", + additionalClassesToHook = [ + "com.hubspot.jinjava.el.JinjavaInterpreterResolver", + // Resolves bare tag arguments, e.g. {% include name %} + "com.hubspot.jinjava.interpret.JinjavaInterpreter", + "com.hubspot.jinjava.lib.tag.CycleTag", + "com.hubspot.jinjava.lib.tag.IfchangedTag", + "com.hubspot.jinjava.lib.tag.eager.EagerCycleTag", + "com.hubspot.jinjava.lib.tag.eager.EagerSetTagStrategy", + "com.hubspot.jinjava.util.EagerExpressionResolver", + ], + ) + @JvmStatic + fun hookJinjavaVariableLookup( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + if (arguments.getOrNull(0) == SSTI_CANARY) { + Jazzer.reportFindingFromHook( + FuzzerSecurityIssueHigh( + "Server Side Template Injection\n" + + "Fuzzer-controlled data was evaluated as a Jinjava template", + ), + ) + } + } + + /** + * Reports a finding when FreeMarker looks up the canary variable, which only happens if + * fuzzer-controlled data was parsed as part of a template or an `?eval` expression. + */ + @MethodHook( + type = HookType.BEFORE, + targetClassName = "freemarker.core.Environment", + targetMethod = "getVariable", + additionalClassesToHook = [ + "freemarker.core.Identifier", + "freemarker.core.BuiltinVariable\$VarsHash", + ], + ) + @JvmStatic + fun hookFreemarkerVariableLookup( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + if (arguments.getOrNull(0) == SSTI_CANARY) { + Jazzer.reportFindingFromHook( + FuzzerSecurityIssueHigh( + "Server Side Template Injection\n" + + "Fuzzer-controlled data was evaluated as a FreeMarker template", + ), + ) + } + } + + /** + * Guides all FreeMarker template source and `?eval` expressions towards a canary variable + * reference. Every template creates its parser in its own constructor, regardless of whether it + * is created directly, by a template loader or by `?interpret`. `?eval` creates a parser without + * creating a template. + */ + @MethodHook( + type = HookType.BEFORE, + targetClassName = "freemarker.core.FMParser", + targetMethod = "", + additionalClassesToHook = [ + "freemarker.template.Template", + "freemarker.core.BuiltInsForStringsMisc\$evalBI", + ], + ) + @JvmStatic + fun hookFreemarkerParse( + method: MethodHandle?, + thisObject: Any?, + arguments: Array, + hookId: Int, + ) { + FREEMARKER_ATTACKS.forEach { Jazzer.guideTowardsContainment("", it, hookId) } } } diff --git a/sanitizers/src/test/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel b/sanitizers/src/test/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel index 3de4f58a0..c5889dc4e 100644 --- a/sanitizers/src/test/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel +++ b/sanitizers/src/test/java/com/code_intelligence/jazzer/sanitizers/BUILD.bazel @@ -19,6 +19,8 @@ java_junit5_test( "//sanitizers/src/main/java/com/code_intelligence/jazzer/sanitizers:constants", "//src/main/java/com/code_intelligence/jazzer/api:hooks", "@clojure_jar//jar", + "@maven//:com_hubspot_jinjava_jinjava", + "@maven//:io_pebbletemplates_pebble", "@maven//:jakarta_el_jakarta_el_api", "@maven//:jakarta_validation_jakarta_validation_api", "@maven//:javax_el_javax_el_api", @@ -26,11 +28,14 @@ java_junit5_test( "@maven//:javax_validation_validation_api", "@maven//:ognl_ognl", "@maven//:org_apache_commons_commons_jexl", + "@maven//:org_apache_velocity_velocity_engine_core", "@maven//:org_freemarker_freemarker", "@maven//:org_junit_jupiter_junit_jupiter_api", "@maven//:org_junit_jupiter_junit_jupiter_params", "@maven//:org_mvel_mvel2", "@maven//:org_springframework_cloud_spring_cloud_function_context", "@maven//:org_springframework_cloud_spring_cloud_function_core", + "@maven//:org_thymeleaf_thymeleaf", + "@pebble_legacy_jar//jar", ], ) diff --git a/sanitizers/src/test/java/com/example/BUILD.bazel b/sanitizers/src/test/java/com/example/BUILD.bazel index 76a1d32eb..70f3faa7c 100644 --- a/sanitizers/src/test/java/com/example/BUILD.bazel +++ b/sanitizers/src/test/java/com/example/BUILD.bazel @@ -314,24 +314,256 @@ java_fuzz_target_test( ], ) -java_fuzz_target_test( - name = "TemplateInjection", - srcs = [ - "TemplateInjection.java", - ], +# FreeMarker template injection. Hooks are only applied to the harness and the classes listed in +# the hooks' additionalClassesToHook, as in JUnit fuzz tests, to verify that these lists are +# complete. +[java_fuzz_target_test( + name = target, + srcs = [target + ".java"], allowed_findings = [ - "com.code_intelligence.jazzer.api.FuzzerSecurityIssueCritical", + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", ], # FreeMarker has too many classes to instrument safely fuzzer_args = [ "--instrumentation_includes=com.example.**", + "--custom_hook_includes=com.example.**", ], tags = ["dangerous"], - target_class = "com.example.TemplateInjection", + target_class = "com.example." + target, verify_crash_reproducer = False, deps = [ "@maven//:org_freemarker_freemarker", ], +) for target in [ + "FreeMarkerEvalInjection", + "FreeMarkerHardenedInjection", + "FreeMarkerSquareBracketInjection", + "TemplateInjection", +]] + +# FreeMarker reads template files through a Reader that doesn't support mark(). Verifies that the +# template injection guidance doesn't break loading them. Fuzzer data is only passed as a value. +java_fuzz_target_test( + name = "FreeMarkerFileTemplate", + srcs = ["FreeMarkerFileTemplate.java"], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=10000", + ], + target_class = "com.example.FreeMarkerFileTemplate", + deps = [ + "@maven//:org_freemarker_freemarker", + ], +) + +# Verifies that the FreeMarker hooks don't report fuzzer data that is only rendered as a value. +# Hooks are applied to all classes to also cover FreeMarker's internal call sites. +java_fuzz_target_test( + name = "FreeMarkerSafeModelValue", + srcs = ["FreeMarkerSafeModelValue.java"], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=20000", + ], + target_class = "com.example.FreeMarkerSafeModelValue", + deps = [ + "@maven//:org_freemarker_freemarker", + ], +) + +[java_fuzz_target_test( + name = target, + srcs = [target + ".java"], + allowed_findings = [ + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", + ], + fuzzer_args = [ + # The sanitizer's hints alone lead the fuzzer to the injection. Instrumenting Thymeleaf for + # coverage would only make the test slower. + "--instrumentation_includes=com.example.**", + # Hooks only reach Thymeleaf's internal call sites through additionalClassesToHook, as in + # JUnit fuzz tests. This catches hooks that no longer list the classes calling their target. + "--custom_hook_includes=com.example.**", + ], + tags = ["dangerous"], + target_class = "com.example." + target, + # The reproducer doesn't contain the sanitizer and thus doesn't crash. + verify_crash_reproducer = False, + deps = [ + "@maven//:org_thymeleaf_thymeleaf", + ], +) for target in [ + "ThymeleafTemplateInjection", + "ThymeleafViewNameInjection", +]] + +# Verifies that the Thymeleaf hooks don't report fuzzer data that is only rendered as a value. +java_fuzz_target_test( + name = "ThymeleafSafeModelValue", + srcs = ["ThymeleafSafeModelValue.java"], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=20000", + ], + target_class = "com.example.ThymeleafSafeModelValue", + deps = [ + "@maven//:org_thymeleaf_thymeleaf", + ], +) + +[java_fuzz_target_test( + name = target, + srcs = [target + ".java"], + allowed_findings = [ + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", + ], + fuzzer_args = [ + # The sanitizer's hints alone lead the fuzzer to the injection. Instrumenting Velocity for + # coverage would only make the test slower. + "--instrumentation_includes=com.example.**", + # Hooks only reach Velocity's internal call sites through additionalClassesToHook, as in + # JUnit fuzz tests. This catches hooks that no longer list the classes calling their target. + "--custom_hook_includes=com.example.**", + ], + tags = ["dangerous"], + target_class = "com.example." + target, + # The reproducer doesn't contain the sanitizer and thus doesn't crash. + verify_crash_reproducer = False, + deps = [ + "@maven//:org_apache_velocity_velocity_engine_core", + ], +) for target in [ + "VelocityEvaluateDirective", + "VelocitySingleQuotedInjection", + "VelocityTemplateInjection", +]] + +# Verifies that the Velocity hooks don't report fuzzer data that is only rendered as a value. Hooks +# are applied to all classes to also cover Velocity's internal call sites. +java_fuzz_target_test( + name = "VelocitySafeModelValue", + srcs = ["VelocitySafeModelValue.java"], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=20000", + ], + target_class = "com.example.VelocitySafeModelValue", + deps = [ + "@maven//:org_apache_velocity_velocity_engine_core", + ], +) + +[java_fuzz_target_test( + name = target, + srcs = [target + ".java"], + allowed_findings = [ + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", + ], + fuzzer_args = [ + # The sanitizer's hints alone lead the fuzzer to the injection. Instrumenting Pebble for + # coverage would only make the test slower. + "--instrumentation_includes=com.example.**", + # Hooks only reach Pebble's internal call sites through additionalClassesToHook, as in + # JUnit fuzz tests. This catches hooks that no longer list the classes calling their target. + "--custom_hook_includes=com.example.**", + ], + tags = ["dangerous"], + target_class = "com.example." + target, + # The reproducer doesn't contain the sanitizer and thus doesn't crash. + verify_crash_reproducer = False, + deps = [ + "@maven//:io_pebbletemplates_pebble", + ], +) for target in [ + "PebbleDoubleQuotedInjection", + "PebbleSingleQuotedInjection", + "PebbleTemplateInjection", +]] + +# Pebble 3.1, the last release using the com.mitchellbosecke.pebble package. +java_fuzz_target_test( + name = "PebbleLegacyTemplateInjection", + srcs = ["PebbleLegacyTemplateInjection.java"], + allowed_findings = [ + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", + ], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "--custom_hook_includes=com.example.**", + ], + tags = ["dangerous"], + target_class = "com.example.PebbleLegacyTemplateInjection", + # The reproducer doesn't contain the sanitizer and thus doesn't crash. + verify_crash_reproducer = False, + runtime_deps = [ + "@maven//:org_slf4j_slf4j_api", + "@maven//:org_unbescape_unbescape", + ], + deps = [ + "@pebble_legacy_jar//jar", + ], +) + +# Verifies that the Pebble hooks don't report fuzzer data that is only rendered as a value. Hooks +# are applied to all classes to also cover Pebble's internal call sites. +java_fuzz_target_test( + name = "PebbleSafeModelValue", + srcs = ["PebbleSafeModelValue.java"], + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=20000", + ], + target_class = "com.example.PebbleSafeModelValue", + deps = [ + "@maven//:io_pebbletemplates_pebble", + ], +) + +[java_fuzz_target_test( + name = target, + srcs = [target + ".java"], + allowed_findings = [ + "com.code_intelligence.jazzer.api.FuzzerSecurityIssueHigh", + ], + fuzzer_args = [ + # The sanitizer's hints alone lead the fuzzer to the injection. Instrumenting Jinjava for + # coverage would make the test slower and log a warning about its bundled Java 5 classes. + "--instrumentation_includes=com.example.**", + # Hooks only reach Jinjava's internal call sites through additionalClassesToHook, as in + # JUnit fuzz tests. This catches hooks that no longer list the classes calling their target. + "--custom_hook_includes=com.example.**", + ], + tags = ["dangerous"], + target_class = "com.example." + target, + # The reproducer doesn't contain the sanitizer and thus doesn't crash. + verify_crash_reproducer = False, + deps = [ + "@maven//:com_hubspot_jinjava_jinjava", + ], +) for target in [ + "JinjavaCommentInjection", + "JinjavaNestedInterpretation", + "JinjavaRawBlockInjection", + "JinjavaSingleQuotedInjection", + "JinjavaTemplateInjection", +]] + +# Verifies that the Jinjava hooks don't report fuzzer data that is only rendered as a value with +# nested interpretation disabled. Hooks are applied to all classes to also cover Jinjava's internal +# call sites. +java_fuzz_target_test( + name = "JinjavaSafeModelValue", + srcs = ["JinjavaSafeModelValue.java"], + # Jinjava bundles a copy of JUEL compiled for Java 5. + expected_warning_or_error = "WARN: Some hooks could not be applied to class files built for Java 7 or lower.", + fuzzer_args = [ + "--instrumentation_includes=com.example.**", + "-runs=20000", + ], + target_class = "com.example.JinjavaSafeModelValue", + deps = [ + "@maven//:com_hubspot_jinjava_jinjava", + ], ) [java_fuzz_target_test( diff --git a/sanitizers/src/test/java/com/example/FreeMarkerEvalInjection.java b/sanitizers/src/test/java/com/example/FreeMarkerEvalInjection.java new file mode 100644 index 000000000..b4e46cfaa --- /dev/null +++ b/sanitizers/src/test/java/com/example/FreeMarkerEvalInjection.java @@ -0,0 +1,55 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import freemarker.core.TemplateClassResolver; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateExceptionHandler; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Uses ?eval to "parse JSON" from fuzzer data in a template that is created once, before fuzzing + * starts. ?eval evaluates FreeMarker expressions, which can read any variable. + */ +public class FreeMarkerEvalInjection { + private static Template template; + + public static void fuzzerInitialize() throws Exception { + Configuration configuration = new Configuration(Configuration.VERSION_2_3_34); + configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER); + configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + configuration.setLogTemplateExceptions(false); + template = + new Template( + "settings", + new StringReader("<#assign settings = settingsJson?eval>${settings.theme!}"), + configuration); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + template.process( + Collections.singletonMap("settingsJson", data.consumeRemainingAsString()), + new StringWriter()); + } catch (Exception ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/FreeMarkerFileTemplate.java b/sanitizers/src/test/java/com/example/FreeMarkerFileTemplate.java new file mode 100644 index 000000000..09d880c15 --- /dev/null +++ b/sanitizers/src/test/java/com/example/FreeMarkerFileTemplate.java @@ -0,0 +1,56 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import freemarker.template.Configuration; +import freemarker.template.Template; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + +/** + * Renders a trusted template loaded from a file and passes fuzzer data only as a value. FreeMarker + * reads template files through a Reader that doesn't support mark(). + */ +public class FreeMarkerFileTemplate { + private static final Configuration configuration = + new Configuration(Configuration.VERSION_2_3_34); + + static { + try { + Path dir = Files.createTempDirectory("freemarker"); + dir.toFile().deleteOnExit(); + Path template = + Files.write( + dir.resolve("greeting.ftl"), "Hello ${name}!".getBytes(StandardCharsets.UTF_8)); + template.toFile().deleteOnExit(); + configuration.setDirectoryForTemplateLoading(dir.toFile()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws Exception { + Template template = configuration.getTemplate("greeting.ftl"); + template.process( + Collections.singletonMap("name", data.consumeRemainingAsString()), new StringWriter()); + } +} diff --git a/sanitizers/src/test/java/com/example/FreeMarkerHardenedInjection.java b/sanitizers/src/test/java/com/example/FreeMarkerHardenedInjection.java new file mode 100644 index 000000000..bc23136e6 --- /dev/null +++ b/sanitizers/src/test/java/com/example/FreeMarkerHardenedInjection.java @@ -0,0 +1,50 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import freemarker.core.TemplateClassResolver; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateExceptionHandler; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a template comment. The configuration blocks ?new, so the injection + * can't execute OS commands, but it can still read the data model. + */ +public class FreeMarkerHardenedInjection { + private static final Configuration configuration = + new Configuration(Configuration.VERSION_2_3_34); + + static { + configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER); + configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + configuration.setLogTemplateExceptions(false); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "<#-- Last edited by " + data.consumeRemainingAsString() + " -->

Hi

"; + try { + new Template("t", new StringReader(template), configuration) + .process(Collections.emptyMap(), new StringWriter()); + } catch (Exception ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/FreeMarkerSafeModelValue.java b/sanitizers/src/test/java/com/example/FreeMarkerSafeModelValue.java new file mode 100644 index 000000000..50b76bba7 --- /dev/null +++ b/sanitizers/src/test/java/com/example/FreeMarkerSafeModelValue.java @@ -0,0 +1,39 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import freemarker.template.Configuration; +import freemarker.template.Template; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Collections; + +/** Passes fuzzer data only as a value, which FreeMarker never parses as template code. */ +public class FreeMarkerSafeModelValue { + private static final Configuration configuration = + new Configuration(Configuration.VERSION_2_3_34); + private static final String TEMPLATE = + "Hello ${name}! <#assign greeting = \"Hi ${name}\">${greeting}" + + "<#if name == 'admin'>Admin"; + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws Exception { + new Template("greeting", new StringReader(TEMPLATE), configuration) + .process( + Collections.singletonMap("name", data.consumeRemainingAsString()), new StringWriter()); + } +} diff --git a/sanitizers/src/test/java/com/example/FreeMarkerSquareBracketInjection.java b/sanitizers/src/test/java/com/example/FreeMarkerSquareBracketInjection.java new file mode 100644 index 000000000..889959138 --- /dev/null +++ b/sanitizers/src/test/java/com/example/FreeMarkerSquareBracketInjection.java @@ -0,0 +1,52 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import freemarker.core.TemplateClassResolver; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateExceptionHandler; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a template comment with the square bracket tag ([#...]) and + * interpolation ([=...]) syntax configured. + */ +public class FreeMarkerSquareBracketInjection { + private static final Configuration configuration = + new Configuration(Configuration.VERSION_2_3_34); + + static { + configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER); + configuration.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX); + configuration.setInterpolationSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX); + configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + configuration.setLogTemplateExceptions(false); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "[#-- Last edited by " + data.consumeRemainingAsString() + " --]

Hi

"; + try { + new Template("t", new StringReader(template), configuration) + .process(Collections.emptyMap(), new StringWriter()); + } catch (Exception ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaCommentInjection.java b/sanitizers/src/test/java/com/example/JinjavaCommentInjection.java new file mode 100644 index 000000000..458e2148c --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaCommentInjection.java @@ -0,0 +1,38 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a template comment. Jinjava neither renders nor outputs comments, + * so exploiting this requires closing the comment. + */ +public class JinjavaCommentInjection { + private static final Jinjava jinjava = new Jinjava(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "{# Last edited by " + data.consumeRemainingAsString() + " #}

Hi

"; + try { + jinjava.render(template, Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Jinjava throws e.g. FatalTemplateErrorsException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaNestedInterpretation.java b/sanitizers/src/test/java/com/example/JinjavaNestedInterpretation.java new file mode 100644 index 000000000..beaacfe0e --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaNestedInterpretation.java @@ -0,0 +1,39 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import java.util.Collections; + +/** + * Passes fuzzer data only as a value. With nested interpretation, which is enabled by default, + * Jinjava renders printed values again if they contain template code. + */ +public class JinjavaNestedInterpretation { + private static final Jinjava jinjava = new Jinjava(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + jinjava.render( + "

Dear {{ name }},

", + Collections.singletonMap("name", data.consumeRemainingAsString())); + } catch (RuntimeException ignored) { + // Jinjava throws e.g. FatalTemplateErrorsException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaRawBlockInjection.java b/sanitizers/src/test/java/com/example/JinjavaRawBlockInjection.java new file mode 100644 index 000000000..44c634445 --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaRawBlockInjection.java @@ -0,0 +1,38 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a raw block, which Jinjava outputs without rendering it. Exploiting + * this requires closing the raw block. + */ +public class JinjavaRawBlockInjection { + private static final Jinjava jinjava = new Jinjava(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "
{% raw %}" + data.consumeRemainingAsString() + "{% endraw %}
"; + try { + jinjava.render(template, Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Jinjava throws e.g. FatalTemplateErrorsException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaSafeModelValue.java b/sanitizers/src/test/java/com/example/JinjavaSafeModelValue.java new file mode 100644 index 000000000..dc41d7abb --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaSafeModelValue.java @@ -0,0 +1,38 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import com.hubspot.jinjava.JinjavaConfig; +import java.util.Collections; + +/** + * Passes fuzzer data only as a value with nested interpretation disabled, so Jinjava never renders + * it as template code. + */ +public class JinjavaSafeModelValue { + private static final Jinjava jinjava = + new Jinjava(JinjavaConfig.newBuilder().withNestedInterpretationEnabled(false).build()); + private static final String TEMPLATE = + "Hello {{ name }}! {% set greeting = 'Hi ' ~ name %}{{ greeting }}" + + "{% if name == 'admin' %}Admin{% endif %}"; + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + jinjava.render(TEMPLATE, Collections.singletonMap("name", data.consumeRemainingAsString())); + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaSingleQuotedInjection.java b/sanitizers/src/test/java/com/example/JinjavaSingleQuotedInjection.java new file mode 100644 index 000000000..63fade374 --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaSingleQuotedInjection.java @@ -0,0 +1,42 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import com.hubspot.jinjava.JinjavaConfig; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a single-quoted string literal. Nested interpretation is disabled, + * so Jinjava doesn't render the printed string again and exploiting this requires breaking out of + * the quotes. + */ +public class JinjavaSingleQuotedInjection { + private static final Jinjava jinjava = + new Jinjava(JinjavaConfig.newBuilder().withNestedInterpretationEnabled(false).build()); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = + "{% set greeting = 'Hello " + data.consumeRemainingAsString() + "' %}{{ greeting }}"; + try { + jinjava.render(template, Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Jinjava throws e.g. FatalTemplateErrorsException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/JinjavaTemplateInjection.java b/sanitizers/src/test/java/com/example/JinjavaTemplateInjection.java new file mode 100644 index 000000000..90d29ef1f --- /dev/null +++ b/sanitizers/src/test/java/com/example/JinjavaTemplateInjection.java @@ -0,0 +1,35 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.hubspot.jinjava.Jinjava; +import java.util.Collections; + +/** Concatenates fuzzer data into the source of a Jinjava template before rendering it. */ +public class JinjavaTemplateInjection { + private static final Jinjava jinjava = new Jinjava(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "

Dear " + data.consumeRemainingAsString() + ",

"; + try { + jinjava.render(template, Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Jinjava throws e.g. FatalTemplateErrorsException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/PebbleDoubleQuotedInjection.java b/sanitizers/src/test/java/com/example/PebbleDoubleQuotedInjection.java new file mode 100644 index 000000000..aa16fdb55 --- /dev/null +++ b/sanitizers/src/test/java/com/example/PebbleDoubleQuotedInjection.java @@ -0,0 +1,40 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import io.pebbletemplates.pebble.PebbleEngine; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a double-quoted string literal, in which Pebble interpolates #{...} + * expressions. + */ +public class PebbleDoubleQuotedInjection { + private static final PebbleEngine engine = new PebbleEngine.Builder().build(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException { + String template = "{{ \"Hello " + data.consumeRemainingAsString() + "\" }}"; + try { + engine.getLiteralTemplate(template).evaluate(new StringWriter(), Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Besides PebbleException, Pebble throws e.g. NumberFormatException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/PebbleLegacyTemplateInjection.java b/sanitizers/src/test/java/com/example/PebbleLegacyTemplateInjection.java new file mode 100644 index 000000000..01fc9f721 --- /dev/null +++ b/sanitizers/src/test/java/com/example/PebbleLegacyTemplateInjection.java @@ -0,0 +1,41 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import com.mitchellbosecke.pebble.PebbleEngine; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a single-quoted string literal of a template compiled by a Pebble + * release that still uses the com.mitchellbosecke.pebble package. + */ +public class PebbleLegacyTemplateInjection { + private static final PebbleEngine engine = new PebbleEngine.Builder().build(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException { + String template = + "{% set greeting = 'Hello " + data.consumeRemainingAsString() + "' %}{{ greeting }}"; + try { + engine.getLiteralTemplate(template).evaluate(new StringWriter(), Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Besides PebbleException, Pebble throws e.g. NumberFormatException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/PebbleSafeModelValue.java b/sanitizers/src/test/java/com/example/PebbleSafeModelValue.java new file mode 100644 index 000000000..824d90db9 --- /dev/null +++ b/sanitizers/src/test/java/com/example/PebbleSafeModelValue.java @@ -0,0 +1,40 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.template.PebbleTemplate; +import java.io.IOException; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; + +/** Passes fuzzer data only as a value, which Pebble never compiles as template code. */ +public class PebbleSafeModelValue { + private static final PebbleTemplate template = + new PebbleEngine.Builder() + .build() + .getLiteralTemplate( + "Hello {{ name }}! {{ \"Hi #{name}\" }} {% if name == 'admin' %}Admin{% endif %}"); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException { + Map context = new HashMap<>(); + context.put("name", data.consumeRemainingAsString()); + template.evaluate(new StringWriter(), context); + } +} diff --git a/sanitizers/src/test/java/com/example/PebbleSingleQuotedInjection.java b/sanitizers/src/test/java/com/example/PebbleSingleQuotedInjection.java new file mode 100644 index 000000000..2294b49f0 --- /dev/null +++ b/sanitizers/src/test/java/com/example/PebbleSingleQuotedInjection.java @@ -0,0 +1,41 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import io.pebbletemplates.pebble.PebbleEngine; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +/** + * Concatenates fuzzer data into a single-quoted string literal. Pebble never interpolates such + * literals, so exploiting this requires breaking out of the quotes. + */ +public class PebbleSingleQuotedInjection { + private static final PebbleEngine engine = new PebbleEngine.Builder().build(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException { + String template = + "{% set greeting = 'Hello " + data.consumeRemainingAsString() + "' %}{{ greeting }}"; + try { + engine.getLiteralTemplate(template).evaluate(new StringWriter(), Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Besides PebbleException, Pebble throws e.g. NumberFormatException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/PebbleTemplateInjection.java b/sanitizers/src/test/java/com/example/PebbleTemplateInjection.java new file mode 100644 index 000000000..83bc14531 --- /dev/null +++ b/sanitizers/src/test/java/com/example/PebbleTemplateInjection.java @@ -0,0 +1,37 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import io.pebbletemplates.pebble.PebbleEngine; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +/** Concatenates fuzzer data into the source of a Pebble template before rendering it. */ +public class PebbleTemplateInjection { + private static final PebbleEngine engine = new PebbleEngine.Builder().build(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException { + String template = "

Dear " + data.consumeRemainingAsString() + ",

"; + try { + engine.getLiteralTemplate(template).evaluate(new StringWriter(), Collections.emptyMap()); + } catch (RuntimeException ignored) { + // Besides PebbleException, Pebble throws e.g. NumberFormatException for invalid templates. + } + } +} diff --git a/sanitizers/src/test/java/com/example/ThymeleafSafeModelValue.java b/sanitizers/src/test/java/com/example/ThymeleafSafeModelValue.java new file mode 100644 index 000000000..62fc37b02 --- /dev/null +++ b/sanitizers/src/test/java/com/example/ThymeleafSafeModelValue.java @@ -0,0 +1,34 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; + +/** Passes fuzzer data only as a model value, which Thymeleaf never evaluates as an expression. */ +public class ThymeleafSafeModelValue { + private static final TemplateEngine engine = new TemplateEngine(); + private static final String TEMPLATE = + "

[[${name}]]

"; + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + Context context = new Context(); + context.setVariable("name", data.consumeRemainingAsString()); + engine.process(TEMPLATE, context); + } +} diff --git a/sanitizers/src/test/java/com/example/ThymeleafTemplateInjection.java b/sanitizers/src/test/java/com/example/ThymeleafTemplateInjection.java new file mode 100644 index 000000000..d52ad39c2 --- /dev/null +++ b/sanitizers/src/test/java/com/example/ThymeleafTemplateInjection.java @@ -0,0 +1,36 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; +import org.thymeleaf.exceptions.TemplateEngineException; + +/** Renders fuzzer-controlled template content, which allows arbitrary expression evaluation. */ +public class ThymeleafTemplateInjection { + // Without a configured template resolver, the engine treats the template name as its content. + private static final TemplateEngine engine = new TemplateEngine(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = data.consumeRemainingAsString(); + try { + engine.process(template, new Context()); + } catch (TemplateEngineException ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/ThymeleafViewNameInjection.java b/sanitizers/src/test/java/com/example/ThymeleafViewNameInjection.java new file mode 100644 index 000000000..926ee6dbd --- /dev/null +++ b/sanitizers/src/test/java/com/example/ThymeleafViewNameInjection.java @@ -0,0 +1,43 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.thymeleaf.IEngineConfiguration; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.ExpressionContext; +import org.thymeleaf.exceptions.TemplateEngineException; +import org.thymeleaf.standard.expression.StandardExpressions; + +/** + * Mimics a Spring controller that returns a view name built from user input. Spring's ThymeleafView + * parses view names containing "::" as fragment expressions, which Thymeleaf preprocesses, so + * nested "__${...}__" expressions in the input are evaluated. + */ +public class ThymeleafViewNameInjection { + private static final IEngineConfiguration configuration = new TemplateEngine().getConfiguration(); + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String section = data.consumeRemainingAsString(); + String viewName = "user/" + section + "/welcome :: content"; + try { + StandardExpressions.getExpressionParser(configuration) + .parseExpression(new ExpressionContext(configuration), "~{" + viewName + "}"); + } catch (TemplateEngineException ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/VelocityEvaluateDirective.java b/sanitizers/src/test/java/com/example/VelocityEvaluateDirective.java new file mode 100644 index 000000000..32a34607e --- /dev/null +++ b/sanitizers/src/test/java/com/example/VelocityEvaluateDirective.java @@ -0,0 +1,45 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.io.StringWriter; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.VelocityException; + +/** + * Passes fuzzer data only as a value, but the trusted template evaluates that value as a template + * with the #evaluate directive. + */ +public class VelocityEvaluateDirective { + private static final VelocityEngine engine = new VelocityEngine(); + private static final String TEMPLATE = "

About me: #evaluate($bio)

"; + + static { + engine.init(); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + VelocityContext context = new VelocityContext(); + context.put("bio", data.consumeRemainingAsString()); + try { + engine.evaluate(context, new StringWriter(), "profile", TEMPLATE); + } catch (VelocityException ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/VelocitySafeModelValue.java b/sanitizers/src/test/java/com/example/VelocitySafeModelValue.java new file mode 100644 index 000000000..c4e3d645f --- /dev/null +++ b/sanitizers/src/test/java/com/example/VelocitySafeModelValue.java @@ -0,0 +1,39 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.io.StringWriter; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + +/** Passes fuzzer data only as a value, which Velocity never parses as template code. */ +public class VelocitySafeModelValue { + private static final VelocityEngine engine = new VelocityEngine(); + private static final String TEMPLATE = + "Hello $name! #set($greeting = \"Hi $name\")$greeting #if($name == 'admin')Admin#end"; + + static { + engine.init(); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + VelocityContext context = new VelocityContext(); + context.put("name", data.consumeRemainingAsString()); + engine.evaluate(context, new StringWriter(), "greeting", TEMPLATE); + } +} diff --git a/sanitizers/src/test/java/com/example/VelocitySingleQuotedInjection.java b/sanitizers/src/test/java/com/example/VelocitySingleQuotedInjection.java new file mode 100644 index 000000000..70997b9b1 --- /dev/null +++ b/sanitizers/src/test/java/com/example/VelocitySingleQuotedInjection.java @@ -0,0 +1,43 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.io.StringWriter; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.VelocityException; + +/** + * Concatenates fuzzer data into a single-quoted string literal. Velocity never interpolates such + * literals, so exploiting this requires breaking out of the quotes. + */ +public class VelocitySingleQuotedInjection { + private static final VelocityEngine engine = new VelocityEngine(); + + static { + engine.init(); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "#set($greeting = 'Hello " + data.consumeRemainingAsString() + "')$greeting"; + try { + engine.evaluate(new VelocityContext(), new StringWriter(), "greeting", template); + } catch (VelocityException ignored) { + } + } +} diff --git a/sanitizers/src/test/java/com/example/VelocityTemplateInjection.java b/sanitizers/src/test/java/com/example/VelocityTemplateInjection.java new file mode 100644 index 000000000..df96b8bdc --- /dev/null +++ b/sanitizers/src/test/java/com/example/VelocityTemplateInjection.java @@ -0,0 +1,40 @@ +/* + * Copyright 2026 Code Intelligence GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.io.StringWriter; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.VelocityException; + +/** Concatenates fuzzer data into the source of a Velocity template before rendering it. */ +public class VelocityTemplateInjection { + private static final VelocityEngine engine = new VelocityEngine(); + + static { + engine.init(); + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + String template = "Dear " + data.consumeRemainingAsString() + ",\nthank you for your order."; + try { + engine.evaluate(new VelocityContext(), new StringWriter(), "greeting", template); + } catch (VelocityException ignored) { + } + } +}