Skip to content

fix(config): validate RIExchangeMode on PUT /api/config #1196

Closed

Description

@cristim

PUT /api/config unmarshals the body onto GlobalConfig wholesale, and GlobalConfig.Validate never constrains RIExchangeMode. So a typo, "" or "Auto" is stored as-is (see the armed() comment at internal/api/handler.go:570-580). The RI-exchange config endpoint does validate the mode (internal/api/handler_ri_exchange.go:2845, only manual or auto).

Today the scheduler routes every non-manual value to auto-execution. After LeanerCloud/cloud-commitments-go#578, RunAutoExchange fails closed on anything other than exactly auto or manual. A stored bad value then makes the scheduled run fail loudly instead of auto-executing. That is safer, but it surfaces a config the API should never have accepted.

Fix:

  • Validate RIExchangeMode (manual | auto) on PUT /api/config, preferably in GlobalConfig.Validate so every writer is covered, with the same error the RI-exchange endpoint returns.
  • Add tests for the typo, "" and "Auto" cases.
  • Once only manual and auto can be stored, update the armed() comment. Keep armed() itself fail-safe (!= "manual") for rows already stored with bad values.
  • Consider a one-off check or a migration note for existing rows with an invalid mode before bumping the go pin past fix(api): GET /api/purchases/cancel/{id} cancels an execution on a side-effecting GET #578.

Reported by the cloud-commitments-go agent; confirmed against origin/main 31a31816.

Activity

  1. IAmJSD commented on Oct 22, 2026

    @IAmJSD
    Collaborator

    Claiming: working on this

  2. self-assigned this
    on Oct 22, 2026
  3. IAmJSD commented on Oct 27, 2026

    @IAmJSD
    Collaborator

    Status update (2026-10-27, checked against main at 7b86e38): Waiting on a held PR.

    Main still doesn't validate ri_exchange_mode on PUT /api/config. Since the go pin moved past go#578 (#1466/#1490), a stored bad value now fails the scheduled exchange run loudly instead of auto-executing. Held draft PR #1243 (D5) fixes it but currently has merge conflicts.

    Left / blocked on: Held open PR #1243 (D5); needs a rebase (CONFLICTING).

  4. added a commit that references this issue on Oct 28, 2026
    bbf0a83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions