Modify rule S5496: Add an how to fix session for Java and Groovy (APPSEC-1587) (#3900)
This commit is contained in:
parent
def7b6c0ee
commit
ab6bf73b3f
@ -24,31 +24,32 @@
|
|||||||
* Xerces
|
* Xerces
|
||||||
* libxml2
|
* libxml2
|
||||||
// Java
|
// Java
|
||||||
|
* Android
|
||||||
* Apache Commons
|
* Apache Commons
|
||||||
|
* Apache Commons
|
||||||
|
* Apache Commons Email
|
||||||
|
* Apache HttpClient
|
||||||
|
* Auth0 JWT
|
||||||
|
* Commons Compiler
|
||||||
|
* Dom4j
|
||||||
|
* FasterXML
|
||||||
|
* Groovy
|
||||||
|
* Gson
|
||||||
|
* Hibernate
|
||||||
|
* Java Cryptography Extension
|
||||||
|
* Java EE
|
||||||
|
* Java JWT
|
||||||
|
* Java SE
|
||||||
|
* Jdom2
|
||||||
* JSP
|
* JSP
|
||||||
|
* Legacy Mongo Java API
|
||||||
|
* OkHttp
|
||||||
|
* Realm
|
||||||
* Servlet
|
* Servlet
|
||||||
* Spring
|
* Spring
|
||||||
* Spring Data Redis
|
* Spring Data Redis
|
||||||
* Thymeleaf
|
|
||||||
* Java SE
|
|
||||||
* Java EE
|
|
||||||
* Hibernate
|
|
||||||
* Apache Commons
|
|
||||||
* Commons Compiler
|
|
||||||
* Legacy Mongo Java API
|
|
||||||
* FasterXML
|
|
||||||
* Gson
|
|
||||||
* Android
|
|
||||||
* Dom4j
|
|
||||||
* Jdom2
|
|
||||||
* OkHttp
|
|
||||||
* Java JWT
|
|
||||||
* Auth0 JWT
|
|
||||||
* Apache Commons Email
|
|
||||||
* SQLCipher
|
* SQLCipher
|
||||||
* Realm
|
* Thymeleaf
|
||||||
* Java Cryptography Extension
|
|
||||||
* Apache HttpClient
|
|
||||||
// JS
|
// JS
|
||||||
* Flow.js
|
* Flow.js
|
||||||
* Node.js
|
* Node.js
|
||||||
|
47
rules/S5496/java/how-to-fix-it/groovy.adoc
Normal file
47
rules/S5496/java/how-to-fix-it/groovy.adoc
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
== How to fix it in Groovy
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
|
||||||
|
The following code example is vulnerable to a Server-Side Template Injection
|
||||||
|
attack because it builds a template string from a user input without control or
|
||||||
|
sanitation.
|
||||||
|
|
||||||
|
[source,java,diff-id=21,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
@GetMapping("/example")
|
||||||
|
public String example(@RequestParam("title") String title) throws CompilationFailedException, ClassNotFoundException, IOException {
|
||||||
|
String templateString = "h1('" + title + "')";
|
||||||
|
TemplateConfiguration config = new TemplateConfiguration();
|
||||||
|
MarkupTemplateEngine engine = new MarkupTemplateEngine(config);
|
||||||
|
Template template = engine.createTemplate(templateString); // Noncompliant
|
||||||
|
Writable out = template.make();
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,java,diff-id=21,diff-type=compliant]
|
||||||
|
----
|
||||||
|
@GetMapping("/example")
|
||||||
|
public String example(@RequestParam("title") String title) throws CompilationFailedException, ClassNotFoundException, IOException {
|
||||||
|
String templateString = "h1(title)";
|
||||||
|
|
||||||
|
Map<String, Object> ctx = new HashMap<>();
|
||||||
|
ctx.put("title", title);
|
||||||
|
|
||||||
|
TemplateConfiguration config = new TemplateConfiguration();
|
||||||
|
MarkupTemplateEngine engine = new MarkupTemplateEngine(config);
|
||||||
|
Template template = engine.createTemplate(templateString);
|
||||||
|
Writable out = template.make(ctx);
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
=== How does this work?
|
||||||
|
|
||||||
|
The compliant code example uses a template binding to pass user information to
|
||||||
|
the template. The rendering engine then ensures that this tainted data is
|
||||||
|
processed in a way that will not change the template semantics.
|
@ -8,6 +8,8 @@ include::../impact.adoc[]
|
|||||||
|
|
||||||
include::how-to-fix-it/spring.adoc[]
|
include::how-to-fix-it/spring.adoc[]
|
||||||
|
|
||||||
|
include::how-to-fix-it/groovy.adoc[]
|
||||||
|
|
||||||
|
|
||||||
== Resources
|
== Resources
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user