rspec/rules/S5146/java/rule.adoc

39 lines
889 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
== Noncompliant Code Example
----
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
resp.sendRedirect(location); // Noncompliant
}
----
== Compliant Solution
----
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
2021-05-21 01:24:06 +00:00
String location = req.getParameter("url");
2020-06-30 12:50:28 +02:00
2021-05-21 01:24:06 +00:00
List<String> allowedHosts = new ArrayList<String>();
allowedUrls.add("https://www.domain1.com/");
allowedUrls.add("https://www.domain2.com/");
2020-06-30 12:50:28 +02:00
2021-05-21 01:24:06 +00:00
if (allowedUrls.contains(location))
2020-06-30 12:50:28 +02:00
resp.sendRedirect(location); // Compliant
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]