wso2 / wso2/api-platform

Enforce read-only policy parameter snapshots at build time

Open
#2,999 0 comments 0 reactions 1 assignee View on GitHub

@renuka-fernando is already working on this.

Since Jul 29, 2026.

Dominant language
Go
Stars
71
Forks
111
Avg merge
1d 14h
Merged PRs (30d)
110

Description

Summary

Policy execution shares spec.Parameters.Raw as an immutable snapshot published during policy-chain construction. Add zero-runtime-cost build-time safeguards so first-party policies cannot mutate the params argument passed to On* policy callbacks.

Rationale

PR #2617 intentionally removed the per-request JSON deep copy because it accounted for approximately 30% of ext_proc CPU time. The raw parameter map is now shared read-only across concurrent requests. Direct or nested mutation could otherwise leak state between requests and, in the direct-write case, cause concurrent map writes.

Affected areas

  • gateway-builder/internal/validation/golang.go, extending ValidateGoInterface or its validation flow with an AST-based policy analyzer.
  • SDK policy callback interfaces/documentation for the read-only parameter contract.
  • Policy-engine executor concurrency coverage, including chain-level -race testing.

Required changes

  1. Add build-time analysis for policy On* callback methods that rejects direct writes to the params argument, including:
    • indexed assignment such as params[key] = value;
    • delete(params, key);
    • clear(params).
  2. Document that policy parameters are immutable snapshots and must be treated as read-only by all policy callbacks.
  3. Add a concurrent chain-execution test suitable for go test -race that protects the shared-snapshot contract.
  4. Document the analyzer's limitation for mutation through nested values or type assertions (for example, params["x"].(map[string]interface{})["y"] = value), and decide whether to add a shallow top-level copy as structural protection without restoring the JSON deep copy.

Acceptance criteria

  • A policy containing any supported direct mutation pattern fails gateway-builder validation with an actionable diagnostic.
  • Valid read-only parameter access continues to pass validation.
  • SDK-facing documentation states the immutable/read-only contract.
  • A chain-level concurrent execution test passes under the Go race detector.
  • The solution does not restore per-request JSON marshal/unmarshal deep copies.

Backlinks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.