Repository navigation
🐛 bug: stat the index for directory SendFile ranges and move the path guards into internal/fspath - #4769
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe change adds shared path validation and normalization helpers. Static middleware uses the validator, and SendFile uses normalized names when checking file sizes and directory indexes. Tests cover path handling and byte-range responses, including missing files. ChangesFile Path Handling
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4769 +/- ##
==========================================
+ Coverage 95.51% 95.54% +0.03%
==========================================
Files 142 142
Lines 18082 18019 -63
==========================================
- Hits 17271 17217 -54
+ Misses 509 502 -7
+ Partials 302 300 -2
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:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32c2c4da0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Description
Cluster 12 of #4604: filesystem path guards.
internal/fspathnow holds the checks between a request and fasthttp's file handler, for the static middleware and SendFile.Validis static'ssanitizePathand its helpers, moved unchanged; static keeps only the call.FSName/OSNamegive the name fasthttp opens for a SendFile name.sendFileContentLengthused to clean only in the fs.FS branch; both branches use them now.%policy, written down: it's a name byte where nothing decodes afterwards (UnescapePath, SendFile), and static's default mode refuses a%that begins no escape the router kept. That's today's behavior.Behavior change: a 416 from SendFile with
ByteRangenow hasContent-Range: bytes */Nwhen the name has dot segments (/srv/missing/../f.txt, ora/../../f.txtwith an fs.FS). Before, the size lookup cleaned a different name than the one served and the header was missing. Covered byTest_SendFile_ByteRange_DotSegments.It also fixes the 416 for a plain directory:
SendFile(root+"/dir/")and an fs.FS"dir/"used to answerContent-Range: bytes */<size>with the directory's own stat size, and now report the size of the index.html they serve.Left alone: the
unhex/isUnreservedcopies inpath.goandinternal/wiretargetare router side (cluster 4).Related #4604
Changes introduced
Valid, static requests (OS hit, escape miss, rejected, fs.FS hit) andCtx_SendFileare within noise with unchanged allocations. SendFile with a Range header is +1.7% (416) and +3.0% (206) for the extra clean.Like #4750, I fuzzed against a verbatim copy of main with throwaway harnesses that aren't in the diff:
ValidvssanitizePathover nil, MapFS and DirFS roots (43.3M execs), andFSName/OSNamevs the old cleaning and what fasthttp opens (23.6M execs). No differences apart from the dot-segment fix.Type of change
Checklist
internal/fspathis at 100% coverage.make test,make lint,make format.🤖 Maintainers:
/generatere-runs the code generators on this branch