Skip to content

proposal: response-side policies#7

Merged
kanywst merged 3 commits into
mainfrom
feat/response-side-policies
May 9, 2026
Merged

proposal: response-side policies#7
kanywst merged 3 commits into
mainfrom
feat/response-side-policies

Conversation

@kanywst
Copy link
Copy Markdown
Member

@kanywst kanywst commented May 9, 2026

Design doc only. Tracks the response-side policies item from ROADMAP near term.

See docs/proposals/response-side-policies.md.

Summary:

  • New target rule allow_response (vs allow) so request-side policies stay backward compatible.
  • Implement proxy_on_response_headers to evaluate against an input shape with request and response subtrees.
  • Deny path replaces the response via proxy_send_local_response using parameters from the rule's value expression.

Status: design only, no implementation.

@coderabbitai

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@kanywst kanywst marked this pull request as ready for review May 9, 2026 13:58
kanywst added 3 commits May 9, 2026 23:51
eval.zig:
- New evaluateWithTarget(arena, input, ast, target_rule). evaluate()
  becomes a thin wrapper targeting 'allow'.

main.zig:
- New evaluate_target wasm export: same shape as evaluate plus an
  explicit target_rule pointer/length pair. Lets generic-ABI hosts
  drive non-default rules without going through proxy-wasm.

proxy_wasm.zig:
- proxy_on_response_headers builds {response: {status, headers}}
  from the response header map and runs evaluateWithTarget against
  'allow_response'. Deny short-circuits with proxy_send_local_response(503).
- :status pseudo-header fetched individually for the same wamr-host
  reason that drives request-side path.
- Unchanged: request-headers path stays on 'allow'.

Tests:
- src/eval.zig: 3 unit cases (5xx denies, default allows, missing
  target rule denies, allow target preserved).
- test/run.mjs and test/run_wasmtime.py: 3 cases each driving the
  new evaluate_target export end-to-end through the wasm boundary.

Release build grows from 50K to 55K. ci.yml gains test-unit job in
line with the other implementation branches.
Three medium-priority concerns from the review needed reconciliation
between the design doc and the v1 implementation:

1. Replacement contract: doc claimed structured replacement (status /
   body / headers from the rule's value). v1 actually returns bool
   from the evaluator and does a fixed 503 on deny. The structured
   replacement requires the evaluator to surface json.Value plus a
   discriminator and is deferred to a follow-up PR. Doc now splits
   'v1' (fixed 503) from 'deferred' (structured).

2. 503 vs 403 asymmetry: doc didn't say which deny code response-side
   uses, request-side already returns 403. v1 uses 503 on the
   response side (upstream being replaced) vs 403 on the request
   side (request rejected before upstream). Doc now states this
   explicitly as intentional.

3. Backward compat for nested input shape: doc showed
   '{request, response}' nested input which would have broken
   existing input.method / input.path refs. v1 keeps the request-side
   input flat (unchanged) and adds 'input.response.*' ONLY for the
   allow_response target rule. input.request.* is reserved for the
   v2 post-snapshot picture. Doc now shows v1 vs v2 input shapes
   separately and clarifies 'allow' policies are untouched.

Per-context state section also corrected: v1 does not snapshot
request fields. The snapshot lives behind body-aware-policies.md
(PR #6) and shows up here only when that lands.
@kanywst kanywst force-pushed the feat/response-side-policies branch from f622c6a to 76e0bf7 Compare May 9, 2026 14:55
@kanywst kanywst merged commit 4d00579 into main May 9, 2026
11 checks passed
@kanywst kanywst deleted the feat/response-side-policies branch May 9, 2026 14:58
@kanywst kanywst mentioned this pull request May 9, 2026
9 tasks
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.

1 participant