Skip to content

Preserve safe app-config validation diagnostics - #496

Open
prk-Jr wants to merge 2 commits into
mainfrom
fix/457-safe-config-diagnostics
Open

prk-Jr wants to merge 2 commits into
mainfrom
fix/457-safe-config-diagnostics

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve explicitly approved validation codes, structural paths, and fixed operator explanations when typed app-config extraction rejects a configuration, including a missing compiled implementation.
  • Share bounded approval and redaction between runtime extraction and CLI validate/push/diff. Never retain validator messages or parameters; redact unknown field names and keep public HTTP responses coarse.
  • Add extraction, logging, CLI, adapter-contract, and boundary coverage, plus a separate CI refusal control that workspace feature unification cannot skip.

Integration note: a current git merge-tree comparison with #509, #512, #514 and #515 reports conflicts in Axum response conversion, Cloudflare/Spin contracts, and core error/extractor code. These siblings need reconciliation when integrated.

Changes

Crate / File Change
edgezero-core/config_diagnostics Static path/code approval registry, bounded traversal and output, safe operator reports, and shared extraction contract fixture
edgezero-core/app_config and edgezero-macros Default-empty metadata and optional #[app_config(diagnostics = REGISTRY)] root registration
edgezero-core/extractor, error, and middleware Preserve approved diagnostics through a new opt-in ConfigValidation error and operator accessor; keep HTTP 503, config_out_of_date, and Retry-After: 60
edgezero-cli/config Apply the shared sanitizer after existing secret-validator pruning in typed validate, push, and diff
Axum, Fastly, Cloudflare, and Spin contracts Exercise extraction and response conversion without exposing diagnostic explanations or value canaries publicly
.github/workflows/test.yml Run the core compiled-implementation refusal test separately without test-utils
Configuration/migration guides and design/plan Document registration, limits, CLI/guest feature alignment, and compatibility changes

Unknown validator field names are now redacted, including names that could be attacker-controlled map keys. Applications opting in should account for ConfigValidation or use validation_diagnostics() / operator_message(); existing ConfigOutOfDate constructors remain supported. Extraction adds no store read, complete-policy reparse, or second validation pass.

Closes

Closes #457

Test plan

Historical author-reported local verification below (original head unrecorded unless an explicit SHA is given). These results, counts, timings and negative controls were not rerun in this audit, and their underlying local logs were unavailable; checked boxes retain the original report. At the current head eba3ce15, all 28 reported hosted checks are passing.

Local checks used Rust 1.98.1 and Node.js 24.20.0.

  • cargo test --workspace --all-targets — 1,565 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM test-target compilation checks for Fastly, Spin, and Cloudflare, including the required Spin WASM compilation check
  • Adapter WASM Clippy, including Fastly's fastly cli combination and Spin's relocated contract test
  • Standalone core refusal control without test-utils, and the same policy's feature-enabled success control
  • CLI validate/push/diff and Axum extraction/response regressions
  • actionlint .github/workflows/test.yml
  • examples/app-demo workspace tests — left to CI
  • Docs: npm run lint, npm run format, and npm run build
  • Manual application startup via edgezero serve --adapter axum
  • Actual WASM runtime contract execution — left to CI; local Viceroy is 0.17.0 instead of the pinned 0.21.0, the Cloudflare runner is 0.2.122 instead of locked 0.2.128 and lacks a browser driver, and Wasmtime is unavailable

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • No route changes; existing brace parameter syntax preserved
  • Application HTTP types use edgezero_core
  • Store wiring uses registries
  • New behavior has tests
  • No secrets or credentials committed

@prk-Jr prk-Jr self-assigned this Nov 13, 2026
@prk-Jr
prk-Jr marked this pull request as ready for review November 13, 2026 12:56

@dhruv8sh dhruv8sh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review

Summary

This adds a bounded, static-allowlist sanitizer (config_diagnostics::ValidationReport) for typed app-config validation failures. Approved path+code pairs keep fixed operator explanations through EdgeError::ConfigValidation; everything else is redacted, including every validator field name, both at runtime and in CLI validate/push/diff. The sanitizer is well bounded and thoroughly tested. However, the blanket field-name redaction removes useful diagnostics from the operator's own CLI.

😃 Praise

  • 😃 A tight, well-bounded sanitizer (crates/edgezero-core/src/config_diagnostics.rs:200). The walker spends its budget before allocating or sorting attacker-sized maps and sorts keys so output is deterministic. Matches must be exact path+code, with wildcards for list indices only. Tests cover every limit at N and N+1 and plant canaries in messages, params, map keys, and nested names. Apps that don't opt in keep ConfigOutOfDate.
  • 😃 Shared adapter contract fixture. contract_fixture::extraction_error() runs the real store read, validation, and error mapping through all four adapters' response conversion in one place.

Findings

