Rule Definition
Using the * as the value of the Access-Control-Allow-Origin header indicates that the application's data is accessible to JavaScript running on any domain.
Remediation
Donot mention "*" use specific domain
Violation Code Sample
// globally in Web.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
// or in the source code
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
}
// In case of .NetCore app, in Configure method of Startup class:-
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
await next();
});
Fixed Code Sample
// globally in Web.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="domain" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
// or in the source code
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "domain");
}
// In case of .NetCore app, in Configure method of Startup class:-
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "domain");
await next();
});
Reference
OWASP Top 10 2017: A6-Security Misconfiguration
https://www.owasp.org/index.php/Top_10-2017_A6-Security_Misconfiguration
https://cwe.mitre.org/data/definitions/16.html
Related Technologies
Technical Criterion
Secure Coding - Weak Security Features
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.