fix: reject numeric request parameters which overflow the destination Go type - #1096
Open
leonklingele wants to merge 4 commits into
Open
fix: reject numeric request parameters which overflow the destination Go type#1096leonklingele wants to merge 4 commits into
leonklingele wants to merge 4 commits into
Conversation
… Go type Numeric request parameters are parsed using 64 bit parsing regardless of the destination Go type, then assigned through reflection. This can silently change user input rather than returning a 4xx validation error.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1096 +/- ##
=======================================
Coverage 93.20% 93.20%
=======================================
Files 23 23
Lines 4988 4992 +4
=======================================
+ Hits 4649 4653 +4
Misses 272 272
Partials 67 67 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens request-parameter numeric parsing so that values are parsed using the destination Go type’s bit-size (via reflection) rather than always parsing as 64-bit first, preventing silent overflow/coercion and returning a client validation error instead.
Changes:
- Parse signed/unsigned integers and floats using the destination type’s bit width (
reflect.Type.Bits()), rejecting overflows. - Apply the same bit-size-aware parsing in both the “set field” helper and the main request parameter parsing path.
- Add a regression test covering query parameter overflow for a narrow integer type (
int8).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| huma.go | Parse numeric parameter values using destination type bit-size to reject overflows. |
| huma_test.go | Add coverage ensuring overflow inputs are rejected (and handler is not called). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Found by Copilot: danielgtaylor#1096 (comment)
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.
Numeric request parameters are parsed using 64 bit parsing regardless of the
destination Go type, then assigned through reflection.
This can silently change user input rather than returning a 4xx validation error.