{{ message }}
Commit 49a7912
authored
security: disable $ENV in tool response filters and sync validation compile options (#7208)
Tool response filters compiled without `WithEnvironLoader` could expose
environment variables (including `GITHUB_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`** — Add
`gojq.WithEnvironLoader(func() []string { return nil })` to
`CompileToolResponseFilter`, matching the existing guard on the
`walk_schema` path:
```go
code, err := gojq.Compile(query,
gojq.WithEnvironLoader(func() []string { return nil }), // explicitly
disable $ENV access (defense-in-depth)
)
```
- **`internal/config/validation.go`** — Apply the same
`WithEnvironLoader` option in `validateToolResponseFilters` so
validation accurately predicts runtime behavior. Previously a filter
using `$ENV` would pass validation but silently return `null`/`{}` for
`$ENV` references at runtime.
- **`internal/middleware/jqschema.go`** — Improve the multiple-results
error message to guide admins toward the correct fix:
```
// Before: "tool response filter returned multiple results, first=...
extra=..."
// After: "tool response filter returned multiple results — use array
form ([.a, .b]) to combine outputs into a single value; first=...
extra=..."
```
- **`internal/middleware/jqschema_coverage_test.go`** — Add
`TestCompileToolResponseFilter_EnvDisabled` which runs a
`$ENV`-referencing filter through the compiled code object directly and
asserts `$ENV` resolves to `{}`, not the real process environment.3 files changed
Lines changed: 32 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
283 | 285 | | |
284 | 286 | | |
285 | 287 | | |
| |||

0 commit comments