49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
include::../description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,java]
|
|
----
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
String location = req.getParameter("url");
|
|
resp.sendRedirect(location); // Noncompliant
|
|
}
|
|
----
|
|
[source,java]
|
|
----
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
String location = req.getParameter("url");
|
|
resp.setStatus(302);
|
|
resp.setHeader("Location", location); // Noncompliant
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,java]
|
|
----
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
String location = req.getParameter("url");
|
|
|
|
List<String> allowedHosts = new ArrayList<String>();
|
|
allowedHosts.add("https://www.domain1.com/");
|
|
allowedHosts.add("https://www.domain2.com/");
|
|
|
|
if (allowedHosts.contains(location))
|
|
resp.sendRedirect(location);
|
|
}
|
|
----
|
|
|
|
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[]
|