-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: Invalid UTF-8 Input Should not Cause HTTP 500 Errors #22612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22612 +/- ##
===========================================
+ Coverage 45.36% 65.85% +20.49%
===========================================
Files 244 1073 +829
Lines 13333 116112 +102779
Branches 2719 2931 +212
===========================================
+ Hits 6049 76471 +70422
- Misses 6983 35403 +28420
- Partials 301 4238 +3937
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Because the middleware harbor/src/server/middleware/url/parse.go Line 27 in 26f6310
|
Do I understand you correctly. You want us to merge both middleware implementations into parse.go? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new validation middleware to prevent HTTP 500 errors caused by invalid UTF-8 input and null bytes in query parameters. The middleware intercepts requests at the middleware layer and returns HTTP 400 Bad Request errors before invalid data reaches the database (PostgreSQL), which would otherwise throw SQLSTATE 22021 errors.
Key changes:
- New
validatemiddleware package that validates query string parameters for null bytes and invalid UTF-8 sequences - Integration of the middleware into the global middleware chain, positioned after URL parsing middleware
- Comprehensive test coverage including edge cases for Unicode, emoji, and various invalid input patterns
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/server/middleware/validate/validate.go | Implements the validation middleware with null byte and UTF-8 validation logic |
| src/server/middleware/validate/validate_test.go | Comprehensive test suite covering valid/invalid inputs including null bytes, invalid UTF-8, Unicode, and emoji |
| src/core/middlewares/middlewares.go | Integrates the validate middleware into the global middleware chain after URL parsing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bupd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
This fixes the error by returning a 400 error instead of 500 on invalid user input.
Please indicate you've done the following: