415 Commits

Author SHA1 Message Date
Khoajs Sync Bot
4ec52ed9c8 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 21:07:17 +00:00
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
Imed Jaberi
0acad8ff37 feat: replace cache-content-type with mime-types directly (#1886)
## 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-06-06 13:11:57 +01:00
Imed Jaberi
2f6e8147db feat: replace debug module with pure node:util::debuglog (#1885)
## 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-06-05 22:32:10 +01:00
jongleberry
f7b9a1835f feat: add custom asyncLocalStorage support 2025-04-27 18:10:38 -07:00
jongleberry
28e8fed28e fix: remove unused depd 2025-04-27 17:23:36 -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
jongleberry
4fe9b65473 docs: add TODO about using a 3rd party library for is-stream 2025-03-21 22:43:19 -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
zhennann
153380b817 docs: fix asyncLocalStorage comment (#1849)
jsdoc of options.asyncLocalStorage

## 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-03-16 21:17:51 -07:00
titanism
04429e4436 chore: fixed lint per <5054af6e31> 2025-02-26 23:39:51 -06:00
Jan Kaiser
399cb6b0dd fix missing cleanup, if response socket is no longer writeable (issue 1547) (#1593)
Relates to issue #1547, see my [comment
there](https://github.com/koajs/koa/issues/1547#issuecomment-908370552)

Co-authored-by: Jan Kaiser <jan.kaiser@boerse-go.de>
Co-authored-by: titanism <101466223+titanism@users.noreply.github.com>
2025-02-26 23:28:52 -06:00
fengmk2
5054af6e31 Merge commit from fork
* fix: avoid redos on host and protocol getter

Only effect on app.proxy enable

closes https://github.com/koajs/koa/security/advisories/GHSA-593f-38f6-jp5m

* 3.0.0-alpha.3
2025-02-12 10:14:18 +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
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
Matthieu Tabarin
757e4ebc51 deps: make "only" package inside (#1824)
closes https://github.com/koajs/koa/issues/1802
2024-06-20 12:26:12 +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
Leslie
f85214a5bd docs: Modify options type in the Application class (#1812) 2024-04-22 14:22:59 +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
那里好脏不可以
5ba533f831 chore: fix jsdoc and typo (#1662) 2023-11-08 23:05:20 +08:00
hustLer2k
814a2a5f62 docs: fix response.vary jsdoc field param (#1767) 2023-10-31 21:08:41 +08:00
Gxkl
e98b8d1918 fix: can not get currentContext in error handler (#1758) 2023-04-12 17:47:09 +08:00
sjfkai
14dec599b4 fix: typo in comment (#1730) 2022-12-28 09:44:46 +08:00
mihailik
edc35ac722 docs: Provide more typings for application's context and request/response (#1726)
A bit more detailed types to help users of the library
2022-12-07 22:41:33 +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
d7894c88a5 refactor: use asyncLocalStorage.run (#1718) 2022-12-06 11:33:47 +08:00
fengmk2
fe76c4a284 refactor: required Node.js >= 12.17.0 2022-12-06 10:26:40 +08:00
dead-horse
c90317dac5 fix: improve compatibility 2022-12-06 10:26:40 +08:00
dead-horse
cdb7a3c9f4 feat: support asyncLocalStorage 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
jongleberry
65f9c939e1 context.response.get: fix test and lint 2021-08-17 22:19:39 -07:00