Hono 4.13.22 Tightens Security: Strict basicAuth(), Prototype Pollution Guard in parseBody(), and Clean SSEBrief · digest for November 26
Brief≈ 2 min

Hono 4.13.22 Tightens Security: Strict basicAuth(), Prototype Pollution Guard in parseBody(), and Clean SSE

Forget to set an environment variable for a password, and basicAuth() in Hono used to keep running—quietly hashing undefined as the literal string "undefined". Anyone could log in. Hono 4.13.22 closes that hole: the middleware now throws right at startup if either username or password isn't a string.

It also patches several other JS traps: parseBody({ dot: true }) now skips constructor.prototype. alongside __proto__. (blocking prototype pollution), writeSSE() forbids \r and \n in retry, getMimeType() stops returning prototype properties for hello.constructor, and mount restores the decodeURI(path) check previously stripped by the bundler.

import { Hono } from 'hono'
import { basicAuth } from 'hono/basic-auth'

// Validate env vars before boot, otherwise basicAuth() will throw on startup
const username = process.env.ADMIN_USER
const password = process.env.ADMIN_PASS
if (!username || !password) {
  throw new Error('ADMIN_USER and ADMIN_PASS must be set')
}

const app = new Hono()
app.use('/admin/*', basicAuth({ username, password }))
app.post('/admin/form', async (c) => {
  // __proto__. and constructor.prototype. keys are now ignored
  const body = await c.req.parseBody({ dot: true })
  return c.json({ ok: true, keys: Object.keys(body) })
})

Before updating, audit .env in staging and CI: a broken config now crashes the process at boot instead of leaving "undefined" as a live password in production.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 6