feat(spec): warn on dubious $ref locations#258
Merged
fredbi merged 1 commit intoJun 10, 2026
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #258 +/- ##
==========================================
+ Coverage 92.33% 92.41% +0.08%
==========================================
Files 23 24 +1
Lines 3183 3271 +88
==========================================
+ Hits 2939 3023 +84
- Misses 160 163 +3
- Partials 84 85 +1 ☔ View full report in Codecov by Harness. |
Adds a warning-only check (validateDubiousRefs) over the unexpanded spec's $refs, to flag location patterns that may indicate an unsafe or adversarial spec when running spec validation: - Rule 1: an absolute local $ref (file://, Unix /abs, Windows C:\, UNC) is flagged when it escapes the spec's base path. Absolute refs that stay beneath the base path are legitimate (flatten/expand introduces such anchors for cyclical $refs) and are not flagged. Relative and fragment-only refs are exempt. - Rule 2: when remote (http/https or protocol-relative) $refs resolve to two or more distinct hosts, a single aggregate warning lists them. A single consistent remote host is not flagged. Findings are warnings only and do not affect validity. The check inspects refs as authored via analyzer.AllRefs(), before expansion. The go-openapi/spec path normalization helpers are unexported, so a minimal slash/drive-letter normalize and a lexical "beneath base" containment check are replicated locally (cleanRefPath, isBeneathBase, localBaseDir). Windows drive paths need care so the "beneath base" comparison holds across every form they can be authored in. All of: bare C:\ / C:/, the canonical file:///C:/ URL, and the (invalid but tolerated) hybrid file://C:/ form (whose drive letter parses into the URL host) normalize to the same drive path with no leading slash, matching the base derived from SpecFilePath. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
b8e81f6 to
838587a
Compare
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.
Adds a warning-only check (validateDubiousRefs) over the unexpanded spec's $refs, to flag location patterns that may indicate an unsafe or adversarial spec when running spec validation:
Findings are warnings only and do not affect validity. The check inspects refs as authored via analyzer.AllRefs(), before expansion.
The go-openapi/spec path normalization helpers are unexported, so a minimal slash/drive-letter normalize and a lexical "beneath base" containment check are replicated locally (cleanRefPath, isBeneathBase, localBaseDir).
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist