Skip to content
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

fix(middleware/jwt): fix incorrect assumption in jwt impl #2775

Merged
merged 2 commits into from
May 23, 2024

Conversation

boehs
Copy link
Contributor

@boehs boehs commented May 23, 2024

The author should do the following, if applicable

Please see https://discord.com/channels/595317990191398933/1243024990652207115/1243024990652207115 (in the cloudflare discord)

THIS WILL BREAK PRODUCTION

In the docs it says

app.use(
  '/auth/*',
  jwt({
    secret: 'it-is-very-secret',
  })
)
app.get('/auth/page', (c) => {
  return c.text('You are authorized')
})

realalitically code in production will look more like

app.use(
  '/auth/*',
  jwt({
    secret: process.env.SECRET,
  })
)
app.get('/auth/page', (c) => {
  return c.text('You are authorized')
})

however, if this app.use is at the top level, in some instances in cloudflare process.env can be undefined. Nobody noticed this, because the code failed to check if it was actually defined.

edit: another solution would be to move this check inside the return callback, but this means that every API call it would run the getter on process.env which would make it susceptible to runtime manipulation.

Though actually if my theory that this is an issue is correct, in its current impl where the check is running before the callback is constructed, it is still vulnerable to runtime manipulation without reruning the check because it never does let secret = options.secret so if you could modify the value of secret (eg if it is a reference to process.env.secret and you modify it elsewhere) but actually, I think I'm wrong because when you construct an object like let obj = { secret: process.env.SECRET }, changing process.env wouldn't have an impact because when SECRET is accessed thats no longer a reference type, thats a copy.

HOWEVER if you access process.env.SECRET every single request, like when I proposed

edit: another solution would be to move this

it would hit the ref type every single request, so that would make it a vuln

  • Add tests
  • Run tests
  • bun denoify to generate files for Deno
  • bun run format:fix && bun run lint:fix to format the code

@yusukebe
Copy link
Member

Hi @boehs

Thanks for the PR. You are right. options.secret should be checked first.

I think this will not be a "breaking change." It just changes the internal behavior in the JWT middleware, so we can ship it as a patch or minor release.

One thing. Could you run the bun run denoify to generate files for Deno and push it?

@boehs
Copy link
Contributor Author

boehs commented May 23, 2024

Hi @boehs

Thanks for the PR. You are right. options.secret should be checked first.

I think this will not be a "breaking change." It just changes the internal behavior in the JWT middleware, so we can ship it as a patch or minor release.

yeah the breaking assumption was before I tried to pentest it and found it wasn't working with undefined and discovered that by luck there was an exception. I'll denoify it now

@boehs
Copy link
Contributor Author

boehs commented May 23, 2024

done

@yusukebe yusukebe changed the title breaking change: fix incorrect assumption in jwt impl fix(middleware/jwt): fix incorrect assumption in jwt impl May 23, 2024
@yusukebe
Copy link
Member

@boehs

Thank you! I'll merge this now and will ship it.

@yusukebe yusukebe merged commit cac22e4 into honojs:main May 23, 2024
10 checks passed
yusukebe pushed a commit that referenced this pull request May 24, 2024
* breaking change: fix incorrect assumption in jwt impl

* denofiy
nicolewhite referenced this pull request in autoblocksai/cli May 29, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [hono](https://hono.dev/) ([source](https://github.com/honojs/hono))
| [`4.3.8` ->
`4.4.0`](https://renovatebot.com/diffs/npm/hono/4.3.8/4.4.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/hono/4.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/hono/4.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/hono/4.3.8/4.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/hono/4.3.8/4.4.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>honojs/hono (hono)</summary>

###
[`v4.4.0`](https://github.com/honojs/hono/compare/v4.3.11...v4.4.0)

[Compare
Source](https://github.com/honojs/hono/compare/v4.3.11...v4.4.0)

### [`v4.3.11`](https://github.com/honojs/hono/releases/tag/v4.3.11)

[Compare
Source](https://github.com/honojs/hono/compare/v4.3.10...v4.3.11)

#### What's Changed

- fix(middleware/jwt): fix incorrect assumption in jwt impl by
[@&#8203;boehs](https://github.com/boehs) in
[https://github.com/honojs/hono/pull/2775](https://github.com/honojs/hono/pull/2775)

#### New Contributors

- [@&#8203;boehs](https://github.com/boehs) made their first
contribution in
[https://github.com/honojs/hono/pull/2775](https://github.com/honojs/hono/pull/2775)

**Full Changelog**:
honojs/hono@v4.3.10...v4.3.11

### [`v4.3.10`](https://github.com/honojs/hono/releases/tag/v4.3.10)

[Compare
Source](https://github.com/honojs/hono/compare/v4.3.9...v4.3.10)

#### What's Changed

- fix(secure-header): Replace NodeJS Buffer API by
[@&#8203;watany-dev](https://github.com/watany-dev) in
[https://github.com/honojs/hono/pull/2761](https://github.com/honojs/hono/pull/2761)
- fix(http-exception): prioritize the status code by
[@&#8203;yusukebe](https://github.com/yusukebe) in
[https://github.com/honojs/hono/pull/2767](https://github.com/honojs/hono/pull/2767)
- feat(etag): export `RETAINED_304_HEADERS` by
[@&#8203;yusukebe](https://github.com/yusukebe) in
[https://github.com/honojs/hono/pull/2763](https://github.com/honojs/hono/pull/2763)

**Full Changelog**:
honojs/hono@v4.3.9...v4.3.10

### [`v4.3.9`](https://github.com/honojs/hono/releases/tag/v4.3.9)

[Compare
Source](https://github.com/honojs/hono/compare/v4.3.8...v4.3.9)

#### What's Changed

- fix(factory): export `CreateHandlersInterface` by
[@&#8203;yusukebe](https://github.com/yusukebe) in
[https://github.com/honojs/hono/pull/2752](https://github.com/honojs/hono/pull/2752)
- feat(aws-lambda): add support for alb multiValueQueryStringParameters
by [@&#8203;yiss](https://github.com/yiss) in
[https://github.com/honojs/hono/pull/2751](https://github.com/honojs/hono/pull/2751)

**Full Changelog**:
honojs/hono@v4.3.8...v4.3.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone
America/Chicago, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/autoblocksai/cli).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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