Skip to content

feat(guard): wazero security hardening — memory cap, backend call limit, interpreter tests#7938

Merged
lpcox merged 5 commits into
mainfrom
copilot/go-fan-review-tetratelabs-wazero
Jun 22, 2026
Merged

feat(guard): wazero security hardening — memory cap, backend call limit, interpreter tests#7938
lpcox merged 5 commits into
mainfrom
copilot/go-fan-review-tetratelabs-wazero

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Go Fan review (#7927) identified security and quality gaps in the wazero WASM guard integration. This PR addresses all five recommendations.

Security

  • Memory cap: Add WithMemoryLimitPages(256) (16 MiB) to the production RuntimeConfig. Without this, a guard declaring a large (memory max ...) can grow to consume unbounded host RAM.

    runtimeConfig := wazero.NewRuntimeConfigCompiler().
        WithCloseOnContextDone(true).
        WithMemoryLimitPages(256) // 16 MiB hard cap
  • Backend call limit: Add maxBackendCallsPerInvocation = 50 counter in hostCallBackend, reset at the start of each callWasmGuardFunction. Prevents a buggy or malicious guard from looping call_backend indefinitely within a single label call.

Performance

  • Interpreter in unit tests: Switch 5 wazero.NewRuntime(ctx) calls in wasm_test.go to wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter()). JIT compilation is pure overhead for hand-crafted test WASM byte slices.

Readability

  • Simplify WithName IIFE: Replace the immediately-invoked function expression with a plain guardName variable.

Tests

  • TestHostCallBackendCallLimit: verifies the error sentinel is returned when the limit is exceeded, and that backendCallCount is reset to zero at the start of each invocation.
  • The existing TestIsWasmTrap/actual_wazero_trap_still_uses_wasm_error_prefix already serves as a live version assertion for the "wasm error:" string — it instantiates a real trap with the installed wazero and fails if the prefix changes on upgrade.

GitHub Advanced Security started work on behalf of lpcox June 22, 2026 17:11 View session
GitHub Advanced Security finished work on behalf of lpcox June 22, 2026 17:12
GitHub Advanced Security started work on behalf of lpcox June 22, 2026 17:21 View session
GitHub Advanced Security finished work on behalf of lpcox June 22, 2026 17:22
GitHub Advanced Security started work on behalf of lpcox June 22, 2026 17:23 View session
Copilot AI changed the title [WIP] Review Go Module: tetratelabs/wazero feat(guard): wazero security hardening — memory cap, backend call limit, interpreter tests Jun 22, 2026
Copilot finished work on behalf of lpcox June 22, 2026 17:23
Copilot AI requested a review from lpcox June 22, 2026 17:23
GitHub Advanced Security finished work on behalf of lpcox June 22, 2026 17:23
@lpcox lpcox marked this pull request as ready for review June 22, 2026 18:16
Copilot AI review requested due to automatic review settings June 22, 2026 18:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the wazero-backed WASM guard integration by adding resource limits (memory and backend call count), simplifying guard module naming, and optimizing/selecting the interpreter runtime for unit tests to reduce unnecessary JIT overhead.

Changes:

  • Add a per-invocation call_backend call counter with a hard limit to prevent runaway backend calls.
  • Add a runtime memory cap to constrain guard-controlled linear memory growth.
  • Switch several unit tests to use the interpreter runtime and add a new test covering the backend call limit behavior.
Show a summary per file
File Description
internal/guard/wasm.go Adds runtime memory cap, simplifies WithName setup, and enforces/reset a per-invocation backend call limit.
internal/guard/wasm_test.go Uses interpreter runtime in tests and adds coverage for the backend call limit + counter reset behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread internal/guard/wasm.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 22, 2026 18:58 View session
GitHub Advanced Security finished work on behalf of lpcox June 22, 2026 19:00
@lpcox

lpcox commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the failed ci check https://github.com/github/gh-aw-mcpg/actions/runs/27976677887/job/82796097537?pr=7938

Addressed in 906538a. The failed check was a gofmt issue in internal/guard/wasm.go; I fixed the indentation, re-ran make lint, and make agent-finished now passes.

GitHub Advanced Security started work on behalf of lpcox June 22, 2026 19:05 View session
Copilot finished work on behalf of lpcox June 22, 2026 19:06
GitHub Advanced Security finished work on behalf of lpcox June 22, 2026 19:06
@lpcox lpcox merged commit 6d3533c into main Jun 22, 2026
27 checks passed
@lpcox lpcox deleted the copilot/go-fan-review-tetratelabs-wazero branch June 22, 2026 20:09
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.

3 participants