Repository navigation
fix(timing): escape double quotes and backslashes in Server-Timing descriptions - #5478
Open
MustafaKemal0146 wants to merge 2 commits into
Open
MustafaKemal0146 wants to merge 2 commits into
MustafaKemal0146 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review comments remain, and regression coverage is included.
Review effort: Lite
Findings: None
What changed in this PR
Fixes Server-Timing description serialization by escaping backslashes and double quotes.
Changes:
- Escapes metric descriptions before header serialization.
- Adds regression tests for quotes, backslashes, and total descriptions.
| File | Summary |
|---|---|
src/middleware/timing/timing.ts |
Escapes quoted-string characters in metric descriptions. |
src/middleware/timing/index.test.ts |
Adds serialization tests for escaped descriptions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
The author should do the following, if applicable
pnpm run check:fixto format and lint the codeDescription
In
src/middleware/timing/timing.ts, metric descriptions (descriptionandvalueDescription) were interpolated intodesc="..."without escaping quotes or backslashes.When descriptions contain double quotes (e.g.
setMetric(c, 'db', 12.3, 'Query "users"')), the resulting header has invalid syntax:Server-Timing: db;dur=12.3;desc="Query "users""According to RFC 9110 Section 5.6.4 and W3C Server Timing Section 2.1,
descis serialized as a quoted-string; inner"and\characters must be backslash-escaped.This change escapes backslashes and double quotes in
descriptionandvalueDescription:This fixes quoted-string escaping per RFC 9110 and matches the quote-escaping approach in Hono's
bearer-authmiddleware.Test Plan
Added unit tests in
src/middleware/timing/index.test.tsverifying expected header outputs:'db;dur=12.3;desc="Query \\"users\\""''cache;desc="hit \\"fast\\""''fs;dur=5.0;desc="path\\\\to\\\\\\"file\\""'totalDescription:'desc="Total \\"App\\" Time"'Verification:
pnpm exec vitest run src/middleware/timing(20/20 passed)pnpm run check:fix(clean)Disclosure: Implemented with AI assistance under human review.