logo

Database

C Sharp Basic Auth Header Hardcoded Credentials

Description

Detects hardcoded Basic Authentication credentials in HTTP request headers in C# applications. Using hardcoded credentials in source code exposes sensitive authentication information that could be exploited by attackers to gain unauthorized access to protected resources.

Weakness:

015 - Insecure authentication method - Basic

Category: Protocol Manipulation

Detection Strategy

    Identifies calls to Headers.Add() method on web request objects

    Checks if the header being added contains Basic Authentication credentials

    Verifies that the header value contains hardcoded credentials rather than dynamic/configurable values

    Reports a vulnerability when Basic Authentication credentials are directly embedded in the source code

Vulnerable code example

using System.Net;

public class UnsafeRequest {
    public WebResponse CreateRequest() {
        WebRequest request = WebRequest.Create("https://api.example.com");
        request.Method = "POST";
        // VULNERABLE: Hardcoded credentials in Authorization header
        request.Headers.Add("Authorization", "Basic dXNlcjpwYXNz");...

✅ Secure code example

using System;
using System.Net;

public class SafeRequest {
    private readonly string _apiUrl;
    
    public SafeRequest(string apiUrl) {
        _apiUrl = apiUrl;...