Why this matters
Allowing user-controlled HTTP redirections enables attackers to redirect victims to malicious websites, commonly used in phishing attacks.
Ensure that user-controlled HTTP redirections are validated to prevent phishing attacks.
Allowing user-controlled HTTP redirections enables attackers to redirect victims to malicious websites, commonly used in phishing attacks.
Side-by-side examples engineers can pattern-match during review.
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
resp.sendRedirect(location);
}protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
List<String> allowedHosts = new ArrayList<String>();
allowedHosts.add("https://trusted1.example.com/");
allowedHosts.add("https://trusted2.example.com/");
if (allowedHosts.contains(location))
resp.sendRedirect(location);
}protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
resp.sendRedirect(location);
}protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
List<String> allowedHosts = new ArrayList<String>();
allowedHosts.add("https://trusted1.example.com/");
allowedHosts.add("https://trusted2.example.com/");
if (allowedHosts.contains(location))
resp.sendRedirect(location);
}From the same buckets as this rule.