Skip to content

fix(config): reject misplaced known YAML keys instead of silently dropping them - #563

Open
almeidapaulopt wants to merge 1 commit into
mainfrom
fix/config-strict-misplaced-keys
Open

almeidapaulopt wants to merge 1 commit into
mainfrom
fix/config-strict-misplaced-keys

Conversation

@almeidapaulopt

Copy link
Copy Markdown
Owner

What

Fixes #562.

processStructField (internal/config/keynormalizer.go) looked keys up in a flat, schema-wide canonical map. A key that exists anywhere in the schema but not at the location used — e.g. dashboard: at the root (only valid inside preset templates) or proxyAccessLog under log: (a top-level field) — passed the flat lookup, failed fieldTypeByCanonical, and hit a bare return: silently dropped. The final plain yaml.Unmarshal decode ignored the surviving key too.

v2.3.4 rejected these configs at startup (yaml KnownFields(true)); main regressed that guarantee. Silent no-ops are worse than boot failures: adminAllowLocalhost: true can appear enabled while doing nothing.

Change

Misplaced keys are now reported as unknown-field issues at their line/column, with suggestions scoped to the struct expected at that location — identical treatment to truly unknown keys:

configuration contains unknown fields:
line 22 column 1: unknown field dashboard
line 28 column 3: unknown field proxyAccessLog — did you mean ...?

Verification (TDD)

  1. RED: TestNormalize_RejectsMisplacedKnownKeys added — misplaced dashboard: at root and proxyAccessLog under log: asserted to be rejected. Failed pre-fix (got nil error), including the subtest proving correct top-level placement decodes all values.
  2. GREEN: fix applied — both subtests pass; keynormalizer suite (normalization, fuzzy suggestions, map-scope unknowns, line/column reporting) untouched and green.
  3. Full suite: go test ./... — 25 packages ok, 0 failures. golangci-lint v2.15.0: 0 issues.

Compatibility

  • Truly unknown keys: unchanged (already rejected).
  • Case/separator normalization (clientId/client_id/CLIENTID): unchanged.
  • Map keys (provider/preset names) are user-defined and were never validated — unchanged.
  • No interaction with the files→lists alias (not yet on main; when it lands it rewrites the key before this check).

…pping them

The key normalizer looked keys up in a flat, schema-wide canonical map.
A key that exists anywhere in the schema but not at the location used
(e.g. `dashboard:` at the root — only valid inside preset templates —
or `proxyAccessLog` under `log:` — a top-level field) passed the flat
lookup, failed fieldTypeByCanonical, and was silently dropped.

v2.3.4 rejected these via yaml KnownFields(true); the normalizer
regressed that guarantee: configs booted with the misplaced settings
silently ignored (worse than failing: adminAllowLocalhost could appear
enabled while actually doing nothing).

processStructField now reports such keys as unknown-field issues at
their line/column, with suggestions scoped to the struct expected at
that location — same treatment as truly unknown keys.

Reported with repro in #562.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: misplaced known YAML keys are silently dropped on main (v2.3.4 rejected them)

1 participant