feat(guard): wazero security hardening — memory cap, backend call limit, interpreter tests#7938
Merged
Merged
Conversation
…interpreter tests
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
Contributor
There was a problem hiding this comment.
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_backendcall 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
Contributor
Author
Addressed in 906538a. The failed check was a |
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 productionRuntimeConfig. Without this, a guard declaring a large(memory max ...)can grow to consume unbounded host RAM.Backend call limit: Add
maxBackendCallsPerInvocation = 50counter inhostCallBackend, reset at the start of eachcallWasmGuardFunction. Prevents a buggy or malicious guard from loopingcall_backendindefinitely within a single label call.Performance
wazero.NewRuntime(ctx)calls inwasm_test.gotowazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter()). JIT compilation is pure overhead for hand-crafted test WASM byte slices.Readability
WithNameIIFE: Replace the immediately-invoked function expression with a plainguardNamevariable.Tests
TestHostCallBackendCallLimit: verifies the error sentinel is returned when the limit is exceeded, and thatbackendCallCountis reset to zero at the start of each invocation.TestIsWasmTrap/actual_wazero_trap_still_uses_wasm_error_prefixalready 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.