Skip to content

fix: use Object.create(null) when parsing query, headers, and params - #5161

Merged
yusukebe merged 1 commit into
mainfrom
fix/object-create-null
Jul 24, 2026
Merged

fix: use Object.create(null) when parsing query, headers, and params#5161
yusukebe merged 1 commit into
mainfrom
fix/object-create-null

Conversation

@yusukebe

@yusukebe yusukebe commented Jul 24, 2026

Copy link
Copy Markdown
Member

A __proto__ key in a request could change the prototype of the returned object. I use Object.create(null) to keep __proto__ as a normal key. This is limited to that single object and does not touch Object.prototype, so it is not prototype pollution. This is a code-quality fix, not a security fix.

By the way, I am planning to create a utility function to do Object.create(null) to reduce the bundle size.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@github-actions

Copy link
Copy Markdown

Bundle size check

main (44f8843) #5161 (94fc4b1) +/-
Bundle Size (B) 18,998B 19,032B 34B
Bundle Size (KB) 18.55K 18.59K 0.04K

Compiler Diagnostics (tsc)

main (44f8843) #5161 (94fc4b1) +/-
Files 83 83 0
Lines 59,439 59,439 0
Identifiers 60,614 60,614 0
Symbols 105,939 105,939 0
Types 159,727 159,727 0
Instantiations 413,958 413,958 0
Memory used 167,923K 167,940K 17K
I/O read 0.01s 0.01s 0s
I/O write 0s 0s 0s
Parse time 0.34s 0.36s 0.02s
Bind time 0.14s 0.14s 0s
Check time 1.35s 1.38s 0.03s
Emit time 0s 0s 0s
Total time 1.83s 1.89s 0.06s

Compiler Diagnostics (typescript-go)

main (44f8843) #5161 (94fc4b1) +/-
Files 215 215 0
Lines 147,087 147,087 0
Identifiers 121,968 121,968 0
Symbols 188,307 188,307 0
Types 259,012 259,012 0
Instantiations 621,523 621,523 0
Memory used 160,846K 160,855K 9K
Memory allocs 1,776,841 1,776,878 37
Config time 0.001s 0.001s 0s
BuildInfo read time 0.001s 0s -0.001s
Parse time 0.093s 0.099s 0.006s
Bind time 0s 0s 0s
Check time 0.444s 0.443s -0.001s
Emit time 0.005s 0.012s 0.007s
Changes compute time 0.023s 0.027s 0.004s
Total time 0.6s 0.649s 0.049s

Reported by octocov

@github-actions

Copy link
Copy Markdown

HTTP Performance Benchmark

Framework Runtime Average Ping Query Body
hono (origin/main) bun 33,839.99 46,051.48 30,652.86 24,815.62
hono (current) bun 33,377.52 44,657.53 30,764.52 24,710.50
Change -1.37% -3.03% +0.36% -0.42%

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.04%. Comparing base (44f8843) to head (8b1ca56).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5161   +/-   ##
=======================================
  Coverage   79.04%   79.04%           
=======================================
  Files         154      154           
  Lines       10779    10779           
  Branches     2256     2256           
=======================================
  Hits         8520     8520           
  Misses       2259     2259           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe

Copy link
Copy Markdown
Member Author

Hey @usualoma !

Can you review this? As I wrote in the description, this should not be a security fix.

@usualoma

Copy link
Copy Markdown
Member

@yusukebe
Thank you!
Yes, I also understand that there are currently no issues in terms of security, but just to be safe, I agree that we should use Object.create(null)!

@yusukebe

Copy link
Copy Markdown
Member Author

@usualoma Thank you! Merging.

@yusukebe
yusukebe merged commit c85aead into main Jul 24, 2026
20 checks passed
@yusukebe
yusukebe deleted the fix/object-create-null branch July 24, 2026 01:57
MadaBurns pushed a commit to MadaBurns/bv-mcp that referenced this pull request Jul 26, 2026
Production framework bump, patch-level. Reviewed against actual usage:

  - SSE fixes do not apply: our MCP SSE transport is a hand-rolled
    ReadableStream in src/lib/sse.ts, not hono/streaming's streamSSE.
  - secure-headers CSP fix does not apply: middleware not used.
  - parseBody/multipart fixes do not apply: only the native
    c.req.formData() is used, in the OAuth authorize/token routes.
  - Object.create(null) for query/header/param parsing (honojs/hono#5161)
    is the one change with real blast radius, since c.req.query() and
    c.req.param() are used throughout. Both hasOwnProperty call sites in
    src/ use the safe Object.prototype.hasOwnProperty.call() form and
    neither operates on a hono-derived object, so this is safe — and it
    is a prototype-pollution hardening improvement.

Hono imports in src/ are limited to Hono, Context, and hono/cors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants