fix(transport/http): escape path parameters safely - #3856
Conversation
|
Hi maintainers, the Non-English Comments Check failed before the scanning step ran. The failure occurred in I also reproduced the workflow's grep check locally against the two changed files, and it found no non-English comments. Failed run: https://github.com/go-kratos/kratos/actions/runs/29814185538 Could you please review the workflow configuration or re-run the appropriate check after it is adjusted? Thank you! |
There was a problem hiding this comment.
Pull request overview
This PR hardens transport/http URL path construction by escaping substituted path parameters in BuildPath, preventing injected ?, #, and spaces from corrupting the resulting request URL while preserving / for resource-name style parameters.
Changes:
- Escape each slash-separated path segment via
url.PathEscape, joining segments to preserve/in resource names. - Restore a small set of RFC 3986 path-segment sub-delimiters that
url.PathEscapewould otherwise escape to avoid compatibility regressions. - Add regression tests covering query/fragment injection, spaces, resource-name slashes, and valid path-segment characters.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| transport/http/path.go | Escapes substituted path parameter values safely (segment-wise) while preserving / and selected valid sub-delimiters. |
| transport/http/path_test.go | Adds test coverage to prevent regressions for escaping behavior and preserved characters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi maintainers, just following up on this PR. The Go and Lint checks are green, and the focused tests cover query/fragment characters, spaces, resource-name slashes, and preserved valid path-segment characters. Please let me know if there are any compatibility cases or changes you would like me to address. Thanks! |
Description (what this PR does / why we need it):
BuildPathpreviously substituted path parameter values without escaping them. Values containing spaces,?, or#could therefore corrupt the URL structure or inject query/fragment delimiters.This change:
url.PathEscape./for resource names such aspublishers/go/books/kratos.BuildPath, avoiding compatibility regressions.Which issue(s) this PR fixes (resolves / be part of):
Fixes #3853
Other special notes for the reviewers:
Focused tests pass: