Skip to content

[Snyk] Upgrade hono from 4.6.12 to 4.7.0 #70

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

nerdy-tech-com-gitub
Copy link
Owner

@nerdy-tech-com-gitub nerdy-tech-com-gitub commented Mar 6, 2025

snyk-top-banner

Snyk has created this PR to upgrade hono from 4.6.12 to 4.7.0.

ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.


  • The recommended version is 9 versions ahead of your current version.

  • The recommended version was released a month ago.

Issues fixed by the recommended upgrade:

Issue Score Exploit Maturity
high severity Out-of-bounds Read
SNYK-JS-ELECTRON-8738836
211 No Known Exploit
Release notes
Package name: hono
  • 4.7.0 - 2025-02-07

    Release Notes

    Hono v4.7.0 is now available!

    This release introduces one helper and two middleware.

    • Proxy Helper
    • Language Middleware
    • JWK Auth Middleware

    Plus, Standard Schema Validator has been born.

    Let's look at each of these.

    Proxy Helper

    We sometimes use the Hono application as a reverse proxy. In that case, it accesses the backend using fetch. However, it sends an unintended headers.

    app.all('/proxy/:path', (c) => {
      // Send unintended header values to the origin server
      return fetch(`http://${originServer}/${c.req.param('path')}`)
    })

    For example, fetch may send Accept-Encoding, causing the origin server to return a compressed response. Some runtimes automatically decode it, leading to a Content-Length mismatch and potential client-side errors.

    Also, you should probably remove some of the headers sent from the origin server, such as Transfer-Encoding.

    Proxy Helper will send requests to the origin and handle responses properly. The above headers problem is solved simply by writing as follows.

    import { Hono } from 'hono'
    import { proxy } from 'hono/proxy'

    app.get('/proxy/:path', (c) => {
    return proxy(http://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">originServer</span><span class="pl-kos">}</span></span>/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">c</span><span class="pl-kos">.</span><span class="pl-c1">req</span><span class="pl-kos">.</span><span class="pl-en">param</span><span class="pl-kos">(</span><span class="pl-s">'path'</span><span class="pl-kos">)</span><span class="pl-kos">}</span></span>)
    })

    You can also use it in more complex ways.

    app.get('/proxy/:path', async (c) => {
      const res = await proxy(
        `http://${originServer}/${c.req.param('path')}`,
        {
          headers: {
            ...c.req.header(),
            'X-Forwarded-For': '127.0.0.1',
            'X-Forwarded-Host': c.req.header('host'),
            Authorization: undefined,
          },
        }
      )
      res.headers.delete('Set-Cookie')
      return res
    })

    Thanks @ usualoma!

    Language Middleware

    Language Middleware provides 18n functions to Hono applications. By using the languageDetector function, you can get the language that your application should support.

    import { Hono } from 'hono'
    import { languageDetector } from 'hono/language'

    const app = new Hono()

    app.use(
    languageDetector({
    supportedLanguages: ['en', 'ar', 'ja'], // Must include fallback
    fallbackLanguage: 'en', // Required
    })
    )

    app.get('/', (c) => {
    const lang = c.get('language')
    return c.text(Hello! Your language is <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">lang</span><span class="pl-kos">}</span></span>)
    })

    You can get the target language in various ways, not just by using Accept-Language.

    • Query parameters
    • Cookies
    • Accept-Language header
    • URL path

    Thanks @ lord007tn!

    JWK Auth Middleware

    Finally, middleware that supports JWK (JSON Web Key) has landed. Using JWK Auth Middleware, you can authenticate by verifying JWK tokens. It can access keys fetched from the specified URL.

    import { Hono } from 'hono'
    import { jwk } from 'hono/jwk'

    app.use(
    '/auth/*',
    jwk({
    jwks_uri: https://<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">backendServer</span><span class="pl-kos">}</span></span>/.well-known/jwks.json,
    })
    )

    app.get('/auth/page', (c) => {
    return c.text('You are authorized')
    })

    Thanks @ Beyondo!

    Standard Schema Validator

    Standard Schema provides a common interface for TypeScript validator libraries. Standard Schema Validator is a validator that uses it. This means that Standard Schema Validator can handle several validators, such as Zod, Valibot, and ArkType, with the same interface.

    The code below really works!

    import { Hono } from 'hono'
    import { sValidator } from '@ hono/standard-validator'
    import { type } from 'arktype'
    import * as v from 'valibot'
    import { z } from 'zod'

    const aSchema = type({
    agent: 'string',
    })

    const vSchema = v.object({
    slag: v.string(),
    })

    const zSchema = z.object({
    name: z.string(),
    })

    const app = new Hono()

    app.get(
    '/:slag',
    sValidator('header', aSchema),
    sValidator('param', vSchema),
    sValidator('query', zSchema),
    (c) => {
    const headerValue = c.req.valid('header')
    const paramValue = c.req.valid('param')
    const queryValue = c.req.valid('query')
    return c.json({ headerValue, paramValue, queryValue })
    }
    )

    const res = await app.request('/foo?name=foo', {
    headers: {
    agent: 'foo',
    },
    })

    console.log(await res.json())

    Thanks @ muningis!

    New features

    • feat(helper/proxy): introduce proxy helper #3589
    • feat(logger): include query params #3702
    • feat: add language detector middleware and helpers #3787
    • feat(hono/context): add buffer returns #3813
    • feat(hono/jwk): JWK Auth Middleware #3826
    • feat(etag): allow for custom hashing methods to be used to etag #3832
    • feat(router): support greedy matches with subsequent static components #3888

    All changes

    New Contributors

    Full Changelog: v4.6.20...v4.7.0

  • 4.6.20 - 2025-01-31

    What's Changed

    New Contributors

    Full Changelog: v4.6.19...v4.6.20

  • 4.6.19 - 2025-01-26

    What's Changed

    • fix(types): missing response type on OnHandlerInterface by @ sor4chi in #3852
    • fix(helper/adapter): env should set c type correctly by @ yusukebe in #3856

    Full Changelog: v4.6.18...v4.6.19

  • 4.6.18 - 2025-01-23

    What's Changed

    Full Changelog: v4.6.17...v4.6.18

  • 4.6.17 - 2025-01-18

    What's Changed

    New Contributors

    Full Changelog: v4.6.16...v4.6.17

  • 4.6.16 - 2025-01-05

    What's Changed

    • fix(jsx/dom): should not return memoized result when context is changed by @ usualoma in #3792
    • fix(context): single body overrides other returns by @ askorupskyy in #3800
    • fix(types): correct app.on(method,path[],middleware,handler) type by @ yusukebe in #3802

    Full Changelog: v4.6.15...v4.6.16

  • 4.6.15 - 2024-12-28

    c.json() etc. throwing type error when the status is contentless code, e.g., 204

    From this release, when c.json(), c.text(), or c.html() returns content, specifying a contentless status code such as 204 will now throw a type error.

    CleanShot 2024-12-28 at 16 47 39@2x

    At first glance, this seems like a breaking change but not. It is not possible to return a contentless response with c.json() or c.text(). So, in that case, please use c.body().

    app.get('/', (c) => {
      return c.body(null, 204)
    })

    What's Changed

    • fix(jsr): exclude unused markdown files by @ ryuapp in #3767
    • feat(hono/context): contentful status code typing by @ askorupskyy in #3763
    • refactor(context): remove lint errors by @ yusukebe in #3769
    • feat(context): ResponseInit accepts generics StatusCode for status by @ yusukebe in #3770
    • feat(utils/cookie): Ability to set a priority to cookies in setCookie options by @ Beyondo in #3762
    • fix(hono-base): don't use Symbol for COMPOSED_HANDLER by @ yusukebe in #3773

    New Contributors

    Full Changelog: v4.6.14...v4.6.15

  • 4.6.14 - 2024-12-14

    What's Changed

    • perf(pattern-router): improve performance when create null object by @ EdamAme-x in #3730
    • perf(trie-router): avoid calling spread operator for Object.create(null) by @ usualoma in #3735
    • fix: Remove charset parameter from MIME type of application/json by @ SaekiTominaga in #3743
    • fix(streaming) Prevent console.error(undefined) when pipe is aborted by @ aantthony in #3747

    New Contributors

Snyk has created this PR to upgrade hono from 4.6.12 to 4.7.0.

See this package in npm:
hono

See this project in Snyk:
https://app.snyk.io/org/nerds-github/project/7ac3a559-e245-43bc-aea8-6d68ed454985?utm_source=github&utm_medium=referral&page=upgrade-pr
Copy link

sourcery-ai bot commented Mar 6, 2025

Reviewer's Guide by Sourcery

This pull request upgrades the hono dependency from version 4.6.12 to 4.7.0. This upgrade includes new features such as Proxy Helper, Language Middleware, JWK Auth Middleware, and Standard Schema Validator. It also addresses a high severity vulnerability: Out-of-bounds Read.

Sequence diagram for Proxy Helper

sequenceDiagram
  participant Client
  participant Hono App
  participant Origin Server

  Client->>Hono App: GET /proxy/:path
  activate Hono App
  Hono App->>Origin Server: fetch(`http://${originServer}/${c.req.param('path')}`, options)
  activate Origin Server
  Origin Server-->>Hono App: Response
  deactivate Origin Server
  Hono App-->>Client: Response
  deactivate Hono App
Loading

Sequence diagram for Language Middleware

sequenceDiagram
  participant Client
  participant Hono App

  Client->>Hono App: GET /
  activate Hono App
  Hono App->>Hono App: languageDetector(options)
  Hono App->>Hono App: c.get('language')
  Hono App-->>Client: Response with language
  deactivate Hono App
Loading

Sequence diagram for JWK Auth Middleware

sequenceDiagram
  participant Client
  participant Hono App
  participant JWK Server

  Client->>Hono App: GET /auth/page with JWT
  activate Hono App
  Hono App->>JWK Server: Fetch JWKS from jwks_uri
  activate JWK Server
  JWK Server-->>Hono App: JWKS
  deactivate JWK Server
  alt Valid JWT
    Hono App->>Hono App: Verify JWT with JWKS
    Hono App-->>Client: 200 You are authorized
  else Invalid JWT
    Hono App-->>Client: 401 Unauthorized
  end
  deactivate Hono App
Loading

File-Level Changes

Change Details Files
Upgraded the hono dependency to version 4.7.0.
  • Updated the hono dependency from version 4.6.12 to 4.7.0.
apps/main/package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have skipped reviewing this pull request. Here's why:

  • It seems to have been created by a bot ('[Snyk]' found in title). We assume it knows what it's doing!
  • We don't review packaging changes - Let us know if you'd like us to change this.

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