0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-24 22:05:56 -05:00
logto/.changeset/rare-readers-cry.md
simeng-li e7accfdab9
fix(core): prevent i18n context contamination by using request-scoped instance (#7028)
* fix(core): prevent i18n context contamination by using request-scoped instances

prevent i18n context contamination by using request-scoped instance

* refactor(core): remove RequestError body getter

remove RequestError body getter

* refactor(core): refactor some unit test context creations

refactor some unit test context creations

* refactor(core): override RequestError message with custom comments

override RequestError message with custom comments

* chore: update comments

update comments

* chore: comment update

Co-authored-by: Gao Sun <gao@silverhand.io>

---------

Co-authored-by: Gao Sun <gao@silverhand.io>
2025-02-14 07:09:22 +00:00

947 B

@logto/core
patch

prevent i18n context contamination by using request-scoped instances

This bug fix resolves a concurrency issue in i18n handling by moving from a global i18next instance to request-scoped instances.

Problem

When handling concurrent requests:

  • The shared global i18next instance's language was being modified via changeLanguage() calls.
  • This could lead to race conditions where requests might receive translations in unexpected languages.
  • Particularly problematic in multi-tenant environments with different language requirements.

Solution

  • Updated koaI18next middleware to create a cloned i18next instance for each request.
  • Attach the request-scoped instance to Koa context (ctx.i18n) All subsequent middleware and handlers should now use ctx.i18n instead of the global i18next instance.
  • Maintains the global instance for initialization while preventing cross-request contamination