
JGe356144 (Community Member) asked a question.
VeraCode scan reported several CWE 601(URL Redirection to Untrusted Site ('Open Redirect')) flaws in our application. Following the guideline in VeraCode site, I have put in the code to check if the URL is local URL before redirecting.
[RedirectUrlCleanser]
private bool IsLocalUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return false;
}
return Url.IsLocalUrl(url);
}
In the application code,
var requestFrom = Request.QueryString["requestFrom"];
if (IsLocalUrl(requestFrom))
{
return Redirect(requestFrom);
}
return RedirectToAction("ContentManagement", "Admin");
VeraCode scan still report the same flaw on line "return Redirect(requestFrom)". Is there anything I did wrong? Why does VeraCode scan recognize the fix?
Thanks.
.png)
Hi @JGe356144 (Community Member) ,
Great question! Once the custom cleanser feature is enabled for your account, the Security Lead or Veracode Administrator will need to decide on what should happen when the Veracode Platform sees a Veracode Annotation within your application scan. Here are the 3 possible options:
For more information on custom cleansers, please review https://community.veracode.com/s/article/How-To-Use-Custom-Cleanser .
Based on your description, either the default setting of "None" is still in place for your account or you might already find some auto-proposed mitigations for these flaws, which need to be approved by your security team for the flaw to not affect your policy anymore.
Thank you,
Florian Walter
Thanks for the reply. Yes, they are in the proposed state. However, the code I put in should solve the issue, not only propose the mitigation.
Url.IsLocalUrl() is VeraCode approved method to solve the URL redirect issue. I expected VeraCode scan recognized the code and remove the issues.
Thanks,
Jason
Hi @JGe356144 (Community Member) ,
Url.IsLocalUrl() is a decent way to deal with CWE 601 (URL Redirection to Untrusted Site ('Open Redirect')). The reason why Veracode Static Analysis still flags this is that you outsource the check into an external function. For a human, it is very easy to see in your example that all control-flow paths either involve the Url.IsLocalUrl() check or make sure that a passed URL is null or whitespace, i.e. cannot be malicious. But for static analysis, this is very hard. I recommend that you move the Url.IsLocalUrl() close to the actual redirect, which should automatically close the flaw. For example:
if (Url.IsLocalUrl(url))
{
return Redirect(url); // Should not be flagged by our engine
}
If that is not an option, then using the custom cleanser like you already do might be a proper solution for you.
Thank you,
Florian Walter
Hi Florian,
Your last recommendation of moving Url.IsLocalUrl() close doesn't align with the idea of Custom Attribute based cleaning methods.
We are thinking of creating the set of 100% effective custom cleansers for Redirect , 117 Log cleaning and get that reviewed by our security team and then get a 3. Approve settings so that we don't need to worry during each code change. Just imagine a line is changed on a controller and all the mitigated issues has to be readdressed!
So we are looking to get an method which will satisfy the scanner and Url.IsLocalUrl() is a recommended cleanser method. Do we need to add anything more? Clean up on the requestFrom to remove any suspicious values - or put some other cleaning methods on requestFrom?
var requestFrom = Request.QueryString["requestFrom"];
Hi @NM257998 (Community Member), makes sense. The way Veracode Static Analysis works is that in case of doubt, it rather risks reporting a false-positive flaw than missing out on any actual flaw. Scenarios like the one you describe are the main reason for custom cleansers. I don't see an easy way to make our engine close this flaw automatically as it involves if-else checks as well as interprocedural flow and our engine would only close it if it can guarantee that all data-flow paths go through the cleansing function (i.e. Url.IsLocalUrl()).
I recommend that you use the custom cleanser, get it looked at and approved by your security team, and then you don't need to worry about it anymore. Our static engine will remember all approved mitigations and match them through subsequent scans, as long as the underlying logic doesn't change significantly.
Thank you,
Florian Walter