
VM116164 (Community Member) asked a question.
I am Sitecore developer and in our website we have a form carrying Re-Captcha. When we are validating our solution in Veracode, at GetResponse the CWE 918 flaw is raised. Adding the code below.
public bool IsReCaptchValid()
{
var result = false;
var captchaResponse = Request.Form["g-recaptcha-response"];
var secretKey = ConfigurationManager.AppSettings["SecretKey"];
var apiUrl = "https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}";
var requestUri = string.Format(apiUrl, secretKey, captchaResponse);
var request = (HttpWebRequest)WebRequest.Create(requestUri);
using(WebResponse response = request.GetResponse())
{
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
JObject jResponse = JObject.Parse(stream.ReadToEnd());
var isSuccess = jResponse.Value<bool>("success");
result = (isSuccess) ? true : false;
}
}
return result;
}
The flaw is thrown in the first line of the code, "request.GetResponse()". How to validate the Response? Thanks in advance.
.png)
Hi @VM116164 (Community Member) ,
Veracode Static Analysis reports a flaw of CWE 918 when it can find that data from outside of the application is going into an HTTP Request done by the application. The concern is that this data may be able to influence the request sent and allow an attacker to get more information or bypass controls.
In the given example the URL appears to take in a "g-recaptcha-response" variable from the request.
We'd recommend URLencoding that (and any variable you use in a URL) using a Supported Cleansing Function ( https://help.veracode.com/reader/4EKhlLSMHm5jC8P8j3XccQ/IiF_rOE79ANbwnZwreSPGA ) and then documenting this in a mitigation ( https://help.veracode.com/go/improve_mitigation ) and contacting your security team for a review of this mitigation.
(Veracode Static Analysis cannot automatically approve CWE 918 flaws when URLEncoding is used as this is only valid for URL variables, not when used on a hostname)
Thank you,
Boy Baukema