fix: allow gator catalog filenames containing ..#4630
Conversation
Signed-off-by: immanuwell <pchpr.00@list.ru>
There was a problem hiding this comment.
Pull request overview
This PR fixes a false-positive in the gator policy catalog fetcher. The previous logic rejected any content path containing the substring .., which incorrectly blocked legitimate filenames such as template..yaml when using local file:// catalogs. The fix replaces the substring check with a new containsPathTraversal helper that only flags .. when it appears as a complete path segment (after URL-decoding and cleaning), preserving traversal protection while allowing valid filenames.
Changes:
- Replaced the
strings.Contains(..., "..")substring check inFetchContentwith a call to a newcontainsPathTraversalhelper. - Added
containsPathTraversal, which URL-decodes andpath.Cleans the input, then rejects only true..path segments. - Added a unit test verifying that a filename containing
..(template..yaml) is fetched successfully.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pkg/gator/policy/catalog/fetch.go |
Swaps the substring .. check for a segment-aware containsPathTraversal helper that allows legitimate filenames while still rejecting traversal segments. |
pkg/gator/policy/catalog/fetch_test.go |
Adds a test confirming filenames containing .. are now accepted by FetchContent. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4630 +/- ##
==========================================
- Coverage 54.49% 44.75% -9.74%
==========================================
Files 134 284 +150
Lines 12329 20968 +8639
==========================================
+ Hits 6719 9385 +2666
- Misses 5116 10775 +5659
- Partials 494 808 +314
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What this PR does / why we need it:
gator policytreats any..substring as traversal, so a normal catalog file liketemplate..yamlgets rejected. That is a false positive, and it is easy to hit with localfile://catalogs. This patch only rejects real..path segments, so traversal protection stays intact. small fix, pretty low-risk.Which issue(s) this PR fixes:
None found. I checked for related
gatorcatalog path issues and PRs. Closest one is #4583, same fetcher, different file path edge case.Special notes for your reviewer:
Repro before this patch:
Checks I ran: