rspec/rules/S5146/java/rule.adoc

39 lines
889 B
Plaintext

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 {
String location = req.getParameter("url");
List<String> allowedHosts = new ArrayList<String>();
allowedUrls.add("https://www.domain1.com/");
allowedUrls.add("https://www.domain2.com/");
if (allowedUrls.contains(location))
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[]