bug fix: serve /report error responses as text/html (not octet-stream) - #41
Merged
Conversation
The /report endpoints use `@serializer contentType list(type="application/octet-stream")` so finished report bytes pass through untouched. But the endpoint-level error paths returned a bare HTML string, which the serializer then labeled application/octet-stream -- so a 400 error page downloaded instead of rendering in the browser. Add an html_error(res, status, message) helper that sets the status, a text/html Content-Type, and the body, then returns the response object -- the same pattern report_response() already uses for successful HTML reports, which bypasses the octet-stream serializer. Route all GET/POST /report validation errors and the ejamit_interface tryCatch failures through it; the tryCatch now returns the condition and is checked with inherits(result, "error"). Verified locally: GET/POST /report error cases now return 400 text/html (previously octet-stream); successful reports and the docs page / root redirect are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes /report endpoint error responses being served with Content-Type: application/octet-stream (due to the endpoint-level octet-stream serializer), which caused browsers to download HTML error pages instead of rendering them.
Changes:
- Added an
html_error(res, status, message)helper that writes an HTML error body to the response object and sets an explicittext/htmlContent-Type. - Routed
/reportvalidation failures andejamit_interface()tryCatchfailures throughhtml_error()to ensure consistent, renderable HTML errors. - Updated
tryCatcherror handling to return the error condition and detect failures viainherits(result, "error").
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
handle_error(..., "html") interpolated the message directly into the error page. Now that /report errors render as text/html, that could break markup or become a reflected-injection vector if a message ever carries user-influenced text. Add an escape_html() helper and apply it in handle_error()'s HTML branch (escapes &, <, >, ", ' -- ampersand first). The JSON branch is unchanged (the JSON serializer encodes safely) and plain static messages are unaffected. Unit-tested with a <script> payload; endpoints still return 400 text/html. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
The
/reportendpoints declare#* @serializer contentType list(type = "application/octet-stream")so finished report bytes (HTML or PDF) pass through untouched. But their endpoint-level error paths returned a bare HTML string, which the octet-stream serializer then labeledContent-Type: application/octet-stream. Result: a400error page downloads as a file instead of rendering in the browser.(Found by review during the #36/#40 merge — pre-existing, not introduced by that work.)
Fix
Add a small
html_error(res, status, message)helper that sets the status, an explicittext/htmlContent-Type, and the body, then returns the response object — the same patternreport_response()already uses for successful HTML reports, which bypasses the octet-stream serializer.Route every
GET/POST /reportvalidation error and theejamit_interface()tryCatchfailures through it. ThetryCatchnow returns the condition and is checked withinherits(result, "error")(instead of the oldis.character(result)on a returned string).Scope:
/reportonly./dataand/queryuse the default JSON serializer and were already fine;report_response()'s ownfileextensionvalidation already settext/html.Verified locally
/reportlat/lon count mismatchtext/html/reportbuffer>15(exercises thetryCatchpath)text/html/reportempty bodytext/html/report?fips=10001&fileextension=html(success)text/html(unchanged)GET /redirect //__docs__/🤖 Generated with Claude Code