CRITICAL
Rule Definition
The software does not properly neutralize URLs that are used in an request execution, allowing attackers to access internal services or to launch attacks from your web server.
Remediation
Do not accept URLs from users.
Use authorized sanitization methods.
Violation Code Sample
// JEE
String taintedURL = request.getParameter("url");
var url = new URL(taintedURL);
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Violation
// .NET
String taintedURL = request.Item("url");
var client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(taintedUrl); // Violation
Fixed Code Sample
// JEE
String constURL = "https://www.validUrl.com/";
var url = new URL(constURL);
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // OK
// .NET
String constURL = "https://www.validUrl.com/";
var client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(constUrl); // OK
Reference
https://cwe.mitre.org/data/definitions/918.html
https://owasp.org/Top10/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/
https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html
Related Technologies
Technical Criterion
Secure Coding - Input Validation
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.