CRITICAL missing tlsaspnetbasic auth

Missing Tls in Aspnet with Basic Auth

Missing Tls in Aspnet with Basic Auth — how this specific combination creates or exposes the vulnerability

Transport Layer Security (TLS) is the baseline network security control that protects data in transit. When an ASP.NET API that uses HTTP Basic Authentication lacks TLS, credentials and session tokens are exposed as plaintext across the network. Basic Authentication encodes a username and password using Base64, which is trivial to decode; without TLS, any intermediary between client and server can observe and decode the header.

This combination is particularly dangerous because Basic Auth credentials are static and often reused across services. An attacker performing passive sniffing on a shared network or via a compromised access point can capture the Authorization header and immediately reuse it to impersonate the victim (credential replay). Passive sniffing tools can collect these unprotected headers at scale, enabling offline password cracking if users have chosen weak passwords.

Active network attacks are also severe. An on-path attacker can execute a man-in-the-middle (MITM) to modify requests or inject malicious content. Without TLS, there is no server identity assurance, so clients may unknowingly send credentials to an impostor. In cloud and containerized environments, misconfigured load balancers or ingress that terminate TLS inconsistently can leave backend HTTP endpoints exposed, allowing attackers who gain network access to intercept Basic Auth traffic.

ASP.NET applications that expose endpoints over HTTP while advertising Basic Auth are effectively publishing credentials in the clear. Scanning tools detect this by checking whether the service is served over HTTPS and whether Strict-Transport-Security (HSTS) is present; without these protections, the risk score for authentication-related controls is severely degraded. Findings will highlight the lack of TLS as a critical vector that undermines the already weak security posture of Basic Auth.

Basic Auth-Specific Remediation in Aspnet — concrete code fixes

Remediation focuses on enforcing TLS and replacing Basic Auth with more secure mechanisms. At minimum, all endpoints must be served over HTTPS with valid certificates and HSTS to prevent protocol downgrade attacks. Below are concrete steps and code examples for an ASP.NET Core application.

1. Enforce HTTPS in ASP.NET Core

Configure the application to redirect HTTP to HTTPS and require HTTPS for all requests. In Program.cs, ensure the following setup:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHsts(options =>
{
    options.MaxAge = TimeSpan.FromDays(365);
    options.IncludeSubDomains = true;
    options.Preload = true;
});

var app = builder.Build();
app.UseHsts();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

This configuration ensures that browsers request HTTPS and that HSTS headers are emitted, reducing the chance of accidental cleartext HTTP access.

2. Replace Basic Auth with token-based authentication

Basic Auth should be removed in favor of bearer tokens or API keys transmitted over TLS. If you must use Basic Auth temporarily, ensure credentials are rotated frequently and scoped to minimal privileges. Below is an example of using JWT Bearer authentication instead:

// Program.cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,
            ValidIssuer = builder.Configuration["Jwt:Issuer"],
            ValidAudience = builder.Configuration["Jwt:Audience"],
            IssuerSigningKey = new SymmetricSecurityKey(
                Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
        };
    });

app.UseAuthentication();
app.UseAuthorization();

Client requests must then include Authorization: Bearer <token> instead of the Basic Auth format. This approach eliminates the repeated transmission of static credentials and enables fine-grained access control.

3. If Basic Auth is unavoidable, enforce TLS and strict transport policies

Should your scenario require Basic Auth (for example, integration with legacy systems), enforce TLS at the load balancer or ingress and reject cleartext HTTP. In ASP.NET, you can also add middleware to reject non-HTTPS requests explicitly:

app.Use(async (context, next) =>
{
    if (!context.Request.IsHttps)
    {
        context.Response.StatusCode = StatusCodes.Status400BadRequest;
        await context.Response.WriteAsync("HTTPS required.");
        return;
    }
    await next.Invoke();
});

Combine this with network-level controls such as TLS termination enforcement and firewall rules that block plain HTTP. Monitor and log any HTTP attempts as security events. Note that these are mitigations, not fixes; long-term migration away from Basic Auth is strongly recommended.

Related CWEs: encryption

CWE IDNameSeverity
CWE-319Cleartext Transmission of Sensitive Information HIGH
CWE-295Improper Certificate Validation HIGH
CWE-326Inadequate Encryption Strength HIGH
CWE-327Use of a Broken or Risky Cryptographic Algorithm HIGH
CWE-328Use of Weak Hash HIGH
CWE-330Use of Insufficiently Random Values HIGH
CWE-338Use of Cryptographically Weak PRNG MEDIUM
CWE-693Protection Mechanism Failure MEDIUM
CWE-757Selection of Less-Secure Algorithm During Negotiation HIGH
CWE-261Weak Encoding for Password HIGH

Frequently Asked Questions

Does middleBrick detect missing TLS when Basic Auth is used?
Yes. middleBrick runs unauthenticated scans that check for HTTPS presence and HSTS headers; findings include missing TLS as a critical risk alongside the use of Basic Auth, with remediation guidance to enforce HTTPS and replace Basic Auth.
Can I rely on Basic Auth over TLS as a secure authentication mechanism?
While TLS protects credentials in transit, Basic Auth still transmits static credentials with every request, lacks replay protection, and does not provide fine-grained scopes. middleBullet findings will highlight this; prefer token-based authentication such as JWT Bearer or OAuth2 over Basic Auth, even when TLS is enforced.