How to Compare .env and Configuration Files Without Exposing Secrets

Compare keys, types and references across environments while keeping values masked, then export a reviewable report or .env.example safely.

On this page

Comparing configuration files sounds simple until those files contain secrets, environment-specific values and different formats. A useful comparison should tell you which keys are missing, extra, different or malformed without turning the review process into a new way to leak credentials.

Config Doctor is an offline Windows utility for .env, JSON, YAML, TOML and INI files. It masks values by default and can compare files or compare an actual configuration against a baseline such as .env.example.

Try the verified Config Doctor walkthrough with three sample files and two masked reports.

Decide what question you are asking

Configuration comparison can mean several things:

  • Are the same keys present in development and production?
  • Is a new deployment missing required-looking settings?
  • Did a value change between two files?
  • Are types inconsistent between environments?
  • Does an actual .env still match the expected template?
  • Are variable references unresolved or cyclic?

Define the question first. A raw text diff often produces noise from ordering, whitespace and formatting that is unrelated to configuration meaning.

Keep secrets out of screenshots and reports

Configuration files commonly contain passwords, API keys, tokens, connection strings and private endpoints.

Treat the entire file as potentially sensitive even if you only expect harmless settings.

A safer workflow is:

  1. process files locally;
  2. keep values masked during review;
  3. reveal a value only when you actually need it;
  4. avoid copying full configurations into chat, tickets or public issues;
  5. export masked reports unless there is a specific approved reason to include values.

Config Doctor works offline, does not upload files and masks configuration values by default.

Compare normalized keys, not only lines

Two configuration files can represent the same settings with different ordering or formatting. A line-by-line diff can make that look more dramatic than it is.

A normalized comparison focuses on configuration paths and values.

For example, these JSON objects differ in formatting but not meaning:

{"api":{"timeout":30,"enabled":true}}

and a multi-line version with the same keys and values.

A structural comparison can identify api.timeout and api.enabled rather than treating every formatting difference as a change.

Config Doctor normalizes supported formats and shows hierarchical paths, including explicit array indexes where applicable.

Compare presence separately from value differences

A missing key is different from a key whose value changed.

Useful categories include:

  • missing from one side;
  • extra on one side;
  • present on both sides but with different values;
  • type mismatch;
  • empty value;
  • syntax error.

This distinction helps avoid bad conclusions. An extra key in production may be intentional. A missing key in an old template may not mean the application is broken. A type mismatch can be more important than a text difference.

Use the comparison as evidence, then check the application’s real configuration requirements.

Use a baseline carefully

A template such as .env.example is useful because it documents expected configuration names without containing real secrets.

But template membership is not proof that every key is mandatory. Some settings may be optional, obsolete or environment-specific.

Config Doctor therefore separates baseline comparison findings rather than declaring every missing template key an application failure.

A practical baseline workflow is:

  1. load the actual configuration;
  2. load the template or known-good baseline;
  3. review missing baseline keys;
  4. review extra keys separately;
  5. confirm requirements against application documentation;
  6. update the template when the application contract has genuinely changed.

Reproduce missing keys and an unresolved reference

This walkthrough uses the public Config Doctor v1.1.0 ZIP on Windows. The practice files contain synthetic settings and a fake token marker. Keep your real configuration files separate from the exercise.

1. Load and compare the files

Extract the practice ZIP into its own folder. Open Config Doctor, select Add files, and add .env.example, actual.env and corrected.env. If the file picker hides .env.example, enter its full path in the Add files dialog. Select Baseline in the sidebar. Choose actual.env as the actual file and .env.example as the template. The results update when you select the files. Leave Reveal values off.

Config Doctor Baseline view with two missing keys and one unresolved reference
The initial comparison reports two missing keys and one unresolved reference.

2. Read the findings and save a masked report

  • Missing — LOG_LEVEL and SERVICE_HOST are listed in the template but absent from actual.env. The template records expected names. Consult the application’s configuration documentation to determine which keys it requires.
  • Unresolved reference — SERVICE_URL is present and refers to ${SERVICE_HOST}. The referenced key must be defined in the same file for this diagnostic to clear. Config Doctor does not consult other files or Windows environment variables for this check.
  • Extra — DEMO_FEATURE exists only in the actual file. An extra key is informational. Keep it if the application uses it.
  • Possible secret — the name DEMO_API_TOKEN triggers the check even though its sample value is fake. Treat this check as a prompt to review the file.

Select Export report and choose JSON. Leave Include values (may expose secrets) unchecked. Choose a new destination, review the preview and select I reviewed this preview and confirm saving to the selected new file. Scroll inside the dialog if needed, then select Save reviewed report…. Even with values masked, review the filenames, key names and diagnostics before sharing your own report.

