|
| 1 | +/** Definitions related to the server-side template injection (SST) query. */ |
| 2 | + |
| 3 | +import java |
| 4 | +private import semmle.code.java.dataflow.FlowSources |
| 5 | +private import semmle.code.java.dataflow.ExternalFlow |
| 6 | +private import semmle.code.java.dataflow.TaintTracking |
| 7 | + |
| 8 | +/** |
| 9 | + * A source for server-side template injection (SST) vulnerabilities. |
| 10 | + */ |
| 11 | +abstract class TemplateInjectionSource extends DataFlow::Node { |
| 12 | + /** Holds if this source has the specified `state`. */ |
| 13 | + predicate hasState(DataFlow::FlowState state) { state instanceof DataFlow::FlowStateEmpty } |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * A sink for server-side template injection (SST) vulnerabilities. |
| 18 | + */ |
| 19 | +abstract class TemplateInjectionSink extends DataFlow::Node { |
| 20 | + /** Holds if this sink has the specified `state`. */ |
| 21 | + predicate hasState(DataFlow::FlowState state) { state instanceof DataFlow::FlowStateEmpty } |
| 22 | +} |
| 23 | + |
| 24 | +/** |
| 25 | + * A unit class for adding additional taint steps. |
| 26 | + * |
| 27 | + * Extend this class to add additional taint steps that should apply to flows related to |
| 28 | + * server-side template injection (SST) vulnerabilities. |
| 29 | + */ |
| 30 | +class TemplateInjectionAdditionalTaintStep extends Unit { |
| 31 | + /** |
| 32 | + * Holds if the step from `node1` to `node2` should be considered a taint |
| 33 | + * step for flows related to server-side template injection (SST) vulnerabilities. |
| 34 | + */ |
| 35 | + predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) { none() } |
| 36 | + |
| 37 | + /** |
| 38 | + * Holds if the step from `node1` to `node2` should be considered a taint |
| 39 | + * step for flows related toserver-side template injection (SST) vulnerabilities. |
| 40 | + * This step is only applicable in `state1` and updates the flow state to `state2`. |
| 41 | + */ |
| 42 | + predicate isAdditionalTaintStep( |
| 43 | + DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2, |
| 44 | + DataFlow::FlowState state2 |
| 45 | + ) { |
| 46 | + none() |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * A sanitizer for server-side template injection (SST) vulnerabilities. |
| 52 | + */ |
| 53 | +abstract class TemplateInjectionSanitizer extends DataFlow::Node { |
| 54 | + /** Holds if this sanitizer has the specified `state`. */ |
| 55 | + predicate hasState(DataFlow::FlowState state) { state instanceof DataFlow::FlowStateEmpty } |
| 56 | +} |
| 57 | + |
| 58 | +private class DefaultTemplateInjectionSource extends TemplateInjectionSource instanceof RemoteFlowSource { |
| 59 | +} |
| 60 | + |
| 61 | +private class DefaultTemplateInjectionSink extends TemplateInjectionSink { |
| 62 | + DefaultTemplateInjectionSink() { sinkNode(this, "ssti") } |
| 63 | +} |
| 64 | + |
| 65 | +private class DefaultTemplateInjectionSanitizer extends TemplateInjectionSanitizer { |
| 66 | + DefaultTemplateInjectionSanitizer() { |
| 67 | + this.getType() instanceof PrimitiveType or |
| 68 | + this.getType() instanceof BoxedType or |
| 69 | + this.getType() instanceof NumericType |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +private class TemplateInjectionSinkModels extends SinkModelCsv { |
| 74 | + override predicate row(string row) { |
| 75 | + row = |
| 76 | + [ |
| 77 | + "freemarker.template;Template;true;process;;;Argument[0];ssti;manual", |
| 78 | + "freemarker.template;Template;true;Template;(String,Reader);;Argument[1];ssti;manual", |
| 79 | + "freemarker.template;Template;true;Template;(String,Reader,Configuration);;Argument[1];ssti;manual", |
| 80 | + "freemarker.template;Template;true;Template;(String,Reader,Configuration,String);;Argument[1];ssti;manual", |
| 81 | + "freemarker.template;Template;true;Template;(String,String,Reader,Configuration);;Argument[2];ssti;manual", |
| 82 | + "freemarker.template;Template;true;Template;(String,String,Reader,Configuration,String);;Argument[2];ssti;manual", |
| 83 | + "freemarker.template;Template;true;Template;(String,String,Reader,Configuration,ParserConfiguration,String);;Argument[2];ssti;manual", |
| 84 | + "freemarker.template;Template;true;Template;(String,String,Configuration);;Argument[1];ssti;manual", |
| 85 | + "freemarker.cache;StringTemplateLoader;true;putTemplate;;;Argument[1];ssti;manual", |
| 86 | + "com.mitchellbosecke.pebble;PebbleEngine;true;getTemplate;;;Argument[0];ssti;manual", |
| 87 | + "com.mitchellbosecke.pebble;PebbleEngine;true;getLiteralTemplate;;;Argument[0];ssti;manual", |
| 88 | + "com.hubspot.jinjava;Jinjava;true;renderForResult;;;Argument[0];ssti;manual", |
| 89 | + "com.hubspot.jinjava;Jinjava;true;render;;;Argument[0];ssti;manual", |
| 90 | + "org.thymeleaf;ITemplateEngine;true;process;;;Argument[0];ssti;manual", |
| 91 | + "org.thymeleaf;ITemplateEngine;true;processThrottled;;;Argument[0];ssti;manual", |
| 92 | + "org.apache.velocity.app;Velocity;true;evaluate;;;Argument[0];ssti;manual", |
| 93 | + "org.apache.velocity.app;Velocity;true;evaluate;;;Argument[3];ssti;manual", |
| 94 | + "org.apache.velocity,app;VelocityEngine;true;evaluate;;;Argument[0];ssti;manual", |
| 95 | + "org.apache.velocity,app;VelocityEngine;true;evaluate;;;Argument[3];ssti;manual", |
| 96 | + "org.apache.velocity.app;Velocity;true;mergeTemplate;;;Argument[2];ssti;manual", |
| 97 | + "org.apache.velocity.app;VelocityEngine;true;mergeTemplate;;;Argument[2];ssti;manual", |
| 98 | + "org.apache.velocity.runtime.resource.util;StringResourceRepository;true;putStringResource;;;Argument[1];ssti;manual", |
| 99 | + "org.apache.velocity.runtime;RuntimeServices;true;evaluate;;;Argument[0];ssti;manual", |
| 100 | + "org.apache.velocity.runtime;RuntimeServices;true;evaluate;;;Argument[3];ssti;manual", |
| 101 | + "org.apache.velocity.runtime;RuntimeServices;true;parse;;;Argument[0];ssti;manual", |
| 102 | + "org.apache.velocity.runtime;RuntimeSingleton;true;parse;;;Argument[0];ssti;manual", |
| 103 | + "org.apache.velocity;Template;true;merge;;;Argument[0];ssti;manual" |
| 104 | + ] |
| 105 | + } |
| 106 | +} |
0 commit comments