Blocking

  • 🔧 CLI validate/push/diff no longer says which field or rule failed (crates/edgezero-cli/src/config.rs:265, :473, :650).
    • Symptom: FixtureConfig with [service] timeout_ms = 50 now prints typed app-config failed validation: app config failed validation for field `<redacted>.<redacted>` . Before this PR it named service.timeout_ms and the range rule. This affects every app that hasn't registered a diagnostic for every rule. typed_errors_on_validator_rule_failure only checks for the word "validation", so CI doesn't catch it.
    • Why it can be narrower: the threat (a runtime-derived map key used as a field name) can be targeted precisely. Every public ValidationErrors builder (add, merge, merge_self, merge_all) takes &'static str and stores Cow::Borrowed. Only errors_mut().insert(Cow::Owned(..)) yields a runtime key, and derived map validation uses numeric indices.
    • Fix: keep the Cow in ActualSegment and redact only owned keys. Then assert that service.timeout_ms appears in typed_errors_on_validator_rule_failure; runtime_validation_redacts_untrusted_map_keys still covers the hostile case.
      enum ActualSegment<'tree> { Field(&'tree Cow<'static, str>), Index(usize) }
      // render_path fallback:
      ActualSegment::Field(Cow::Borrowed(name)) if is_safe_ident(name) => name,
      ActualSegment::Field(_) => "<redacted>",

Non-blocking

  • 🤔 The public field_path is always the literal "<redacted>" (crates/edgezero-core/src/config_diagnostics.rs:228; emitted at error.rs:114 and :318), even for approved diagnostics, so it tells a client almost nothing. The fix above restores static names. Otherwise, omit the key when every segment is redacted.
  • 🤔 The operator message redacts a field and then names it (crates/edgezero-core/src/config_diagnostics.rs:140). It reads …for field `<redacted>`; implementation [implementation_unavailable]: …. When diagnostics are present, skip the generic for field … prefix.
  • 🤔 Existing ConfigOutOfDate matches silently miss approved failures (crates/edgezero-core/src/error.rs:32). Downstream matches!(e, EdgeError::ConfigOutOfDate { .. }) checks return false once an app registers any diagnostic. Consider a public is_config_out_of_date() covering both variants, and mention it in the migration guide.
  • ⛏ --no-default-features has no effect (.github/workflows/test.yml:115) because edgezero-core has no default features. Also, runtime_approved_diagnostic_tracks_compiled_availability uses cfg!(feature = "test-utils"). Feature unification means the refusal branch only runs in this separate step, so a comment on the test explaining that would help.
  • ⛏ Duplicate diagnostics (crates/edgezero-core/src/config_diagnostics.rs:239). The same approved code on the same field is pushed twice, using 2 of the 8 MAX_DIAGNOSTICS slots. Skip the push when the previous (field_path, code) matches.
  • 🌱 #[app_config(diagnostics = …)] on a nested-only child is silently ignored (crates/edgezero-macros/src/app_config.rs:664). A future lint could flag it.

📌 Out of Scope

  • 📌 Rust 1.99 clippy failure: with no rust-toolchain.toml, clippy 1.99 fails on existing code at crates/edgezero-macros/src/app_config.rs:478 (rest_pattern_accessible_field). Worth tracking before the next toolchain bump.

CI Status

Run locally on the pinned Rust 1.98.1:

  • fmt: PASS
  • clippy: PASS
  • tests: PASS
  • check --features "fastly cloudflare spin": PASS
  • spin wasm32-wasip2 check: PASS

@ChristianPavilonis ChristianPavilonis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃 Approved — no blocking correctness or security defects found.

The shared, bounded approval registry preserves fixed operator diagnostics without retaining validator messages or parameters. The extraction-backed adapter contracts provide strong coverage of the operator/public boundary.

Review observations

  • The loss of unregistered field names in typed CLI validate/push/diff is real, but is an intentional, documented default-redaction trade-off rather than an accidental implementation error. I do not consider it blocking for this opt-in contract.
  • I independently checked the earlier borrowed-key suggestion: Cow::Borrowed proves lifetime, not schema provenance. A runtime-derived key held in OnceLock<String> can reach ValidationErrors::add as borrowed. The current sanitizer correctly redacts it; the borrowed-key shortcut would weaken that protection. Preserving more CLI field locations would require a trusted schema-metadata approach.
  • A focused probe exercised real typed CLI entry points and the #[action] extraction → RequestLogger → Axum service → SimpleLogger path. Approved explanations reached operator output; validator message/value canaries did not. HTTP stayed coarse: 503, config_out_of_date, and Retry-After: 60.

Verification

Passed locally with Rust 1.98.1:

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --workspace --all-targets — 1,565 passed, 1 ignored
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • cargo check -p edgezero-adapter-spin --target wasm32-wasip2 --features spin
  • Separate core compiled-implementation refusal and feature-enabled success controls
  • Fastly and Cloudflare WASM contract compilation
  • Spin WASM contract execution — 13 passed
  • Cloudflare browser/WASM contract execution — 14 passed
  • Workflow actionlint with explicit installed tool paths
  • Focused standalone CLI, borrowed-runtime-key, and native Axum logging/public-response probes

Local Fastly runtime execution was not repeated because installed Viceroy is 0.17.0 rather than the pinned 0.21.0. I inspected the actual Fastly CI log: Viceroy 0.21.0 ran the new contract successfully, with 8 contract tests and 97 runtime unit tests passing. Docs/demo startup checks were not repeated locally; GitHub checks are green.

Reviewed all 17 changed files at head eba3ce157259a49b15d0b7c5d737871cbc084284 against base/merge-base e11ea3082f66ec864aabdd6007b15c4926c73b82. No production source changes were made during review.

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.

Preserve safe validation diagnostics during app-config extraction

3 participants