Skip to content

fix(server): Validate targets before binding authorization [SAO-20817] - #305

Merged
josjeon merged 6 commits into
mainfrom
codex/clone-bind-target-validation
Nov 18, 2026
Merged

josjeon merged 6 commits into
mainfrom
codex/clone-bind-target-validation

Conversation

@josjeon

@josjeon josjeon commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

VictorOps incident 62266 included a POST /api/v1/controls/{control_id}/clone-and-bind request with target identifiers only in the URL and no JSON body. Agent Control sent a missing target context to Orbit's binding-write authorization check; Orbit returned 400 and Agent Control surfaced 502. A sampled trace shows that 400-to-502 path. Review also reproduced the same 502 behavior for missing-target bodies on four other binding-write routes.

Endpoint behavior

Previously fixed GET route: PR #297 was merged on 2026-11-05. It changed target-required GET /api/v1/control-bindings requests with missing or incomplete target_type/target_id from an Orbit 400 surfaced as 502 to a local 422 VALIDATION_ERROR before the upstream call. control_id alone is insufficient; it is a filter inside an authorized target. The rule is enabled only for the relevant Orbit management-authorization deployment, so generic upstreams retain their namespace-wide list behavior. PR #305 does not introduce that GET behavior; it reuses the same target-pair predicate while preserving the flag and query contract.

Endpoint Where the target belongs Invalid or missing target after this PR
GET /api/v1/control-bindings (already fixed in #297) target_type and target_id query parameters Existing local 422 when binding_list_requires_target is enabled. control_id remains an optional filter within that target. PR #305 only refactors its target-pair check.
POST /api/v1/controls/{control_id}/clone-and-bind JSON target_binding.target_type and target_binding.target_id Local 422 with a nested-body hint before the binding-write Orbit check. URL-only or flat JSON target fields do not satisfy this contract.
PUT /api/v1/control-bindings Top-level JSON target_type and target_id Local 422 before binding-write Orbit authorization.
PATCH /api/v1/control-bindings/by-key Top-level JSON target_type and target_id Local 422 before binding-write Orbit authorization.
PUT /api/v1/control-bindings/by-key Top-level JSON target_type and target_id Local 422 before binding-write Orbit authorization.
POST /api/v1/control-bindings/by-key:delete Top-level JSON target_type and target_id Local 422 before binding-write Orbit authorization.

The four body-bearing binding-write routes are additional scope found during review. Eight HTTP/HTTPS regression cases reproduced their prior 502 behavior before the fix and returned 422 afterward. They share one _binding_body_context path, so the same validation applies consistently.

Reuse and preserved behavior

complete_target_context() is the shared, side-effect-free check for a nonblank string pair. Each endpoint still extracts fields from its own documented location and supplies its own 422 detail/hint. GET keeps its deployment flag and existing query-field length behavior; JSON-body routes keep their 255-character model limit. The optional control-list attachment target uses the same pair check. Public binding models and attachment filter query parameters now express the nonblank rule with a \S pattern, without trimming opaque identifiers. Valid targets still reach Orbit, and an Orbit permission denial remains 403. Clone-and-bind may perform its separate control-create/read authorization checks before local target rejection; this change prevents the invalid binding-write check.

FastAPI rejects malformed application/json before binding authorization. It does not pre-parse an empty body or malformed text/plain body, so the body context builder catches ValueError from request.json() and returns local 422. An Astra dry-run review caught the missing fallback as a real 500 regression; 16 HTTP/HTTPS cases across all four body-bearing binding routes failed before the fix and passed afterward. The caller still needs a separate correction to send the documented nested clone-and-bind body.

Review note: The four body-bearing binding routes intentionally report an invalid target as 422 before their authorizer runs, including with header auth. HTTP tests pin that order and confirm that a complete target still requires credentials (401 without them).

The UI CI job is pinned to Ubuntu 24.04 because Playwright 1.57 cannot install Chromium on the ubuntu-latest Ubuntu 26.04 image.

Ticket: SAO-20817

Validation

  • Three review passes covered GET/POST contracts, every body-bearing binding route, authorization denials, and CI/test impact.
  • After the second Astra review fixes, full make check passed on Python 3.12, including 1,093 server tests, lint, and type checks. Focused auth-order and attachment-filter tests passed; the OpenAPI spec generated with the nonblank pattern. Local UI ESLint, TypeScript type check, and Prettier check passed. The local TypeScript SDK generation check requires a Speakeasy login, so the hosted SDK CI remains the generation gate.
  • All six PR commits are SSH-signed, locally verified, and rebased onto freshly fetched main; GitHub reports verified=true / reason=valid for every commit. Astra's third dry-run round on 476bd42 returned approve with no remaining findings; it was not posted to GitHub. Exact-head server, SDK, UI, build, title, and Codecov checks all pass. Human review is still required.

The exact bodies of the other incident requests and the deployed US1 revisions remain unverified. No production change or live US1 test was performed.

@josjeon josjeon changed the title [SAO-20817] Return 422 for invalid clone-and-bind targets fix(server): Return 422 for invalid clone-and-bind targets [SAO-20817] Nov 18, 2026
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@josjeon josjeon changed the title fix(server): Return 422 for invalid clone-and-bind targets [SAO-20817] fix(server): Validate targets before binding authorization [SAO-20817] Nov 18, 2026
@josjeon
josjeon merged commit ece2edb into main Nov 18, 2026
9 checks passed
@josjeon
josjeon deleted the codex/clone-bind-target-validation branch November 18, 2026 22:12
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.

2 participants