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>();  
  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[]
