Repository navigation
Commit 0bebdf4
authored
fix(schema): stop upstream tool schemas from loading local files (#1788)
## Bug
Two validators compile the JSON Schema that an upstream server declares
for its tools:
- `internal/outputvalidation/validator.go` `compile()`: the
`outputSchema`, used for output-schema validation (Spec 056; on by
default in `warn` mode).
- `internal/server/mcp_input_validation.go` `compileInputSchema()`: the
`inputSchema`, used for pre-dispatch argument validation (Spec 085;
always on).
Both call `jsonschema.NewCompiler()` without setting a loader. In
`santhosh-tekuri/jsonschema/v6` the default loader is `FileLoader`,
which opens any `file://` URL. So when a schema contains `{"$ref":
"file:///any/path.json"}`, mcpproxy opens that path on the user's
machine, parses it, and compiles it into the tool's schema. The verdict
then depends on a local file the upstream chose.
## Trigger
Any upstream, including a remote HTTP one, can list a tool whose
`inputSchema` or `outputSchema` contains a `file://` `$ref`. The file is
read on the first call to that tool. No user action is needed beyond
calling the tool.
## Fix
Call `c.UseLoader(jsonschema.SchemeURLLoader{})` on both compilers. The
empty loader rejects every external URL scheme. Two things keep working:
- In-document refs (`#/$defs/...`) resolve against the in-memory
resource and never reach the loader.
- The standard `$schema` metaschemas are embedded in the library and are
served before the loader is consulted.
A schema that uses an external ref now fails to compile and takes the
existing fail-open path (FR-A9 / FR-013b).
## Tests
- `TestCompile_RefusesFileRef` (outputvalidation) and
`TestCompileInputSchema_RefusesFileRef` (server): a temp file holds
`{"type":"string"}`, and the schema is `{"$ref":"file://<that file>"}`.
With the fix it must not compile.
- `TestCompile_LocalRefsAndMetaSchemaStillWork` and
`TestCompileInputSchema_LocalRefStillWorks`: a `#/$defs` ref and the
draft 2020-12 `$schema` still compile and validate.
## Commands run
- `CGO_ENABLED=0 go test -count=1 -run 'Test'
./internal/outputvalidation/`: ok
- `CGO_ENABLED=0 go test -count=1 -run
'TestCompileInputSchema_|TestPreDispatchValidation_'
./internal/server/`: ok
- `CGO_ENABLED=0 go vet ./internal/outputvalidation/`: ok
- On current `main` (and again with both one-line fixes reverted), both
`RefusesFileRef` tests fail, with `schema with $ref file:///…/local.json
compiled; the local file was loaded`.
I did not run the full `./internal/server` package locally.1 parent e8cf15a commit 0bebdf4
4 files changed
Lines changed: 94 additions & 0 deletions
File tree
- internal
- outputvalidation
- server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
211 | 214 | | |
212 | 215 | | |
213 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
0 commit comments