Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/demo/security/servlet/TemplateServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package demo.security.servlet;

import org.apache.commons.text.StringSubstitutor;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/template")
public class TemplateServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response)

Check warning on line 16 in src/main/java/demo/security/servlet/TemplateServlet.java

View check run for this annotation

Sonar-Nautilus / SonarQube Code Analysis

Add the "@Override" annotation above this method signature

[S1161] "@OverRide" should be used on overriding and implementing methods See more on https://nautilus.sonarqube.org/project/issues?id=demo%3Ajava-security&pullRequest=83&issues=d5b63785-11b8-4d9e-8df2-1f44f704455d&open=d5b63785-11b8-4d9e-8df2-1f44f704455d
throws ServletException, IOException {
String template = request.getParameter("template");
// CVE-2022-42889: StringSubstitutor with user-controlled input allows
// arbitrary code execution via script/dns/url lookups
String result = StringSubstitutor.replaceSystemProperties(template);
response.setContentType("text/html");
PrintWriter out = response.getWriter();

Check warning on line 23 in src/main/java/demo/security/servlet/TemplateServlet.java

View check run for this annotation

Sonar-Nautilus / SonarQube Code Analysis

Handle the following exception that could be thrown by "getWriter": IOException.

[S1989] Exceptions should not be thrown from servlet methods See more on https://nautilus.sonarqube.org/project/issues?id=demo%3Ajava-security&pullRequest=83&issues=c383c553-5a53-42ee-bdbc-8617edf7997a&open=c383c553-5a53-42ee-bdbc-8617edf7997a

Check notice

Code scanning / SonarQube

Exceptions should not be thrown from servlet methods Low

Handle the following exception that could be thrown by "getWriter": IOException. See more on SonarQube
Comment thread
cole-gannaway-sonarsource marked this conversation as resolved.
Dismissed
out.print("<p>" + result + "</p>");
out.close();
}
}