1. Home
  2. Web App Vulnerabilities
  3. How to remediate – ASP.NET Core Configuration File Detected

How to remediate – ASP.NET Core Configuration File Detected

1. Introduction

The ASP.NET Core Configuration File Detected vulnerability involves the potential exposure of sensitive information stored in `appsettings.json` and related configuration files used by ASP.NET Core applications. Attackers gaining access to these files could obtain secrets, leading to unauthorized privileged access to web application components. This affects confidentiality, integrity, and availability. Systems running ASP.NET Core applications are typically affected.

2. Technical Explanation

ASP.NET Core applications use configuration files like `appsettings.json` to store settings. Developers may unintentionally include sensitive data such as passwords or API keys in these files. If the application is deployed with these files accessible via a web server, an attacker can retrieve them and compromise the system. The vulnerability arises from predictable resource location (CWE-16, CWE-538). An example exploit involves directly accessing `appsettings.json` through a browser or using tools like `curl`.

  • Root cause: Sensitive data stored in publicly accessible configuration files.
  • Exploit mechanism: An attacker requests the configuration file via HTTP/HTTPS and retrieves its contents.
  • Scope: ASP.NET Core applications deployed with exposed configuration files are affected.

3. Detection and Assessment

To confirm vulnerability, first check if `appsettings.json` is accessible through a web browser. A thorough method involves scanning the deployment directory for sensitive data within configuration files.

  • Quick checks: Attempt to access `https://yourdomain.com/appsettings.json` in a web browser.
  • Scanning: Use tools like truffleHog or gitleaks to scan the repository and deployed environment for secrets. These are examples only, results should be verified manually.
  • Logs and evidence: Check web server logs for requests to `appsettings.json`.
curl https://yourdomain.com/appsettings.json

4. Solution / Remediation Steps

The following steps outline how to fix the issue by preventing access to configuration files and using secure secret storage practices.

4.1 Preparation

  • Ensure you have a rollback plan in case of issues, such as restoring from backup.

4.2 Implementation

  1. Step 1: Configure the web server to deny direct access to `appsettings.json` and other configuration files. This can be done through web server configuration (e.g., IIS URL Rewrite rules, Nginx configuration).
  2. Step 2: Implement Microsoft’s recommended secret storage practices using environment variables or Azure Key Vault.
  3. Step 3: Remove any hardcoded secrets from the `appsettings.json` file.

4.3 Config or Code Example

Before

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=yourserver;Database=yourdatabase;User Id=youruser;Password=yourpassword;"
  }
}

After

{
  "ConnectionStrings": {
    "DefaultConnection": ""
  }
}

4.4 Security Practices Relevant to This Vulnerability

Several security practices can help prevent this issue. Least privilege reduces the impact of compromised credentials. Input validation prevents attackers from manipulating configuration data. Secure defaults ensure that sensitive information is not exposed by default. Patch cadence ensures timely updates and mitigations.

  • Practice 1: Implement least privilege to limit access to sensitive files and resources.
  • Practice 2: Avoid storing secrets directly in configuration files; use secure secret storage mechanisms like environment variables or Key Vault.

4.5 Automation (Optional)

Automation can be used to scan for exposed secrets during deployment. This example uses a simple PowerShell script to check if `appsettings.json` is accessible.

# Check if appsettings.json is accessible via HTTP/HTTPS
$url = "https://yourdomain.com/appsettings.json"
try {
    $response = Invoke-WebRequest -Uri $url -ErrorAction Stop
    Write-Host "Warning: appsettings.json is publicly accessible!"
} catch {
    Write-Host "appsettings.json is not publicly accessible."
}

5. Verification / Validation

Confirm the fix by verifying that `appsettings.json` is no longer accessible via a web browser and that secrets are stored securely. Perform a smoke test to ensure application functionality remains intact.

  • Post-fix check: Attempt to access `https://yourdomain.com/appsettings.json` in a web browser; expect a 403 Forbidden or similar error.
  • Re-test: Re-run the curl command from step 3 and confirm it fails.
  • Smoke test: Verify that application login, data retrieval, and other key functions work as expected.
  • Monitoring: Monitor web server logs for any attempts to access configuration files.
curl https://yourdomain.com/appsettings.json - should return 403 Forbidden

6. Preventive Measures and Monitoring

Update security baselines to include restrictions on accessing sensitive files. Incorporate SAST or SCA tools into CI pipelines to detect hardcoded secrets during development. Implement a regular patch review cycle to address vulnerabilities promptly.

  • Baselines: Update your web server baseline configuration to deny access to `.json` config files.
  • Pipelines: Add static application security testing (SAST) tools to your CI/CD pipeline to detect secrets in code and configuration.
  • Asset and patch process: Review configurations regularly for exposed credentials or sensitive data.

7. Risks, Side Effects, and Roll Back

  • Risk or side effect 1: Applications relying on direct access to `appsettings.json` may fail if not updated.
  • Risk or side effect 2: Incorrectly configured secret storage can lead to application downtime.
  • Roll back: Restore the web server configuration from backup and redeploy the original application version.

8. References and Resources

Links to official advisories and trusted documentation related to this vulnerability.

Updated on October 26, 2025

Was this article helpful?

Related Articles