feat: inject a confined document loader into flatten and schema analysis#220
Merged
Merged
Conversation
Flattening and schema analysis resolve remote and relative $ref through the spec
package loader, which by default is unsandboxed. A caller processing an untrusted
specification had no way to confine that loading, exposing arbitrary file read
and SSRF (the same class of issue addressed in go-openapi/spec).
Add an injectable, option-aware loader to the two paths that actually load
documents:
- FlattenOpts.PathLoaderWithOptions, forwarded through ExpandOpts. This covers
the whole flatten feature, since ExpandSpec, ResolveRefWithBase and
DeepestRef all go through ExpandOpts.
- SchemaOpts.PathLoaderWithOptions, threaded through AnalyzedSchema and the
recursive Schema() calls; inferFromRef now uses spec.ExpandSchemaWithOptions
(new in spec v0.22.8) instead of the default-settings ExpandSchema. Flatten's
Schema() call sites propagate the loader too.
Set either to a confined loader (e.g. built with loading.WithRoot /
loading.WithHTTPClient, or a restricted loader from go-openapi/loads) to safely
process untrusted specs. Left nil, behavior is unchanged.
The New() analyzer and the diff package were audited and do not load external
documents (in-memory cataloguing and definition-map lookups only), so they need
no loader.
Bumps spec to v0.22.8 (for ExpandSchemaWithOptions) and aligns swag to v0.27.3;
the testintegration module moves to spec v0.22.8 and loads v0.24.1.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #220 +/- ##
==========================================
- Coverage 92.01% 92.01% -0.01%
==========================================
Files 30 30
Lines 3395 3393 -2
==========================================
- Hits 3124 3122 -2
Misses 189 189
Partials 82 82 ☔ View full report in Codecov by Harness. |
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.
Flattening and schema analysis resolve remote and relative $ref through the spec package loader, which by default is unsandboxed. A caller processing an untrusted specification had no way to confine that loading, exposing arbitrary file read and SSRF (the same class of issue addressed in go-openapi/spec).
Add an injectable, option-aware loader to the two paths that actually load documents:
Set either to a confined loader (e.g. built with loading.WithRoot / loading.WithHTTPClient, or a restricted loader from go-openapi/loads) to safely process untrusted specs. Left nil, behavior is unchanged.
The New() analyzer and the diff package were audited and do not load external documents (in-memory cataloguing and definition-map lookups only), so they need no loader.
Bumps spec to v0.22.8 (for ExpandSchemaWithOptions) and aligns swag to v0.27.3; the testintegration module moves to spec v0.22.8 and loads v0.24.1.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist