-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 web-server: Handles safely overly long status messages in web server responses #7760
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
Conversation
matusdrobuliak66
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.
Thanks a lot for the effort 👍
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7760 +/- ##
==========================================
- Coverage 86.79% 86.50% -0.30%
==========================================
Files 1841 1433 -408
Lines 71500 59880 -11620
Branches 1214 617 -597
==========================================
- Hits 62060 51800 -10260
+ Misses 9098 7882 -1216
+ Partials 342 198 -144
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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
Adds a centralized safe_status_message helper to sanitize and truncate HTTP reason phrases, and replaces ad-hoc newline stripping with this function across the web server and library.
- Replaces inline newline removal and manual truncation with
safe_status_messagein server exporters, exception classes, and factory. - Introduces
safe_status_messageinservicelib.aiohttp.rest_responseswith tests covering newline replacement and truncation. - Updates tests to validate that sanitized messages can be used as HTTP reasons without errors.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| services/web/server/src/simcore_service_webserver/exporter/utils.py | Applied safe_status_message to FileResponse reason parameter |
| services/web/server/src/simcore_service_webserver/exporter/exceptions.py | Applied safe_status_message to SDSException reason parameter |
| services/web/server/src/simcore_service_webserver/exception_handling/_factory.py | Applied safe_status_message in JSON error response factory |
| packages/service-library/src/servicelib/aiohttp/rest_responses.py | Added safe_status_message implementation and used it in errors |
| packages/service-library/tests/aiohttp/test_rest_responses.py | Added parameterized tests for safe_status_message behavior |
Comments suppressed due to low confidence (1)
packages/service-library/tests/aiohttp/test_rest_responses.py:145
- The test uses
web.Responsebutwebis not imported in this test module, leading to a NameError. Consider addingfrom aiohttp import webat the top of the file.
web.Response(reason=result)
|
@mergify queue |
🟠 Waiting for conditions to match
|
sanderegg
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.
very good! thanks a lot!
… newlines; add tests for safe_status_message
…attributes in exception responses
…sponses in error handlers
…nsistent response formatting
…d append ellipsis; enhance tests for truncation behavior
…andling; adjust tests accordingly
…s; adjust tests for response structure
93e08d2 to
efccac2
Compare
|



What do these changes do?
Addresses excessively long messages passed to the HTTP status line which is encoded with the
reason=parameter in aiohttp Responses.--
IMPORTANT difference between
reasonandtextinaiohttp.HTTPException!Using reason in an HTTP error like

web.HTTPNotFound(reason="something short")gets into the header's status lineFor long messages, use instead
web.HTTPNotFound(text="something very detailed")In
aiohttp.web.HTTPException(e.g.,HTTPBadRequest,HTTPNotFound, etc.), bothreasonandtextparameters can be set when raising an exception, but they serve different purposes:reasonHTTP/1.1 400 Bad Request→"Bad Request"is the reason."Not Found"for 404).text"Invalid user ID".When to use what
reason=text=Example
Response:
Summary
reason=to override the HTTP reason phrase (rare).text=to define the body of the error response (common).text=.reason=only if you want the HTTP status line to say something other than the default.Related issue/s
reasonattribute and new lines #7755How to test
Dev-ops
None