C Sharp Cors Wildcard Origin Http Request
Description
Detects insecure CORS configurations in C# applications where wildcard origins (*) are set in HttpWebRequest headers. This creates a security risk by allowing any domain to make cross-origin requests to the application, potentially exposing sensitive data to malicious websites.
Detection Strategy
• Check if the System.Net namespace is imported in the C# code
• Look for header modifications on HttpWebRequest objects
• Identify CORS-related headers (e.g. Access-Control-Allow-Origin)
• Flag cases where the header value is set to a wildcard (*) which allows any origin
• Report a vulnerability when CORS headers are configured with unrestricted wildcard origins
Vulnerable code example
using System.Net;
public void MakeRequest()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.example.com");
// Vulnerable: Using wildcard allows any origin to access the API
request.Headers["Access-Control-Allow-Origin"] = "*";
request.Headers["Access-Control-Allow-Methods"] = "GET,POST,PUT,DELETE";...✅ Secure code example
using System.Net;
public void MakeRequest()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.example.com");
// Safe: Restricting access to specific trusted origin
request.Headers["Access-Control-Allow-Origin"] = "https://trusted-client.example.com";
// Safe: Limiting allowed methods to only those needed...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.