An appsettings.json file should be stored as application configuration and protected when it contains connection strings, API keys or other secrets. Keep secrets out of source control where possible, restrict access on build and runtime hosts, and scan for exposed credentials. Separate secret material from non-sensitive settings.
How appsettings.json should be stored
Store appsettings.json as application configuration, not as a secret store. Its safest role is to hold non-sensitive defaults such as feature flags, endpoint names, logging levels, and other values that do not create exposure if read by a wider set of developers or operators. When the file contains secrets, treat it as sensitive configuration and narrow who can read, copy, or deploy it.
The practical distinction is between settings that can be public inside the build and runtime pipeline, and values that change the security posture if leaked. That means the same file can contain harmless configuration and dangerous material, but the file’s handling must follow the most sensitive content it carries. If possible, keep secret values in environment-specific secret stores or managed configuration services rather than embedding them directly in the JSON file.
In .NET deployments, the file often ends up in source trees, build artifacts, container images, and release bundles unless teams deliberately prevent that. The storage model should assume those paths are discoverable by multiple tools and humans. For that reason, the file should be excluded from broad read access where practical, protected at rest on hosts and storage platforms, and handled as part of the application’s configuration boundary rather than as ordinary source text.
What needs to be protected inside the file
Not every value in appsettings.json deserves the same protection. Connection strings, API keys, shared tokens, client secrets, signing material references, and similar credentials need stricter handling than ordinary operational settings. A useful rule is simple: if disclosure would let someone authenticate, call a protected API, or reach a backend service, it belongs in the protected category.
That also means the file should be split conceptually even when it is not split physically. Keep non-sensitive application defaults separate from secret material so you can review, version, and deploy them differently. This reduces accidental exposure during code review, image building, backup, logging, and troubleshooting, where a single monolithic settings file is easy to mishandle.
Build and runtime protection should cover who can read the file, where it is copied, and how it is surfaced in diagnostics. Secret scanning should run against the repository and the delivery pipeline so exposed credentials are detected before release. If the file is stored on servers, restrict file ACLs to the application identity and only the administrators who truly need access for operations or recovery.
When secrets must not be in appsettings.json
If the file contains live production secrets, the safer choice is to move those values out of the repository entirely. Keep them outside source control, inject them at deploy time, and use a store designed for secret handling wherever possible. This is especially important when the same repository is cloned broadly, shared with contractors, or used to build multiple environments.
That separation also matters for drift. A hardcoded secret in appsettings.json tends to propagate into test copies, backups, forks, documentation, and example projects. Once that happens, rotation becomes harder because every copied instance must be found and updated. A central secret source gives you a clearer rotation point and a smaller blast radius if exposure is suspected.
Risk and Threat Considerations
Exposed configuration files are a common source of credential leakage because they are copied widely and are easy to overlook in logs, artifacts, and backups. If an attacker or careless insider gets a readable copy of appsettings.json, the file can become an authentication shortcut into databases, APIs, or internal services.
Failure mechanism: The main failure is secret sprawl, where sensitive values are stored alongside ordinary settings and then copied into source control, build outputs, container layers, deployment bundles, and operational backups. That makes accidental disclosure and unauthorized reuse much more likely.
Impact: A leaked secret can enable unauthorized access, lateral movement into connected systems, and persistent abuse until the secret is rotated and every dependent deployment is updated.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
CIS Controls v8, NIST SP 800-53 Rev 5 and OWASP ASVS set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS-5 — Account Management | Protecting appsettings.json hinges on controlling who can read and use embedded secrets. |
| Recommendation — Restrict access to configuration files and remove unused accounts that can read secrets. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Appsettings.json may contain API keys and shared secrets that require lifecycle protection. |
| AC-6 — Least Privilege | File and host access to configuration with secrets should be limited to only necessary principals. | |
| Recommendation — Manage secrets centrally and rotate them when exposure is suspected. Limit read access to configuration secrets to the smallest necessary set of identities. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access control | The file’s secret-bearing settings need access restriction and controlled handling. |
| Recommendation — Apply access restrictions so only authorized personnel and services can read secret-bearing configuration. | ||
| OWASP ASVS | V14 — Data Protection | Storing secrets in configuration requires protection against disclosure and insecure handling. |
| Recommendation — Keep secret material out of exposed configuration paths and protect sensitive values at rest. | ||
Practitioner Guidance
What to verify: Check whether the current appsettings.json contains any value that grants access to another system, not just whether it “looks like configuration.” If it does, verify that the value is excluded from source control, protected by file permissions or a secret store, and not echoed into build logs, crash dumps, or deployment manifests.
What good looks like: The file holds only non-sensitive defaults, while secrets are injected from a controlled runtime source and can be rotated without editing application code. Teams should be able to show where secret values live, who can read them, and how exposure would be detected and remediated.
Practitioner takeaway: Treat appsettings.json as safe only for non-sensitive configuration; the moment it carries credentials or keys, its storage and access model must follow the security requirements of the most sensitive value inside it.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 17, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org