47 Commits

Author SHA1 Message Date
Khoajs Sync Bot
1f4bbea3d9 chore: apply Khoajs naming transformations (upstream sync)
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Node.js CI / build (20.x) (push) Has been cancelled
Node.js CI / build (22.x) (push) Has been cancelled
2026-04-17 19:46:56 +00:00
killa
2503a1fb14 feat: defer AsyncLocalStorage creation for v8 startup snapshots (#1946)
## Summary

- Defer `AsyncLocalStorage` creation when
`v8.startupSnapshot.isBuildingSnapshot()` is true, making Koa compatible
with Node.js startup snapshots
- Register a `v8.startupSnapshot.addDeserializeCallback` to properly
initialize `ctxStorage` after snapshot restoration
- Extract `getAsyncLocalStorage()` helper to consolidate creation logic

## Test plan

- [x] All 429 existing tests pass with 0 failures
- [x] `currentContext` tests verify both `asyncLocalStorage: true` and
custom `AsyncLocalStorage` instance paths work correctly
- [x] Normal (non-snapshot) code path is unchanged —
`v8.startupSnapshot?.isBuildingSnapshot?.()` returns `undefined` in
regular execution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 13:37:53 +08:00
killa
55ab9bab04 Merge commit from fork
When a malformed Host header containing @ symbol (e.g., "evil.com:fake@legitimate.com")
is received, use URL parser to correctly extract the actual host portion instead of
naively splitting by colon which would return attacker-controlled value.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-25 21:24:26 +08:00
Jeff Wainwright
863c2118f0 fix: only original value destroy if the new value is not a stream (#1914)
close https://github.com/koajs/koa/issues/1913
2025-10-27 12:23:33 +08:00
Jeff Wainwright
27df3b6e00 fix: adds steam clean up (#1910)
**Adds stream clean-up** in addition to nullish value clean-up.

- update from @fengmk2's identified issue
[here](https://github.com/koajs/koa/pull/1893#discussion_r2455395874).
   - https://github.com/koajs/koa/pull/1893#discussion_r2455395874
- Stackblitz display issue + fix
[here](https://stackblitz.com/~/github.com/yowainwright/koa-patch-ISSUE-1834_discussion_r2455395874?file=patch/koa/lib/response.js).
-
https://stackblitz.com/~/github.com/yowainwright/koa-patch-ISSUE-1834_discussion_r2455395874?file=patch/koa/lib/response.js
2025-10-24 13:51:42 +08:00
Jeff Wainwright
49a32077f6 feat: fixes mem leak relating to issue-1834 (#1893)
## Description

- closes #1834 
- closes #1882 
- closes #1889

## Checklist

- [x] I have ensured my pull request is not behind the main or master
branch of the original repository.
- [x] I have rebased all commits where necessary so that reviewing this
pull request can be done without having to merge it first.
- [x] I have written a commit message that passes commitlint linting.
- [x] I have ensured that my code changes pass linting tests.
- [x] I have ensured that my code changes pass unit tests.
- [x] I have described my pull request and the reasons for code changes
along with context if necessary.

## Checklist for 1834 (before re-pinging team)

- [x] Update stackblitz - [stackblitz demostrating error and
fix](https://stackblitz.com/edit/koa-patch-starter-pwupm4kr?file=README.md,index.js,patch%2Fkoa%2Flib%2Fapplication.js,vendor%2Fkoa%2Flib%2Fapplication.js)
- [x] Address comments
- [x] Re-review after merging 2 issues together
2025-10-22 11:50:13 -07:00
MK (fengmk2)
769fd75cc6 fix: normalize referer before redirect (#1908)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-18 22:20:14 +08:00
Jeff Wainwright
83128eb6cc fix: fixes response.attachment behavior leads to Content-Type Sniffing (#1904)
## Checklist

Added security-focused tests to verify:
  1. Content-Type is preserved when already set
2. Content-Type is still set when not previously defined (backwards
compatibility)
  3. The fix prevents XSS vulnerabilities with HTML and SVG files

credit "Luca Carettoni of Doyensec LLC" as [requested in the
advisory](https://github.com/koajs/koa/security/advisories/GHSA-c5vw-j4hf-j526).
2025-09-17 08:52:31 +08:00
fengmk2
422c551c63 Merge commit from fork
https://github.com/koajs/koa/security/advisories/GHSA-jgmv-j7ww-jx2x

close https://github.com/koajs/koa/issues/1892
2025-07-27 15:25:47 +08:00
Jeff Wainwright
9057541332 chore: removes done callbacks in tests [CHORE-1870] (#1875)
## Checklist

Chore: removes done callback; prefer async

- [x] I have ensured my pull request is not behind the main or master
branch of the original repository.
- [x] I have rebased all commits where necessary so that reviewing this
pull request can be done without having to merge it first.
- [x] I have written a commit message that passes commitlint linting.
- [x] I have ensured that my code changes pass linting tests.
- [x] I have ensured that my code changes pass unit tests.
- [x] I have described my pull request and the reasons for code changes
along with context if necessary.

---------

Co-authored-by: jongleberry <jonathanrichardong@gmail.com>
Co-authored-by: Jeff Wainwright <jeffry@tuta.com>
2025-05-08 00:06:19 -07:00
jongleberry
f7b9a1835f feat: add custom asyncLocalStorage support 2025-04-27 18:10:38 -07:00
jongleberry
cdc5802052 fix: remove a conlog 2025-04-27 16:55:08 -07:00
jongleberry
d601d7ba52 breaking: remove redirect(back) for v3 2025-04-27 16:50:35 -07:00
jongleberry
ff25eb4a7f fix: don't render redirect values in anchor ref 2025-04-06 14:35:16 -07:00
Jeff Wainwright
a10d08f9ab chore: updates tests to use node:assert/strict (#1865)
## Description

First PR. Migrates tests from `assert` to `node:assert/strict`.

## Checklist

- [x] I have ensured my pull request is not behind the main or master
branch of the original repository.
- [x] I have rebased all commits where necessary so that reviewing this
pull request can be done without having to merge it first.
- [x] I have written a commit message that passes commitlint linting.
- [x] I have ensured that my code changes pass linting tests.
- [x] I have ensured that my code changes pass unit tests.
- [x] I have described my pull request and the reasons for code changes
along with context if necessary.
2025-04-02 21:25:26 -07:00
KristapsUI
0486b65ef9 feat: support custom streams
closes #1825
2025-03-21 22:42:08 -07:00
jongleberry
c5ad22e8bb breaking: req.origin should display the origin header if it exists, not the current hostname closes #1008 2025-03-21 00:26:27 -07:00
jongleberry
40d5d3303b breaking: .body=<json> should not overwrite type if type already json
closes #1120
2025-03-21 00:17:17 -07:00
jongleberry
9ce4536d9e breaking: remove special ENOENT support (#1861)
This is a huge breaking change as it breaks `fs.createReadStream`
support. Instead, you'll have to make sure you'll handle the stream's
errors before it reaches the koa response logic. This is good as you'd
want to do this for all streams anyways. You can have an upstream
middleware like:


```js
app.use(async (ctx, next) {
  await next()

  // check if the object is a stream
  if (ctx.body?.readable && typeof ctx.body?.pipe === 'function') {
    await new Promise((resolve, reject) => { // wait for it to be either readable or throw an error
      ctx.body.on('readable', () => resolve())
      ctx.body.on('error', (err) => reject(err)) // TODO handle errors
    })
  }
})
```

closes #1420
2025-03-19 09:31:00 +08:00
jongleberry
af0547d5f6 don't coerce header value to string on set #1394 (#1859)
this is a rebase of https://github.com/koajs/koa/pull/1394. closes #1394
2025-03-17 21:43:21 -07:00
jongleberry
7a666e59f6 node@18 closes #1850 2025-03-16 21:30:24 -07:00
Imed Jaberi
4c34546413 deps: update http-errors to v2.0.0 (#1486)
- https://github.com/jshttp/http-errors/blob/master/HISTORY.md
2024-11-03 20:52:31 -08:00
Vlad Sirenko
ce6b3b6eee Use node test runner (#1845)
## Checklist
use `node --test` instead of `jest`
See: https://github.com/koajs/koa/issues/1837#issuecomment-2323002820

- [X] I have ensured my pull request is not behind the main or master
branch of the original repository.
- [X] I have rebased all commits where necessary so that reviewing this
pull request can be done without having to merge it first.
- [X] I have written a commit message that passes commitlint linting.
- [X] I have ensured that my code changes pass linting tests.
- [X] I have ensured that my code changes pass unit tests.
- [X] I have described my pull request and the reasons for code changes
along with context if necessary.
2024-10-27 22:04:24 -05:00
Martin Iwanowski
f9f7714e95 response.redirect: extract special-cased back, fixes #904 (#1115)
The simple solution to drop special-cased `'back'` in
`response.redirect`.
I can't label but should be labeled as version-major.

This PR **does not** make use of Symbol as purposed in #904.

**Edit**
If this solution is acceptable, a deprecation should be added to Koa 2
on `'back'` use.

---------

Co-authored-by: Kevin Peno <kjpeno@outlook.com>
2024-10-20 16:41:19 -07:00
jongleberry
0d9f062aa8 ⬆️ statuses@2.0.1
commit 84c89f25b880cf648044e2d0eeb14f9a43e1f2c9
Author: jongleberry <jonathanrichardong@gmail.com>
Date:   Sat Aug 31 11:02:37 2024 -0700

    package-lock++

commit 2c7715c797473d463ed73542d68e634f172dc3c3
Merge: 5af69c8 b95dfcb
Author: jongleberry <jonathanrichardong@gmail.com>
Date:   Sat Aug 31 10:56:58 2024 -0700

    Merge branch 'master' into update-statuses-to-v2.0.0

commit 5af69c87926db6f491af2b8882c07d7d141fe422
Author: imed jaberi <imed.jaberi@hotmail.fr>
Date:   Sat Apr 2 14:47:43 2022 +0100

    fix tests

commit 9af4bb37db0be416cd9e211ef4fc52f57de0cb69
Author: imed jaberi <imed.jaberi@hotmail.fr>
Date:   Sat Apr 2 14:43:51 2022 +0100

    lint code

commit 140be25c88d7641ce7cfc1463889d437e3cb939d
Author: imed jaberi <imed.jaberi@hotmail.fr>
Date:   Sat Apr 2 14:42:10 2022 +0100

    clean locks ---force

commit bc553ec713b16c1fe4d6a400637ab30590c176d2
Author: imed jaberi <imed.jaberi@hotmail.fr>
Date:   Sat Apr 2 14:35:12 2022 +0100

    clean locks

commit 3d7e22aef781820f7d611ad64f7622a7258e2c6d
Merge: ff65ef6 f3c67d9
Author: imed jaberi <imed.jaberi@hotmail.fr>
Date:   Sat Apr 2 14:31:30 2022 +0100

    resolve conflicts

commit ff65ef6c6b19c7f307726bae22eb8154894a14dc
Author: 3imed-jaberi <imed_jebari@hotmail.fr>
Date:   Tue Jul 14 10:52:50 2020 +0200

     deps: use the new statuses api --ctx --response --test

commit f565f3b732a6550a74506c480319e6efe4b51da7
Author: 3imed-jaberi <imed_jebari@hotmail.fr>
Date:   Tue Jul 14 10:52:31 2020 +0200

     deps: use the new statuses api --ctx --response --src

commit e8f7609ca405904fabc6669fa31be0df1c9ada55
Author: 3imed-jaberi <imed_jebari@hotmail.fr>
Date:   Tue Jul 14 10:50:49 2020 +0200

     deps: update statuses >> v2.0.0
2024-08-31 11:05:25 -07:00
jongleberry
c62a0a965b test: remove leaky handles (#1838) 2024-08-31 11:04:07 -07:00
Matthieu Tabarin
7cf1462d34 Feat: Replace node querystring with URLSearchParams (#1828)
Fix #1570 Replace node querystring with URLSearchParams it mimics the
way that querystring works

## Checklist

- [x] I have ensured my pull request is not behind the main or master
branch of the original repository.
- [x] I have rebased all commits where necessary so that reviewing this
pull request can be done without having to merge it first.
- [x] I have written a commit message that passes commitlint linting.
- [x] I have ensured that my code changes pass linting tests.
- [x] I have ensured that my code changes pass unit tests.
- [x] I have described my pull request and the reasons for code changes
along with context if necessary.
2024-08-30 21:50:02 -07:00
Matthieu Tabarin
8d5beb329d feat: add support web WHATWG (#1830)
closes https://github.com/koajs/koa/issues/1777
2024-06-28 22:45:36 +08:00
Leslie
b89e19a275 fix: improve body null check (#1814) 2024-05-30 09:02:33 +08:00
andrew0
5bc0b46516 fix: remove unused async local storage middleware (#1817)
This middleware was made obsolete by e98b8d1.
2024-05-30 08:59:19 +08:00
FDrag0n
185e701a8a fix: handle upper case protocol like HTTP or HTTPS (#1805)
Co-authored-by: fengmk2 <suqian.yf@antgroup.com>
2024-03-21 16:23:36 +08:00
fengmk2
435534aa08 fix: formatting redirect url on http(s) protocol url (#1804)
closes https://github.com/koajs/koa/issues/1800

pick from https://github.com/koajs/koa/pull/1803
2024-03-15 15:19:01 +08:00
Evgenii Troinov
ac61b8ca12 chore: Replacing eslint with standard cli (#1796) 2024-01-17 10:01:07 +08:00
Gxkl
e98b8d1918 fix: can not get currentContext in error handler (#1758) 2023-04-12 17:47:09 +08:00
fengmk2
9d2afef286 fix: should export createAsyncCtxStorageMiddleware function (#1725)
pick from https://github.com/koajs/koa/pull/1724
2022-12-07 15:06:01 +08:00
fengmk2
beb0b896a3 test: skip mock socket error on Node.js 18 2022-12-06 10:26:40 +08:00
fengmk2
fe76c4a284 refactor: required Node.js >= 12.17.0 2022-12-06 10:26:40 +08:00
shfshanyue
5e372304a9 chore: allow the compose function to be configurable 2022-07-02 10:35:11 +02:00
imed jaberi
30242ee546 fix: fix all eslint warns 2022-07-02 09:04:39 +02:00
jongleberry
65f9c939e1 context.response.get: fix test and lint 2021-08-17 22:19:39 -07:00
jongleberry
6cf6a95ac3 fix: Set body to if and @likegun closes #1059 closes #998 2021-08-17 22:12:13 -07:00
jongleberry
94c2ac4f0f fix: set content-Length header on explicit null body response @ognjenjevremovic closes #1528 #1525 2021-08-17 22:06:01 -07:00
jongleberry
39c0b48a7a fix: Do not response Content-Length if Transfer-Encoding is defined closes #1562 2021-08-17 21:47:13 -07:00
jongleberry
60c2d30a35 test: remove koa-convert and generators 2021-08-17 21:39:44 -07:00
jongleberry
e9494b5b3e lint: stick to standard
- less maintenance
- more strict
2021-08-17 21:35:33 -07:00
jongleberry
4a410cc2fb migrate assert.deepEqual => .deepStrictEqual 2021-08-17 21:29:16 -07:00
jongleberry
4545b59aa5 test: switch tests to jest 2021-08-17 21:27:08 -07:00