Why this matters
SSRF vulnerabilities allow attackers to manipulate server-side requests, potentially accessing internal resources or exposing sensitive data.
Ensure that server-side requests are properly validated to prevent SSRF attacks.
SSRF vulnerabilities allow attackers to manipulate server-side requests, potentially accessing internal resources or exposing sensitive data.
Side-by-side examples engineers can pattern-match during review.
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
URL url = new URL(location);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}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/");
URL url = new URL(location);
if (allowedHosts.contains(location))
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String location = req.getParameter("url");
URL url = new URL(location);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}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/");
URL url = new URL(location);
if (allowedHosts.contains(location))
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
}From the same buckets as this rule.