-
Notifications
You must be signed in to change notification settings - Fork 0
[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
base: dev
Are you sure you want to change the base?
[Snyk] Upgrade hono from 4.6.12 to 4.7.0 #70
Conversation
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
Reviewer's Guide by SourceryThis pull request upgrades the Sequence diagram for Proxy HelpersequenceDiagram
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
Sequence diagram for Language MiddlewaresequenceDiagram
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
Sequence diagram for JWK Auth MiddlewaresequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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.
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:
SNYK-JS-ELECTRON-8738836
Release notes
Package name: hono
Release Notes
Hono v4.7.0 is now available!
This release introduces one helper and two 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.For example,
fetch
may sendAccept-Encoding
, causing the origin server to return a compressed response. Some runtimes automatically decode it, leading to aContent-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 { 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.
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 { 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
.Accept-Language
headerThanks @ 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 { 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 { 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
All changes
yarn
by @ EdamAme-x in #3878toLowerCase()
is unnecessary forreq.header()
by @ yusukebe in #3880env
type by @ yusukebe in #3885c.json({})
by @ yusukebe in #3873deno.lock
by @ yusukebe in #3897New Contributors
Full Changelog: v4.6.20...v4.7.0
What's Changed
np
by @ yusukebe in #3874New Contributors
Full Changelog: v4.6.19...v4.6.20
What's Changed
OnHandlerInterface
by @ sor4chi in #3852env
should setc
type correctly by @ yusukebe in #3856Full Changelog: v4.6.18...v4.6.19
What's Changed
types.ts
by @ yusukebe in #3836ParamKey
simply by @ yusukebe in #3837factory.createMiddleware()
by @ yusukebe in #3849Full Changelog: v4.6.17...v4.6.18
What's Changed
New Contributors
Full Changelog: v4.6.16...v4.6.17
What's Changed
app.on(method,path[],middleware,handler)
type by @ yusukebe in #3802Full Changelog: v4.6.15...v4.6.16
c.json()
etc. throwing type error when the status is contentless code, e.g., 204From this release, when
c.json()
,c.text()
, orc.html()
returns content, specifying a contentless status code such as 204 will now throw a type error.At first glance, this seems like a breaking change but not. It is not possible to return a contentless response with
c.json()
orc.text()
. So, in that case, please usec.body()
.What's Changed
ResponseInit
accepts genericsStatusCode
forstatus
by @ yusukebe in #3770COMPOSED_HANDLER
by @ yusukebe in #3773New Contributors
Full Changelog: v4.6.14...v4.6.15
What's Changed
Object.create(null)
by @ usualoma in #3735charset
parameter from MIME type ofapplication/json
by @ SaekiTominaga in #3743New Contributors