Config Doctor JSON report preview with mask values enabled and include values unchecked
The preview masks configuration values before the report is saved.

3. Compare the corrected copy

In a real configuration, use the level and host documented by the application. For this exercise, corrected.env adds LOG_LEVEL=info and SERVICE_HOST=https://example.invalid. The host is a placeholder for demonstrating the reference check. Select corrected.env as the actual file and keep .env.example as the template. Export another masked JSON report to a new file.

Baseline finding actual.env corrected.env
Missing keys 2 0
Present baseline keys 3 5
Extra keys 1 1
Unresolved references 1 0
Config Doctor comparing corrected.env with .env.example showing zero missing keys and unresolved references
The corrected copy resolves the reference and retains the extra key.

Both JSON files above were exported from Config Doctor. To reproduce the check, compare baseline.counts and the row for SERVICE_URL in the two reports. Both exports have includesValues set to false. SHA-256 checks confirmed that all three input files stayed byte-for-byte unchanged. These results verify the file comparison and reference check. They do not establish that an application can start or connect using the sample settings.

Generate .env.example without copying secret values

A good .env.example shows variable names and perhaps safe placeholders, not production secrets.

If your project lacks a current example file, generate one from the actual key set while removing real values. Review the preview before saving.

Do not publish an example file blindly. Key names themselves can reveal architecture, vendor names or internal services. That is usually much safer than leaking values, but it is still information worth reviewing before public release.

Config Doctor creates a preview and will not silently overwrite an existing destination.

Check variable references in .env files

Environment files can reference other variables. A configuration may look complete while still containing an undefined reference or a cycle.

Conceptually:

API_URL=${BASE_URL}/api

needs BASE_URL to exist in the intended resolution context.

To reproduce a circular reference, save these two lines in a separate file named cycle.env and add it to Config Doctor:

A=${B}
B=${A}

In the file diagnostics, look for the cyclic reference warning. Config Doctor flags the reference that closes the loop. Each key exists, but following either reference leads back to the starting key. Replace B=${A} with B=demo in a new copy, then add that copy and check that its cycle warning is gone. Config Doctor inspects the references without executing the file or expanding its values.

Config Doctor can diagnose bare and braced .env references and report undefined references or cycles without needing to display the secret values themselves.

This is diagnostic information, not a guarantee that every runtime or framework resolves variables identically. Confirm behavior against the application that will consume the file.

Compare types when the format supports them

JSON, YAML and TOML can represent types such as booleans, numbers, arrays and objects. A string "true" is not necessarily the same as boolean true.

Configuration bugs often come from values that look right to a human but have the wrong type for the parser or application.

When a comparison reports a type mismatch, investigate it even if the visible text seems similar.

.env files are more text-oriented, so type interpretation may happen later in the consuming application.

A practical environment comparison workflow

Suppose you have development and production configurations.

  1. Make read-only copies if the originals are managed by a deployment system.
  2. Load both files locally.
  3. Keep values masked.
  4. Resolve syntax errors first.
  5. Review missing and extra keys.
  6. Review type mismatches.
  7. Review changed values only where the change matters.
  8. Check .env references if applicable.
  9. Export a masked report for the ticket or handover.
  10. Make actual configuration changes through the normal deployment process, not by editing production files casually from the comparison tool.

The comparison should support the operational process, not replace it.

Possible-secret detection is only a hint

Tools can flag key names or values that resemble secrets, but secret detection is heuristic.

A harmless string can be flagged. A real credential can be missed. Do not use the absence of a warning as proof that a report is safe to publish.

Review every report before sharing it outside the intended audience.

Be cautious with unsupported YAML structures

YAML is especially flexible. Anchors, tags and complex structures can behave differently across parsers.

Config Doctor deliberately supports a conservative subset rather than pretending every YAML feature can be normalized safely. If a file uses unsupported constructs, use the project’s native parser or configuration tooling for authoritative interpretation.

Do not overwrite configuration during diagnosis

A comparison tool is most useful when it is observational. Keep diagnosis separate from deployment changes.

Export reports and examples to new files. Apply real configuration changes through version control, secret-management systems, deployment tooling or the process your project already uses.

That gives you an audit trail and reduces the chance of fixing one environment while accidentally breaking another.

The core principle is: compare structure and meaning locally, keep values masked, confirm requirements against the application, and share only the minimum configuration information needed to solve the problem.

Related ALMARFELD software: Config Doctor

These guides explain practical workflows and limits; they are not a substitute for the policy, legal or security requirements of the organization receiving your files.

← All practical Windows guides · About the project · Contact ALMARFELD