jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Malformed config silently falls back to broad defaults

Open ianalitis opened this issue 3 months ago • 0 comments

Summary

Config::load() silently converts configuration read and TOML parse failures into Config::default(). A malformed or unreadable config can therefore discard the operator's safety, privacy, provider, tool, and routing choices while allowing Jcode to continue under broad defaults.

Why this matters

A missing config and a broken config are different states:

  • Missing config may legitimately use documented defaults.
  • Present but malformed/unreadable config indicates operator intent that Jcode failed to honor.

Silently replacing the latter with defaults is fail-open behavior. A typo in a privacy or authority setting can enable behavior the operator explicitly intended to disable.

Source trace

Audited at 008abc44b1653efa65ccf98acb3b7236ce8507e6:

  • Config::load uses the non-strict path.
  • The normal load path maps file/read/TOML failures to Config::default().
  • Strict parsing is used for config updates, and tests already protect against overwriting malformed config: config_file.rs, tests.

Reproduction shape

  1. Create a valid config that disables or restricts one or more features.
  2. Introduce a TOML syntax error or an invalid value.
  3. Start Jcode normally.
  4. Observe that startup continues with Config::default() rather than surfacing a blocking configuration error or retaining a last-known-good configuration.

Expected behavior

For a config file that exists but cannot be read or parsed, Jcode should fail closed and make the problem visible. Reasonable policies include:

  • refuse startup with an actionable parse/read diagnostic,
  • enter a clearly marked restricted recovery mode,
  • or use a validated last-known-good snapshot while reporting that the current file was rejected.

It should not silently substitute broad defaults.

Suggested regression

Add tests that distinguish:

  • absent file -> documented defaults,
  • malformed present file -> surfaced error/restricted state,
  • unreadable present file -> surfaced error/restricted state,
  • malformed update -> existing bytes remain untouched.

This is broader than individual enum/value parse defects because the concern is the top-level fallback contract.

ianalitis avatar Aug 30 '26 19:08 ianalitis