security: disable $ENV in tool response filters and sync validation compile options#7208
Merged
Conversation
4 tasks
…ons, improve multiple-results error message
…ssert input preservation
Copilot
AI
changed the title
[WIP] Review gojq module for JSON processing
security: disable $ENV in tool response filters and sync validation compile options
Jun 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens jq-based tool response filtering by explicitly disabling $ENV access during filter compilation and ensuring config validation compiles filters with the same options as the runtime path, preventing accidental environment-variable exposure and eliminating validation/runtime behavior mismatches.
Changes:
- Disable
$ENVaccess when compiling tool response filters viagojq.WithEnvironLoader(...). - Align config-time jq filter validation compilation options with runtime compilation behavior.
- Improve the “multiple results” error message and add a regression test asserting
$ENVis blocked.
Show a summary per file
| File | Description |
|---|---|
| internal/middleware/jqschema.go | Disables $ENV in tool response filter compilation and improves multiple-results guidance error text. |
| internal/middleware/jqschema_coverage_test.go | Adds coverage test to ensure $ENV is blocked in compiled tool response filters. |
| internal/config/validation.go | Makes validation compile jq filters with the same environment-loader restriction as runtime. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Tool response filters compiled without
WithEnvironLoadercould expose environment variables (includingGITHUB_TOKEN) if a filter referenced$ENV. Validation also compiled with different options than the runtime path, meaning$ENV-referencing filters would pass validation but behave differently at runtime.Changes
internal/middleware/jqschema.go— Addgojq.WithEnvironLoader(func() []string { return nil })toCompileToolResponseFilter, matching the existing guard on thewalk_schemapath:internal/config/validation.go— Apply the sameWithEnvironLoaderoption invalidateToolResponseFiltersso validation accurately predicts runtime behavior. Previously a filter using$ENVwould pass validation but silently returnnull/{}for$ENVreferences at runtime.internal/middleware/jqschema.go— Improve the multiple-results error message to guide admins toward the correct fix:internal/middleware/jqschema_coverage_test.go— AddTestCompileToolResponseFilter_EnvDisabledwhich runs a$ENV-referencing filter through the compiled code object directly and asserts$ENVresolves to{}, not the real process environment.