My company uses a security scan tool called Snyk to scan code for security vulnerabilities.
It is complaining about a Server-Side Request Forgery (SSRF)
vulnerability.
The details says Unsanitized input from a SOQL statement flows into setendpoint, where it is used as an URL to perform a request. This may result in a Server-Side Request Forgery vulnerability.
Here is what the code looks like:
String endpointWithParams = String.format('{0}/{1}', new String[] { constants.API_URL, String.escapeSingleQuotes(subscriptionId) });
HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + accessToken);
request.setHeader('Content-Type', 'application/json');
request.setMethod('DELETE');
request.setEndpoint(endpointWithParams); // <- THIS IS THE LINE TRIGGERING THE VULERABILITY
It is all coming from the variable subscriptionId
which is coming from an object returned by a SOQL query. As you see above I tried to wrap the subscriptionId
is a call to String.escapeSingleQuotes
but no luck.
What am I missing? How do I sanitize the input?