@lenne.tech/nest-server 12.14.1 → 12.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/rules/better-auth.md +6 -3
- package/.claude/rules/configurable-features.md +1 -0
- package/.claude/rules/persistence.md +23 -0
- package/.claude/rules/testing.md +4 -4
- package/FRAMEWORK-API.md +1 -1
- package/dist/core/common/persistence/sql/mysql/mysql-executor.js +6 -1
- package/dist/core/common/persistence/sql/mysql/mysql-executor.js.map +1 -1
- package/dist/core/common/persistence/sql/mysql/mysql-transport.d.ts +9 -0
- package/dist/core/common/persistence/sql/mysql/mysql-transport.js +42 -0
- package/dist/core/common/persistence/sql/mysql/mysql-transport.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/docs/choosing-a-database.md +8 -0
- package/migration-guides/12.14.x-to-12.15.x.md +102 -0
- package/package.json +3 -3
- package/src/core/common/persistence/sql/mysql/mysql-executor.ts +8 -1
- package/src/core/common/persistence/sql/mysql/mysql-transport.ts +91 -0
- package/src/index.ts +1 -0
|
@@ -644,9 +644,12 @@ statements run in the session the framework set up (strict mode, UTC). On MongoD
|
|
|
644
644
|
`sql-escaper` 1.5.1 on, an object turns into `key = value` pairs only after a bare `SET ?`, which Kysely never writes
|
|
645
645
|
(it writes `col = ?`); before that, `{"name": {"roles": "[\"admin\"]"}}` assigned `roles` — a signed-in user making
|
|
646
646
|
themselves an administrator. The peer range (`>= 3.24.6`; `>= 3.25.0` since 12.13.0, for GHSA-f763-mv98-7rv9)
|
|
647
|
-
guarantees the fixed escaper; never lower it.
|
|
648
|
-
|
|
649
|
-
(
|
|
647
|
+
guarantees the fixed escaper; never lower it. Since 12.15.0 the floor is `>= 3.26.0`: 3.25 and older carry
|
|
648
|
+
GHSA-jxvc-9hcf-fw42 (critical: SQL injection through `query()` on non-UTF-8 connection charsets — Kysely's path),
|
|
649
|
+
GHSA-mxg9-wm8p-75g7 (high: forged packets before the TLS handshake ends) and GHSA-cc6q-ch5m-cffx (the server's RSA key
|
|
650
|
+
fetched from whoever answers). 3.26 fetches that key over a connection without TLS only when allowed, which
|
|
651
|
+
`mysqlKeyRetrievalOption()` decides for every pool the framework opens — Better-Auth's included
|
|
652
|
+
(`.claude/rules/persistence.md` → "Connections to MySQL without TLS").
|
|
650
653
|
|
|
651
654
|
**Sign-up holds a pool connection while it hashes (accepted).** Better-Auth runs its Kysely adapter with transactions
|
|
652
655
|
on a `pg` pool, and `/sign-up/email` hashes the password inside its transaction — on the framework's application pool
|
|
@@ -335,6 +335,7 @@ This pattern is currently applied to:
|
|
|
335
335
|
| Config Endpoint | `configEndpoint` | Explicit Boolean with DERIVED default | **Unset → a project's `GET /config` answers only in `local` / `ci` / `e2e` (`isLocalEnv()`), 404 everywhere else (12.5.0+)**; `true` answers everywhere, `false` nowhere; a non-boolean value counts as not set (`NSC__CONFIG_ENDPOINT=true`). The route lives in project code (the starter's `ServerController`) and returns `configEndpointResponse()`, which throws `NotFoundException` when closed (404, as if the route did not exist; the route's `@Roles(ADMIN)` still answers 401 first) and otherwise the REDACTED configuration (`ConfigService.getRedactedConfig()`). Before 12.5.0 the starter's endpoint returned the database URI, auth secrets and mail password to every administrator, and projects created before the starter redacted kept doing so. Redaction is the one framework masker `redactSecrets()` (`common/helpers/redact-secrets.helper.ts`, moved from the Hub where it remains as `maskConfigDeep`): key patterns (`secret`/`password`/`token`/`credential` anywhere in the name, names ending in `pass` or `key`, `encryption`, `dsn`, `salt`, … — a superset of the pattern the starter used before; `pfx` / `pkcs12` since 12.10.1), every string or `Buffer` holding a PEM private key whatever its key is called (12.10.1 — a certificate login keeps certificate and key in one PEM under `certificate`, which reached `GET /config` in clear text before; a certificate alone stays readable), the password of a connection URI and secret-named URI query parameters, scheme + host + port only for an address under a key ending in `url`/`uri`/`endpoint`/`webhook` (a webhook carries its secret in the path), nested values; below a secret-named key EVERYTHING is masked except booleans; plus `FRAMEWORK_SECRET_FIELDS` and `security.secretFields`. The Hub config panel and the `ConfigService` `warn: true` debug output use the same view. Implementation: `common/helpers/config-endpoint.helper.ts` |
|
|
336
336
|
| Secret Fields Removal | `security.secretFields` | Array | `['password', 'verificationToken', ...]`. A project list is a UNION with the defaults (it can add, never remove). `CheckSecurityInterceptor` strips each field under its SQL column name too since 12.3.1 (`passwordResetToken` and `password_reset_token`): a row read through `store.native()` / `store.raw()` carries snake_case columns, and a route returning it unchanged used to hand every secret but `password` to the client. Pinned by `tests/unit/check-security-secret-columns.spec.ts` (mutation `secret-columns-not-stripped`) |
|
|
337
337
|
| Data Sources | `database` | Explicit Value — absent = today's `mongoose` config | **Absent → the `mongoose` configuration is the only data source, exactly as before; nothing SQL is loaded or installed.** A URL string (`'postgres://…'`) sets the default source (driver from the scheme, `sqlEngine` defaults to `typeorm`; `kysely` and `drizzle` are the alternatives — optional peers, each with `pg`); an object adds `ownerUrl` (default source), `sources` (name → URL or `{ url, ownerUrl, sqlEngine }`) and per-model exceptions (`models`); `false` means no database. Precedence for a model: `database.models` > the `dataSource` of a `CorePersistenceModule.forFeature()` definition > `@PersistedModel({ dataSource })` (read from the definition's `model:` class, otherwise from the decorated class named like the model; two such classes naming different sources refuse to guess) > default. When `database` sets a default and the project ALSO configures `mongoose` explicitly, that MongoDB becomes the source `mongoose` — only the project's own `mongoose` counts, because `CoreModule.forRoot()` always merges a fallback URI. **Since phase 1 (DEV-3829) PostgreSQL sources are wired**: only models registered with `CorePersistenceModule.forFeature()` are routed — **since phase 2 (DEV-3830) that includes the core's own models**: the user model (the reference `UserModule`), tenant memberships and API tokens, whose services switch to the routed store (a service that only received `@InjectModel()` follows its model's store; the Mongoose model of a model routed to SQL refuses every data access with a named error, so a direct `mainDbModel` call cannot split a model's data). **Since phase 3 (DEV-3831) Better-Auth follows the user model**: with the user model (table `users`) on a SQL source, Better-Auth runs its built-in Kysely adapter on that source's application pool — ONE `users` row per user shared with the user model (Better-Auth's own columns `name`, `email_verified`, `image` beside the framework's; its required ones are added nullable, so a row the user model writes alone stays valid), snake_case tables (`session`, `account`, `verification`, `jwks`, `two_factor`, `passkey`), ObjectId-hex ids. Its schema is applied as the OWNER at boot, under the same schema lock and grants as the framework's tables; without `ownerUrl` the application role only verifies and the boot stops while Better-Auth's migrations are pending. The framework's own reads and writes of Better-Auth's data follow it (session lookup by token, token service, JWKS, passkey challenge mappings — as Better-Auth verification values —, the e-mail-verified hook, user mapper, system setup, migration status — counted in SQL —, the MCP OAuth subject's roles); the MongoDB boot steps (indices, account-issuer backfill) are skipped there. Nothing is copied from MongoDB: a project that moves its users brings them over itself. **Since phase 4 (DEV-3832) the remaining core persistence follows too**: the AI module's eleven models and the three MCP OAuth stores (clients, codes, refresh tokens) are registered through `CorePersistenceModule.forFeature()` and run on their routed store (one code path; an upsert is update-then-insert with a retry on a duplicate, `sum()` replaces the budget aggregation, `find(…, { exclude })` the `-field` projection); the S3 and filesystem file metadata are two framework models (`CoreS3File`, `CoreFilesystemFile`, tables `s3_files` / `filesystem_files`) read and written through `fileMetadataCollection()` by the file service, the TUS hand-off and the Hub — GridFS stays MongoDB-only. A collection name with a hyphen becomes a table with an underscore. A TTL (`expires`, `index: { expireAfterSeconds }`) is a plain index on SQL; an **expiry sweep** (`scheduleExpirySweep()`, every 15 min, one replica per interval through a lease in the default SQL source's `lt_locks`, fail-open) deletes the expired rows of every routed TTL model, and — with Better-Auth on SQL — expired sessions and verification values. Nothing relies on it for correctness: every reader checks the expiry (an MCP authorization code older than ten minutes is refused on read on both databases). MongoDB keeps its TTL indexes and gets no sweep. The framework's leases (system-setup claim, cron, migrations) live in the default source: on MongoDB in the 12.0.0 documents (a rolling deploy with older replicas shares them), on SQL in `lt_locks`, namespaced, swept an hour after expiry. With `healthCheck.configs.database` every SQL source answers as `<key>:<source>`; `createMigrationStore(<owner URL>)` keeps the migration state in `lt_migrations` with an advisory run lock, on the first SQL engine installed (the CLI cannot read `database.sqlEngine`), and the Hub refuses to run migrations while that table is empty and the MongoDB collection is not (a `migrate.js` still writing MongoDB); the Hub's Persistence panel shows the routing. a SQL model's table is migrated as the OWNER (`ownerUrl`) when its store is created — without `ownerUrl` the application role only verifies and the boot stops while changes are pending; ONE owner connection per source, released once the application is bootstrapped — and the boot refuses an application role that is superuser, has `BYPASSRLS`, owns (or inherits the owner of) a framework table or may `TRUNCATE` it. Two roles in every environment (plan §3.9). Changes the framework never applies on its own (type change, new unique index, rename collision) stop the boot with the suggested statements; `migrate create <name> --sql` + `runSqlMigration()` apply them after review. **Since phase 5 (DEV-3833, 12.1.0) MongoDB is optional**: `mongoose`, `@nestjs/mongoose` and `mongodb` are optional peers, loaded through `common/persistence/mongo/mongo-packages.ts`; `CoreModule` connects MongoDB only when a source uses it (`usesMongoDb()` — `mongoose` configured explicitly, `database` naming MongoDB, or `database` absent), otherwise `@InjectConnection()` receives `null` and a model token without a connection is a stand-in that refuses data access. A configured MongoDB feature without the packages fails the boot with `MongoPackagesMissingError`. `database: false` runs a service without any database: a registered model's store refuses with the reason, Better-Auth is refused at boot. Proven by `pnpm run check:without-mongodb` (dist, packages hidden) and `check:without-mongodb:package` (the tarball installed without them, publish path). **Since phase 6 (DEV-3848) MySQL 8.4 and MariaDB 11.8 sources are wired** (`mysql://`, `mariadb://` — the scheme must name the server the URL reaches): `mysql2` is an optional peer beside the engine, all three engines run on one pool the framework creates (strict session with backslash escapes, UTC), `MysqlDataStore` writes the statements, the owner grants the application account `SELECT, INSERT, UPDATE, DELETE` on the database once and the boot refuses an application account that may alter, drop, index, trigger or grant; leases, migration state (`createMigrationStore()` / `runSqlMigration()` under `GET_LOCK`), the expiry sweep, health check and Hub work there. **Neither database has row-level security**: tenant isolation is the store's, the boot warns once per source, and native / raw access on a tenant table must filter by tenant itself. **Since 12.1.1 (DEV-3904) Better-Auth runs there too**: its Kysely adapter on the source's `mysql2` pool (the promise wrapper — Better-Auth builds `MysqlDialect` from it), its migrations as the owner under `GET_LOCK`, with the database's default collation switched to `utf8mb4_bin` while it creates a table and restored (`withFrameworkDefaultCollation()`; only on such a run and with a 5 s lock wait, because `ALTER DATABASE` locks every table) — Better-Auth names no collation, and MariaDB refuses a foreign key to `users.id` across collations; the database-level grant covers its tables. 12.1.0 refused it at boot. An indexed text field is `varchar(255)` (longer: 400); a DDL run is not transactional. Still refused with a named `DataSourceConfigError`: a second MongoDB source, and an `ownerUrl` without `url` — what `NSC__DATABASE__OWNER_URL` leaves of a `database` given as a URL string, because the environment merge replaces the string with an object (write `database: { url }`, or set `NSC__DATABASE__URL` too). An update path the model does not declare is dropped on SQL as by MongoDB's strict mode (`CrudService.update()` adds `updatedBy` to every update with a current user). URLs appear in errors and logs as scheme + host only. Implementation: `common/persistence/data-source.config.ts`, `data-source.runtime.ts`, `sql/` (db-agnostic plan §3.9) |
|
|
338
|
+
| MySQL Password Transport | the query string of a `mysql://` `database` URL (`ssl`, `socketPath`, `serverPublicKey`, `allowPublicKeyRetrieval`) | Explicit Value with DERIVED default | **12.15.0.** mysql2 3.26+ fetches the server's RSA key over a connection without TLS only when allowed (GHSA-cc6q-ch5m-cffx); `caching_sha2_password` (MySQL 8.4's default) needs it for the first login after a MySQL restart, so an undecided connection fails with `PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED` after the next restart while every test passes (the server cache is warm). **URL carries one of the four parameters** → it decides, in every environment, and the framework adds nothing (mysql2 keeps an option set in the object over the URL's value, so adding one would turn a project's `false` into `true`). **URL carries none, `local` / `ci` / `e2e`** (`isLocalEnv()`; the configured `env`, else `NODE_ENV`, unset = `local`) → `allowPublicKeyRetrieval: true`. **None, any other environment, `mysql://`** → `MysqlTransportUndecidedError` before anything connects, naming the ways out: `?ssl={"rejectUnauthorized":true,"verifyIdentity":true}` (TLS, recommended; without `verifyIdentity` mysql2 accepts any certificate a trusted CA issued for any domain, and for an IP host it never checks the name), `?serverPublicKey=<PEM>`, `?allowPublicKeyRetrieval=true` (accepts that a host in the network path can read the password), `?allowPublicKeyRetrieval=false` (an account without `caching_sha2_password`). **`mariadb://`** → left alone (`mysql_native_password` by default, measured on 11.8). Applies to every pool `createMysqlExecutor()` opens: application and owner URL, Better-Auth's Kysely adapter, migration state, the migrate CLI. Pinned by `tests/unit/mysql-transport.spec.ts` and `tests/persistence-mysql-executor.e2e-spec.ts` (flushes privileges before each login; mutations `mysql-transport-undecided-deployed-accepted`, `mysql-transport-url-overridden`, `mysql-pool-key-retrieval-dropped`). Implementation: `common/persistence/sql/mysql/mysql-transport.ts` |
|
|
338
339
|
| Multi-Tenancy | `multiTenancy` | Presence Implies Enabled | **`excludeSchemas` is an OFF SWITCH for isolation, per model** — a listed schema gets no tenant filter at all; since 11.35.0 the plugin WARNS once per model when the excluded schema declares `tenantId` (i.e. was built for isolation). The framework's own docs recommended `['User', 'Session']` until then; that is withdrawn — it is only right for the global-user model. Since 11.35.0 GraphQL operations over the WEBSOCKET also run inside a `RequestContext` (`CoreModule` installs a context-aware `execute`/`subscribe` pair inside `subscriptions`, where `ApolloDriver` forwards it): the tenant comes from the handshake header validated against an active membership, else from the subscriber's memberships, and an unresolvable tenant leaves the safety net to refuse the read rather than returning everything. `headerName: 'x-tenant-id'`, `membershipModel: 'TenantMember'`, `adminBypass: true`, `excludeSchemas: []`, `roleHierarchy: { member: 1, manager: 2, owner: 3 }`, `cacheTtlMs: 30000` (0 disables, process-local). System roles (`S_EVERYONE`, `S_USER`, `S_VERIFIED`) are checked as OR alternatives before real roles; method-level system roles take precedence; membership validated for context when system role grants access + header present. Hierarchy roles use level comparison, normal roles use exact match. Use `DefaultHR` or `createHierarchyRoles()` for type-safe role constants. Bypass: `RequestContext.runWithBypassTenantGuard()`. Cache invalidation: `invalidateUser(userId)` / `invalidateAll()` are **instance** methods on the singleton `CoreTenantGuard` — inject it and call `this.tenantGuard?.invalidateUser(userId)`, never `CoreTenantGuard.invalidateUser(...)` (there is no static). With `redis` configured, both additionally BROADCAST the invalidation to every replica (`<keyPrefix>:tenant-cache:invalidate` pub/sub); without Redis they clear the local process only, so other replicas stay stale until `cacheTtlMs`. A received broadcast clears locally without re-publishing. **`isTenantActive` (11.42.0)**: optional hook `(tenantId, { connection, store }) => boolean \| Promise<boolean>`, absent = every tenant active (no change). `store(modelName)` (12.x, db-agnostic) is the data store of a model registered with `CorePersistenceModule.forFeature()`, wherever `database` routes it, and THROWS for any other model — an `undefined` would read as "active" in a hook written with `?.` and open every deactivated tenant. Asked AFTER the membership check on every path that establishes a tenant: 403 on header paths and for tenant API tokens, no enrichment on `S_EVERYONE`, dropped from the header-less tenant list, no tenant for a NEW WebSocket subscription, and since 11.42.3 an OPEN one is closed with 4403 on `invalidateTenant()` (or at its next event once `graphQl.subscriptionRevalidationMs` has passed — see the GraphQL Subscription Re-check row); an admin under `adminBypass` is exempt (someone must be able to switch it back on). Only `false` deactivates. Cached for `cacheTtlMs`; `invalidateTenant(tenantId)` clears and broadcasts (`{ scope: 'tenant' }`) — since 12.3.0 together with the tenant's cached memberships and every cached tenant list holding it, so memberships removed without `invalidateUser()` (a deleted tenant) stop counting at once rather than after `cacheTtlMs` (a tenant switched off through `isTenantActive` was already refused at once, its answer being cleared). **Removing a tenant (12.3.0)**: `CoreTenantService.purgeTenantData(tenantId, { dryRun?, exclude? })` first ends every way in — the memberships (`deleteAllMembers()`) and the tenant's API tokens, which need no member — then deletes, in batches of 1000 ids, every registered model with a `tenantId` path (MongoDB and SQL), the core references without one (the AI settings with `scope: 'tenant'`) and the AI connections — one only this tenant could use is deleted, from a shared one the tenant is removed (an empty `tenantIds` means every tenant). `excludeSchemas` and `exclude` are left out, so are users and files; the protected `purgeTenantRecords()` is where a project adds its own references. A function, so `config.env.ts` only — not reachable through `NSC__*`. **`adminBypass: false` (11.42.0)** additionally withholds two things that went around it: `CoreUserService.update()` refuses changing another account's e-mail or password (`assertCredentialChangeAllowed()`, administrator targets included — promote-then-change — system work without a current user exempt), and the AI tool registry grants no ADMIN bypass, and (12.13.0) the `file.access: 'tenant'` preset reads a tenant's files for an administrator only through an active membership. **`selectionCookie` (12.13.0)**: Boolean Shorthand, absent = off. `true` / `{}` / `{ name }`: the tenant guard writes `lt-tenant-id` (`__Host-` prefixed where cookies are `Secure`, the auth-cookie rule; HttpOnly, SameSite=Lax, Path=/, no Domain, session cookie) whenever a request's tenant header passed its check, never for API tokens. Read only on routes with `@ResolveTenantSelection()` (the file controller and resolver), after access was granted and when no tenant was set: header (foreign → 403, on a public route no tenant) → cookie (no active membership → ignored and cleared) → the only active membership; several and no selection → no tenant. Not `lt-tenant` (nuxt-extensions' app cookie, one host behind `apiProxy`). Implementation: `core-tenant-selection.helper.ts`, `CoreTenantGuard.completeTenantSelection()` |
|
|
339
340
|
| GraphQL Subscription Re-check | `graphQl.subscriptionRevalidationMs` | Numeric — `0` = STRICTEST, `false` = off, invalid → default (a fifth shape: Family C's "invalid never means unbounded", but `0` asks for MORE checking, not less) | **30000 since 11.42.3.** Before, a WebSocket was authorized once, at the handshake, and every event and operation on it ran on that snapshot until the client reconnected. Every connection a `CoreModule` `onConnect` accepts is now registered (`registerWsConnection()`) and re-checked — at once when an invalidation names it (`CoreTenantGuard.invalidateUser()` / `invalidateTenant()` / `invalidateAll()`, `CoreUserService.setRoles()` and role/verification `update()`s, the legacy password reset, and Better-Auth deleting a session through `wsSessionRevocationPlugin()`), and otherwise before the next event or operation once the last check is older than this value. The check re-runs the handshake's own authentication (session store, Better-Auth JWT signature/expiry, or for legacy tokens `CoreAuthService.verifyJwt()` — signature/expiry, verified on the WebSocket since 11.42.3 — plus the device binding) and the tenant resolution; any difference in user id, roles, verification state or tenant scope closes the socket with **4403**, which the graphql-ws client retries — the user continues with current rights or is refused at the handshake. `0` re-checks on every event and operation (one session lookup each); `false` switches only the TIME-based check off, invalidations still apply. Process-local registry: an invalidation reaches other replicas only where a Redis broadcast carries it — the tenant guard's (memberships, tenants) and, since 12.1.1, the Better-Auth user mapper's (`invalidateUserCache()`: roles and verification of IAM users); everything else is bounded by the interval. A project that replaces `onConnect` through `graphQl.driver.subscriptions` must call `registerWsConnection()` itself to keep this. An HTTP stream (SSE) of a project's own registers with `registerHttpStream()` (12.11.0): re-checked in place like a WebSocket when its Better-Auth credential can be run again, ended on every re-check otherwise. Implementation: `common/helpers/graphql-ws-connection.helper.ts` |
|
|
340
341
|
| API Tokens | `apiTokens` | Boolean Shorthand + Presence Implies Enabled — absent = off | `prefix: 'ltt'`, `scopes: []` (vocabulary; empty = no token creatable, boot warning), `manageRole`: highest hierarchy role, `maxAssertionLifetimeSeconds: 900` (invalid → default, never unbounded — Family C), `rateLimit: { max: 600, windowSeconds: 60 }` per token (**on by default**, `false` disables; Redis-shared when configured), `userTokens: true`, `tenantTokens: true` (effective only with `multiTenancy`), `encryptionKey` → `SECRETS_ENCRYPTION_KEY` → dev default (boot FAILS in production/staging). Top-level, NOT under `multiTenancy`: user tokens must work without it. **Deny by default**: every guard refuses a token on a route without `@ApiTokenScopes()`, public routes included, via ONE shared function (`enforceApiTokenRoute`) called BEFORE each guard's public-route shortcut. USER tokens act as their user with global roles REMOVED (no admin bypass); TENANT tokens act with the lowest hierarchy role in their own tenant, and a route guarded ONLY by `S_SELF` / `S_CREATOR` refuses them (a tenant token is nobody's self — skipping those roles would grant for any target). A tenant token depends on no member, so it outlives an off-boarded or deleted tenant until the project calls `deleteAllForTenant()` or `CoreTenantService.purgeTenantData()`. The boot refuses a hierarchy in which that lowest role reaches `manageRole`. A prefixed credential that fails answers 401 on every route (not anonymous); `CoreBetterAuthMiddleware` skips prefixed credentials entirely, cookie fallback included. A password reset that ends the user's sessions ends their USER tokens too (legacy reset always; IAM reset while `betterAuth.emailAndPassword.revokeSessionsOnPasswordReset` is on), wired through `core-api-token.registry.ts` so neither reset path imports the optional module. Implementation: `src/core/modules/api-token/` |
|
|
@@ -82,6 +82,29 @@ On MySQL / MariaDB a text field that is part of an index is `varchar(255)` (a lo
|
|
|
82
82
|
prefix when it is a lookup index and is refused when unique. DDL commits on its own there: a run is serialized by
|
|
83
83
|
`GET_LOCK`, not a transaction, and a failed change leaves the statements before it applied.
|
|
84
84
|
|
|
85
|
+
## Connections to MySQL without TLS (12.15.0)
|
|
86
|
+
|
|
87
|
+
MySQL 8.4 signs accounts in with `caching_sha2_password`. While the server caches the account a scrambled proof
|
|
88
|
+
suffices; the first login after a restart (or `FLUSH PRIVILEGES`, a password change) needs the password, which a client
|
|
89
|
+
without TLS encrypts with the server's RSA key. mysql2 3.26+ fetches that key only when allowed
|
|
90
|
+
(GHSA-cc6q-ch5m-cffx) and otherwise fails with `PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED` — after the next MySQL restart, not
|
|
91
|
+
when it is tested. Every pool the framework opens goes through `createMysqlExecutor()`, which asks
|
|
92
|
+
`mysqlKeyRetrievalOption()` (`sql/mysql/mysql-transport.ts`):
|
|
93
|
+
|
|
94
|
+
| The URL carries … | Result |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `ssl`, `socketPath`, `serverPublicKey` or `allowPublicKeyRetrieval` | the URL decides, in every environment |
|
|
97
|
+
| nothing, `local` / `ci` / `e2e` | the framework adds `allowPublicKeyRetrieval: true` (nobody sits in that network path) |
|
|
98
|
+
| nothing, any other environment, `mysql://` | boot refused with `MysqlTransportUndecidedError` naming the ways out |
|
|
99
|
+
| nothing, any other environment, `mariadb://` | left alone (`mysql_native_password` by default, no RSA key) |
|
|
100
|
+
|
|
101
|
+
| Do | Never |
|
|
102
|
+
|---|---|
|
|
103
|
+
| Open MySQL connections through `createSqlExecutor()` / the data store | A pool of your own without the same decision — it boots and fails after the next MySQL restart |
|
|
104
|
+
| Let the URL decide (`?ssl={"rejectUnauthorized":true,"verifyIdentity":true}`, `?allowPublicKeyRetrieval=false` for an account without RSA) | Set `allowPublicKeyRetrieval` in the options object next to a URL: mysql2 keeps the object's value over the URL's, so the project's `false` would turn into `true` |
|
|
105
|
+
| Recommend TLS with `verifyIdentity` | `{"rejectUnauthorized":true}` alone: mysql2 checks the host name only with `verifyIdentity`, so any certificate a trusted CA issued for any domain passes, and the password goes to whoever presents one. For an IP host it skips the name check altogether: only a private `ca` protects that connection |
|
|
106
|
+
| Open direct test connections to MySQL with `allowPublicKeyRetrieval: true` (`tests/helpers/mysql-test-db.ts`) | Rely on a warm server cache in a test — the e2e case flushes privileges first (mutation `mysql-pool-key-retrieval-dropped`) |
|
|
107
|
+
|
|
85
108
|
## Updates on MySQL / MariaDB
|
|
86
109
|
|
|
87
110
|
Two operators on one path, or on a path and a path inside it, are refused (`Updating the path … would create a
|
package/.claude/rules/testing.md
CHANGED
|
@@ -418,7 +418,7 @@ pnpm run check:mutations -- --id=<id> # one mutation
|
|
|
418
418
|
pnpm run check:mutations -- --list # the registry, without running anything
|
|
419
419
|
pnpm run check:mutations -- --allow-dirty # when the fix and its evidence share a working tree
|
|
420
420
|
pnpm run check:mutations -- --jobs=4 # N mutations at a time (default: 2, or 4 on >=12 cores)
|
|
421
|
-
pnpm run check:mutations -- --no-infra # only the
|
|
421
|
+
pnpm run check:mutations -- --no-infra # only the 556 that need no MongoDB
|
|
422
422
|
pnpm run check:mutations -- --since=<ref> # only mutations touching files changed since <ref>
|
|
423
423
|
pnpm run check:mutations -- --shard=2/4 # this job's quarter of the selection (CI splits the full run)
|
|
424
424
|
```
|
|
@@ -438,7 +438,7 @@ when the registry, a vitest config or a setup file changed, since those can move
|
|
|
438
438
|
commit, and in CI alongside the publish without blocking it. The price of caching is a cache that
|
|
439
439
|
has to model each spec's full dependency closure correctly, and getting that wrong produces a stale
|
|
440
440
|
PASS for a test that has since gone vacuous — exactly what the gate is there to prevent. Bad trade
|
|
441
|
-
at
|
|
441
|
+
at 816 mutations.
|
|
442
442
|
|
|
443
443
|
**Decided 2026-10-03 (repo owner): keep the full run.** Measured at 128 mutations, the CI job for
|
|
444
444
|
11.41.6 took **14 minutes**. The trigger to revisit is that wall time, not the mutation count —
|
|
@@ -509,9 +509,9 @@ exactly the environment where the answer matters.
|
|
|
509
509
|
|
|
510
510
|
### The cost is vitest's cold start, not the tests
|
|
511
511
|
|
|
512
|
-
Worth knowing before optimising the wrong thing: the specs behind all
|
|
512
|
+
Worth knowing before optimising the wrong thing: the specs behind all 260 e2e mutations add up to
|
|
513
513
|
**~40 seconds**. The step takes ~740s. The remaining ~700s is paying vitest's startup — process
|
|
514
|
-
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation,
|
|
514
|
+
spawn, transform, module graph, mongod connect, DB create and drop — once per mutation, 816 times.
|
|
515
515
|
That work is largely single-threaded I/O and barely scales with cores: the full registry measures
|
|
516
516
|
**744s on a 12-core laptop and 777s on a 4-vCPU CI runner**.
|
|
517
517
|
|
package/FRAMEWORK-API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @lenne.tech/nest-server — Framework API Reference
|
|
2
2
|
|
|
3
|
-
> Auto-generated from source code as of 2026-12-
|
|
3
|
+
> Auto-generated from source code as of 2026-12-06 (v12.15.0)
|
|
4
4
|
> File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
|
|
5
5
|
|
|
6
6
|
## CoreModule.forRoot()
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Logger } from '@nestjs/common';
|
|
2
2
|
import { MYSQL_SESSION_SQL, mysqlConnectionOptions, mysqlResult, mysqlStatementParts, toMysqlStatement, } from './mysql-session.js';
|
|
3
|
+
import { mysqlKeyRetrievalOption } from './mysql-transport.js';
|
|
3
4
|
const logger = new Logger('SqlPool');
|
|
4
5
|
export async function createMysqlExecutor(options) {
|
|
6
|
+
mysqlKeyRetrievalOption(options.url, options.variant);
|
|
5
7
|
switch (options.engine) {
|
|
6
8
|
case 'drizzle':
|
|
7
9
|
return createDrizzleExecutor(options);
|
|
@@ -27,7 +29,10 @@ async function loadMysql2() {
|
|
|
27
29
|
}
|
|
28
30
|
function createPool(mysql2, options) {
|
|
29
31
|
const url = options.url.replace(/^mariadb:/i, 'mysql:');
|
|
30
|
-
const pool = mysql2.createPool(
|
|
32
|
+
const pool = mysql2.createPool({
|
|
33
|
+
...mysqlConnectionOptions(url, options.maxConnections ?? 10),
|
|
34
|
+
...mysqlKeyRetrievalOption(options.url, options.variant),
|
|
35
|
+
});
|
|
31
36
|
pool.on('connection', (connection) => {
|
|
32
37
|
connection.query(MYSQL_SESSION_SQL, (error) => {
|
|
33
38
|
if (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-executor.js","sourceRoot":"","sources":["../../../../../../src/core/common/persistence/sql/mysql/mysql-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EAEnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"mysql-executor.js","sourceRoot":"","sources":["../../../../../../src/core/common/persistence/sql/mysql/mysql-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EAEnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AA4B/D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AAErC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA6B;IAErE,uBAAuB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,QAAQ;YACX,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACvC,KAAK,SAAS;YACZ,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,OAAO,CAA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AAM,EAAE,SAAS;QACjB,MAAM,EAAE,GAAM,EAAE,CAAC,EAAO;QACxB,GAAG,EAAE,CAAI,SAAuB,EAAE,MAAsB,EAAE,EAAE,CAAC,SAAS,CAAI,WAAW,EAAE,SAAS,CAAC;QACjG,WAAW,EAAE,CAAI,EAAsC,EAAc,EAAE,CACrE,EAAE;aACC,WAAW,CAAC,CAAC,EAAO,EAAE,EAAE,CACvB,EAAE,CAAC;YACD,MAAM,EAAE,GAAM,EAAE,CAAC,EAAO;YACxB,GAAG,EAAE,CAAI,SAAuB,EAAE,EAAE,CAClC,SAAS,CAAC,KAAK,IAAI,EAAE;gBACnB,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;gBACpD,OAAO,WAAW,CAAI,MAAM,CAAC,CAAC;YAChC,CAAC,CAAC;SACL,CAAC,CACH;aACA,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC;QACN,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MysqlVariant } from './mysql-session.js';
|
|
2
|
+
export declare const MYSQL_TRANSPORT_PARAMETERS: readonly ["allowPublicKeyRetrieval", "serverPublicKey", "socketPath", "ssl"];
|
|
3
|
+
export declare class MysqlTransportUndecidedError extends Error {
|
|
4
|
+
readonly name = "MysqlTransportUndecidedError";
|
|
5
|
+
}
|
|
6
|
+
export declare function currentMysqlEnvironment(): string;
|
|
7
|
+
export declare function mysqlKeyRetrievalOption(url: string, variant: MysqlVariant, env?: string | undefined): {
|
|
8
|
+
allowPublicKeyRetrieval?: true;
|
|
9
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isLocalEnv } from '../../../helpers/cookies.helper.js';
|
|
2
|
+
import { ConfigService } from '../../../services/config.service.js';
|
|
3
|
+
import { redactUrl } from '../../data-source.config.js';
|
|
4
|
+
export const MYSQL_TRANSPORT_PARAMETERS = ['allowPublicKeyRetrieval', 'serverPublicKey', 'socketPath', 'ssl'];
|
|
5
|
+
export class MysqlTransportUndecidedError extends Error {
|
|
6
|
+
name = 'MysqlTransportUndecidedError';
|
|
7
|
+
}
|
|
8
|
+
export function currentMysqlEnvironment() {
|
|
9
|
+
return ConfigService.configFastButReadOnly?.env || process.env.NODE_ENV || 'local';
|
|
10
|
+
}
|
|
11
|
+
export function mysqlKeyRetrievalOption(url, variant, env = currentMysqlEnvironment()) {
|
|
12
|
+
const stated = statedTransportParameters(url);
|
|
13
|
+
if (stated === null || stated.length > 0) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
if (isLocalEnv(env)) {
|
|
17
|
+
return { allowPublicKeyRetrieval: true };
|
|
18
|
+
}
|
|
19
|
+
if (variant === 'mysql') {
|
|
20
|
+
throw new MysqlTransportUndecidedError(`The MySQL source ${redactUrl(url)} does not say how the password travels, and the environment ` +
|
|
21
|
+
`"${env ?? ''}" is not local. mysql2 fetches the server's RSA key over a connection without TLS only when ` +
|
|
22
|
+
'allowed, so the first login after the next MySQL restart would fail with PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED. ' +
|
|
23
|
+
'Add one parameter to the URL: ?ssl={"rejectUnauthorized":true,"verifyIdentity":true} (TLS, recommended: verifyIdentity makes mysql2 ' +
|
|
24
|
+
'check that the certificate names the URL host, which must be a DNS name; with your CA add "ca":"<PEM>"), ' +
|
|
25
|
+
"?serverPublicKey=<PEM of the server's RSA public key>, " +
|
|
26
|
+
'?allowPublicKeyRetrieval=true (accepts that a host in the network path can read the password), or ' +
|
|
27
|
+
'?allowPublicKeyRetrieval=false when the account does not use caching_sha2_password. ' +
|
|
28
|
+
'See migration-guides/12.14.x-to-12.15.x.md.');
|
|
29
|
+
}
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
function statedTransportParameters(url) {
|
|
33
|
+
let parameters;
|
|
34
|
+
try {
|
|
35
|
+
parameters = new URL(url).searchParams;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return MYSQL_TRANSPORT_PARAMETERS.filter((name) => parameters.has(name));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mysql-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-transport.js","sourceRoot":"","sources":["../../../../../../src/core/common/persistence/sql/mysql/mysql-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AA0BxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,yBAAyB,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,CAAU,CAAC;AAGvH,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACnC,IAAI,GAAG,8BAA8B,CAAC;CACzD;AAMD,MAAM,UAAU,uBAAuB;IACrC,OAAO,aAAa,CAAC,qBAAqB,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC;AACrF,CAAC;AAWD,MAAM,UAAU,uBAAuB,CACrC,GAAW,EACX,OAAqB,EACrB,MAA0B,uBAAuB,EAAE;IAEnD,MAAM,MAAM,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAEzC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,4BAA4B,CACpC,oBAAoB,SAAS,CAAC,GAAG,CAAC,8DAA8D;YAC9F,IAAI,GAAG,IAAI,EAAE,8FAA8F;YAC3G,6GAA6G;YAC7G,sIAAsI;YACtI,2GAA2G;YAC3G,yDAAyD;YACzD,oGAAoG;YACpG,sFAAsF;YACtF,6CAA6C,CAChD,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAGD,SAAS,yBAAyB,CAAC,GAAW;IAC5C,IAAI,UAA2B,CAAC;IAChC,IAAI,CAAC;QACH,UAAU,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export * from './core/common/persistence/sync-model.js';
|
|
|
106
106
|
export * from './core/common/persistence/unsupported-capability.error.js';
|
|
107
107
|
export * from './core/common/persistence/sql/mysql/mysql-data-store.js';
|
|
108
108
|
export * from './core/common/persistence/sql/mysql/mysql-lock-store.js';
|
|
109
|
+
export * from './core/common/persistence/sql/mysql/mysql-transport.js';
|
|
109
110
|
export * from './core/common/persistence/sql/postgres/postgres-lock-store.js';
|
|
110
111
|
export * from './core/common/persistence/sql/sql-data-store.js';
|
|
111
112
|
export * from './core/common/persistence/sql/sql-errors.js';
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,7 @@ export * from './core/common/persistence/sync-model.js';
|
|
|
105
105
|
export * from './core/common/persistence/unsupported-capability.error.js';
|
|
106
106
|
export * from './core/common/persistence/sql/mysql/mysql-data-store.js';
|
|
107
107
|
export * from './core/common/persistence/sql/mysql/mysql-lock-store.js';
|
|
108
|
+
export * from './core/common/persistence/sql/mysql/mysql-transport.js';
|
|
108
109
|
export * from './core/common/persistence/sql/postgres/postgres-lock-store.js';
|
|
109
110
|
export * from './core/common/persistence/sql/sql-data-store.js';
|
|
110
111
|
export * from './core/common/persistence/sql/sql-errors.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,kBAAkB,CAAC;AAKjC,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mDAAmD,CAAC;AAClE,cAAc,oDAAoD,CAAC;AACnE,cAAc,oDAAoD,CAAC;AACnE,cAAc,wDAAwD,CAAC;AACvE,cAAc,+DAA+D,CAAC;AAC9E,cAAc,oDAAoD,CAAC;AACnE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,iDAAiD,CAAC;AAChE,cAAc,sDAAsD,CAAC;AACrE,cAAc,kDAAkD,CAAC;AACjE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,qDAAqD,CAAC;AACpE,cAAc,iDAAiD,CAAC;AAChE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0CAA0C,CAAC;AACzD,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qDAAqD,CAAC;AACpE,cAAc,oDAAoD,CAAC;AACnE,cAAc,qDAAqD,CAAC;AACpE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,qDAAqD,CAAC;AACpE,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAClE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,oCAAoC,CAAC;AACnD,cAAc,2CAA2C,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ACxD,cAAc,iDAAiD,CAAC;AAChE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,wDAAwD,CAAC;AACvE,cAAc,oDAAoD,CAAC;AAMnE,cAAc,mDAAmD,CAAC;AAClE,cAAc,sDAAsD,CAAC;AACrE,cAAc,uDAAuD,CAAC;AACtE,cAAc,kDAAkD,CAAC;AACjE,cAAc,mDAAmD,CAAC;AAClE,cAAc,mDAAmD,CAAC;AAClE,cAAc,qDAAqD,CAAC;AAMpE,cAAc,6BAA6B,CAAC;AAM5C,cAAc,mDAAmD,CAAC;AAClE,cAAc,iDAAiD,CAAC;AAChE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,mDAAmD,CAAC;AAClE,cAAc,kDAAkD,CAAC;AACjE,cAAc,uDAAuD,CAAC;AACtE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,8CAA8C,CAAC;AAM7D,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,sDAAsD,CAAC;AACrE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,uEAAuE,CAAC;AAMtF,cAAc,uBAAuB,CAAC"}
|
|
@@ -111,3 +111,11 @@ MySQL and MariaDB run with **two accounts** too: the owner creates and migrates
|
|
|
111
111
|
account `SELECT, INSERT, UPDATE, DELETE` on the database once; the boot refuses an application account that may alter,
|
|
112
112
|
drop, index, trigger or grant — without row-level security, the tables and their constraints are what the store's
|
|
113
113
|
policies rely on. MySQL 8.4 / MariaDB 11.8 or newer, and the URL's scheme must name the server it reaches.
|
|
114
|
+
|
|
115
|
+
On **MySQL** (not MariaDB) a deployed environment says in the URL how the password travels without TLS (12.15.0):
|
|
116
|
+
`?ssl={"rejectUnauthorized":true,"verifyIdentity":true}` (TLS, recommended; the URL host must be the DNS name on the certificate, with your CA add
|
|
117
|
+
`"ca":"<PEM>"`), `?serverPublicKey=<PEM>`,
|
|
118
|
+
or `?allowPublicKeyRetrieval=true` (accepts that a host in the network path can read the password).
|
|
119
|
+
`?allowPublicKeyRetrieval=false` is the answer for an account that does not use `caching_sha2_password`. Without one of
|
|
120
|
+
them the boot stops with `MysqlTransportUndecidedError`; in `local`, `ci` and `e2e` the framework allows the key
|
|
121
|
+
retrieval itself. mysql2 3.26 or newer is required.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Migration Guide: 12.14.x → 12.15.x
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | **MySQL only** (not MariaDB, not PostgreSQL or MongoDB): on a deployed environment a `mysql://` URL must say how the password travels without TLS, or the boot stops (§1). `mysql2` peer floor `>= 3.26.0` (§2) |
|
|
8
|
+
| **New Features** | `mysqlKeyRetrievalOption()`, `MysqlTransportUndecidedError` (§1) |
|
|
9
|
+
| **Bugfixes** | mysql2 3.26 closes four advisories of 3.25 and older, one critical (§2) |
|
|
10
|
+
| **Migration Effort** | None for projects on MongoDB, PostgreSQL or MariaDB, and none in `local` / `ci` / `e2e`. A project with MySQL on a deployed environment adds one URL parameter (§1) |
|
|
11
|
+
|
|
12
|
+
This minor contains a breaking change for MySQL projects. The version stays 12.x because the major follows NestJS.
|
|
13
|
+
|
|
14
|
+
## Quick Migration
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @lenne.tech/nest-server@12.15.0
|
|
18
|
+
pnpm add mysql2@3.26.1 # only if the project declares mysql2 (MySQL / MariaDB, or a vendor-mode project)
|
|
19
|
+
pnpm run update # nest-server-starter based projects
|
|
20
|
+
pnpm run build
|
|
21
|
+
pnpm test
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then, for MySQL on a deployed environment only: add one parameter from §1 to `NSC__DATABASE__URL` (and
|
|
25
|
+
`NSC__DATABASE__OWNER_URL`) of every deployed stage.
|
|
26
|
+
|
|
27
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual, and raise `mysql2` to 3.26.1 in the project's
|
|
28
|
+
`package.json` (vendor projects declare it themselves).
|
|
29
|
+
|
|
30
|
+
## 1. MySQL: say how the password travels without TLS
|
|
31
|
+
|
|
32
|
+
MySQL 8.4 signs accounts in with `caching_sha2_password`. While the server holds an account in its cache, a scrambled
|
|
33
|
+
proof suffices. The first login after a MySQL restart (or `FLUSH PRIVILEGES`, a password change) needs the password
|
|
34
|
+
itself, which a client without TLS encrypts with the server's RSA public key. Up to 3.25, mysql2 fetched that key from
|
|
35
|
+
whoever answered, so a host in the network path could hand out its own key and read the database password
|
|
36
|
+
(GHSA-cc6q-ch5m-cffx). mysql2 3.26 fetches it only when allowed and otherwise fails with
|
|
37
|
+
`PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED`.
|
|
38
|
+
|
|
39
|
+
The trap is the timing: while the server's cache is warm, everything works. A project that only raised mysql2 would
|
|
40
|
+
pass every test and fail on the first login after the next MySQL restart.
|
|
41
|
+
|
|
42
|
+
So the framework decides once, for every connection it opens (application and owner URL, Better-Auth, migration state,
|
|
43
|
+
the migrate CLI):
|
|
44
|
+
|
|
45
|
+
| The URL carries … | `local` / `ci` / `e2e` | any other environment |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `ssl`, `socketPath`, `serverPublicKey` or `allowPublicKeyRetrieval` | the URL decides | the URL decides |
|
|
48
|
+
| none of them, `mysql://` | key retrieval allowed (nobody sits in that network path) | **boot stops** with `MysqlTransportUndecidedError` |
|
|
49
|
+
| none of them, `mariadb://` | unchanged | unchanged (MariaDB uses `mysql_native_password` by default and needs no RSA key) |
|
|
50
|
+
|
|
51
|
+
The environment is the configured `env` (`NODE_ENV` for the migrate CLI; unset means `local`).
|
|
52
|
+
|
|
53
|
+
**What to add to a deployed MySQL URL, one of:**
|
|
54
|
+
|
|
55
|
+
| Parameter | When |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `?ssl={"rejectUnauthorized":true,"verifyIdentity":true}` | **Recommended.** mysql2 then checks the certificate chain AND that the certificate was issued for the URL's host. Both flags are needed: with `rejectUnauthorized` alone mysql2 accepts any certificate a trusted CA issued for any domain, so a host in the network path with a certificate for its own domain still receives the password. The URL host must be the DNS name on the certificate: for an IP address mysql2 skips the name check, and only a private CA (`"ca":"<PEM>"`, URL-encoded) then protects the connection. For a provider's or your own CA add `"ca":"<PEM>"`. Never `"rejectUnauthorized":false` on a deployed stage: it encrypts but accepts any certificate |
|
|
58
|
+
| `?serverPublicKey=<PEM>` | No TLS, but you pin the server's RSA public key (URL-encoded PEM; `SHOW STATUS LIKE 'Caching_sha2_password_rsa_public_key'`). Update it when the server's key changes |
|
|
59
|
+
| `?allowPublicKeyRetrieval=true` | No TLS, and you accept that a host in the network path can read the password, e.g. API and database in one private network you control. This is the behaviour of 12.14 and before |
|
|
60
|
+
| `?allowPublicKeyRetrieval=false` | The account does not use `caching_sha2_password` (for example `mysql_native_password`), so no RSA key is ever needed. Allows nothing, only answers the question |
|
|
61
|
+
|
|
62
|
+
Example (environment variable of a deployed stage):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
NSC__DATABASE__URL='mysql://app:<password>@db.internal:3306/project?ssl={"rejectUnauthorized":true,"verifyIdentity":true}'
|
|
66
|
+
NSC__DATABASE__OWNER_URL='mysql://owner:<password>@db.internal:3306/project?ssl={"rejectUnauthorized":true,"verifyIdentity":true}'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
mysql2 reads these parameters from the URL itself (JSON values such as `{"rejectUnauthorized":true,"verifyIdentity":true}` are parsed), so
|
|
70
|
+
nothing else changes in the project.
|
|
71
|
+
|
|
72
|
+
**API:** `mysqlKeyRetrievalOption(url, variant, env?)` returns the option the framework adds (or throws
|
|
73
|
+
`MysqlTransportUndecidedError`); a project that opens a `mysql2` pool of its own can use it for the same decision.
|
|
74
|
+
|
|
75
|
+
**Check:** projects on MongoDB, PostgreSQL or MariaDB: nothing. Projects on MySQL: start the API once against a deployed
|
|
76
|
+
stage's configuration; if it stops with `MysqlTransportUndecidedError`, add a parameter from the table.
|
|
77
|
+
|
|
78
|
+
## 2. Dependencies
|
|
79
|
+
|
|
80
|
+
- **`mysql2` peer floor `>= 3.26.0`** (was `>= 3.25.0`); tested with 3.26.1. 3.25 and older carry four advisories that
|
|
81
|
+
mysql2 published in its repository between 2026-12-01 and 2026-12-05. They are not in GitHub's global advisory
|
|
82
|
+
database yet, so `pnpm audit` does not report them:
|
|
83
|
+
- GHSA-jxvc-9hcf-fw42 (critical): SQL injection through `query()` on non-UTF-8 connection charsets (`latin1`, `sjis`,
|
|
84
|
+
`cp932`, `big5`, …). The framework connects with mysql2's default `utf8mb4` and is not affected unless a URL sets
|
|
85
|
+
`?charset=` to one of them.
|
|
86
|
+
- GHSA-mxg9-wm8p-75g7 (high): forged packets accepted before the TLS handshake completes. Affects connections WITH
|
|
87
|
+
TLS, so it matters exactly for the recommended setup of §1.
|
|
88
|
+
- GHSA-cc6q-ch5m-cffx (medium): the RSA key problem of §1.
|
|
89
|
+
- GHSA-mccj-fxgw-vqw2 (medium): the string `'false'` enabled the cleartext plugin. The framework does not set it.
|
|
90
|
+
|
|
91
|
+
## Troubleshooting
|
|
92
|
+
|
|
93
|
+
| Symptom | Cause | Fix |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| Boot stops: `MysqlTransportUndecidedError: The MySQL source mysql://… does not say how the password travels` | Deployed environment, MySQL URL without a transport parameter (§1) | Add one parameter from §1 to the URL |
|
|
96
|
+
| `PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED` on the first login after a MySQL restart | The URL says `allowPublicKeyRetrieval=false`, but the account uses `caching_sha2_password`; or a pool of the project's own without the decision | Use TLS or `allowPublicKeyRetrieval=true`; for an own pool, `mysqlKeyRetrievalOption()` |
|
|
97
|
+
| `ERESOLVE` / peer warning for `mysql2` | The project still pins 3.25 | `pnpm add mysql2@3.26.1` |
|
|
98
|
+
|
|
99
|
+
## Module Documentation
|
|
100
|
+
|
|
101
|
+
- `src/core/common/persistence/sql/mysql/mysql-transport.ts`
|
|
102
|
+
- `docs/choosing-a-database.md` (MySQL section)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Server framework in TypeScript on top of NestJS: GraphQL and REST APIs on MongoDB, PostgreSQL, MySQL or MariaDB, with authentication, field-level permissions, multi-tenancy, offline sync and an AI assistant.",
|
|
6
6
|
"keywords": [
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"kysely": ">=0.29.0 <0.30.0",
|
|
176
176
|
"mongodb": ">=7.9.1 <8",
|
|
177
177
|
"mongoose": ">=9.13.0 <10",
|
|
178
|
-
"mysql2": ">=3.
|
|
178
|
+
"mysql2": ">=3.26.0 <4",
|
|
179
179
|
"pg": ">=8.23.0 <9",
|
|
180
180
|
"typeorm": ">=1.1.0 <2"
|
|
181
181
|
},
|
|
@@ -284,7 +284,7 @@
|
|
|
284
284
|
"kysely": "0.29.9",
|
|
285
285
|
"mongodb": "7.9.1",
|
|
286
286
|
"mongoose": "9.13.2",
|
|
287
|
-
"mysql2": "3.
|
|
287
|
+
"mysql2": "3.26.1",
|
|
288
288
|
"nodemon": "3.1.14",
|
|
289
289
|
"otpauth": "9.6.0",
|
|
290
290
|
"oxfmt": "0.80.0",
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type MysqlVariant,
|
|
11
11
|
toMysqlStatement,
|
|
12
12
|
} from './mysql-session.js';
|
|
13
|
+
import { mysqlKeyRetrievalOption } from './mysql-transport.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The SQL engine adapters for MySQL 8.4 and MariaDB 11.8 (plan §3.10, phase 6) — the PostgreSQL ones' counterpart.
|
|
@@ -40,6 +41,8 @@ export interface MysqlExecutor extends SqlExecutor {
|
|
|
40
41
|
const logger = new Logger('SqlPool');
|
|
41
42
|
|
|
42
43
|
export async function createMysqlExecutor(options: MysqlExecutorOptions): Promise<MysqlExecutor> {
|
|
44
|
+
// Before anything connects: a deployed MySQL source must say how the password travels without TLS (12.15.0)
|
|
45
|
+
mysqlKeyRetrievalOption(options.url, options.variant);
|
|
43
46
|
switch (options.engine) {
|
|
44
47
|
case 'drizzle':
|
|
45
48
|
return createDrizzleExecutor(options);
|
|
@@ -74,7 +77,11 @@ async function loadMysql2(): Promise<any> {
|
|
|
74
77
|
function createPool(mysql2: any, options: MysqlExecutorOptions): any {
|
|
75
78
|
// The URL scheme picks the variant; the driver only understands `mysql://`
|
|
76
79
|
const url = options.url.replace(/^mariadb:/i, 'mysql:');
|
|
77
|
-
const pool = mysql2.createPool(
|
|
80
|
+
const pool = mysql2.createPool({
|
|
81
|
+
...mysqlConnectionOptions(url, options.maxConnections ?? 10),
|
|
82
|
+
// Key retrieval without TLS where no one sits in the network path, or nothing and the URL decides (12.15.0)
|
|
83
|
+
...mysqlKeyRetrievalOption(options.url, options.variant),
|
|
84
|
+
});
|
|
78
85
|
pool.on('connection', (connection: any) => {
|
|
79
86
|
connection.query(MYSQL_SESSION_SQL, (error: Error | null) => {
|
|
80
87
|
if (error) {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isLocalEnv } from '../../../helpers/cookies.helper.js';
|
|
2
|
+
import { ConfigService } from '../../../services/config.service.js';
|
|
3
|
+
import { redactUrl } from '../../data-source.config.js';
|
|
4
|
+
import type { MysqlVariant } from './mysql-session.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How the password travels on a MySQL connection without TLS (12.15.0).
|
|
8
|
+
*
|
|
9
|
+
* MySQL 8.4 signs accounts in with `caching_sha2_password`. While the server holds the account in its cache, a scrambled
|
|
10
|
+
* proof suffices; the first login after a restart (or `FLUSH PRIVILEGES`, a password change) needs the password itself.
|
|
11
|
+
* Without TLS the client encrypts it with the server's RSA public key — and mysql2 up to 3.25 fetched that key from
|
|
12
|
+
* whoever answered, so a host in the network path could hand out its own key and read the password
|
|
13
|
+
* (GHSA-cc6q-ch5m-cffx). mysql2 3.26 refuses the fetch unless TLS, a socket path, a pinned key (`serverPublicKey`) or
|
|
14
|
+
* `allowPublicKeyRetrieval: true` allows it, and the login fails with `PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED`. While the
|
|
15
|
+
* cache is warm everything works, so the failure surfaces only after the next MySQL restart.
|
|
16
|
+
*
|
|
17
|
+
* The framework therefore decides once, for every connection it opens:
|
|
18
|
+
*
|
|
19
|
+
* | The URL says … | `local` / `ci` / `e2e` | every other environment |
|
|
20
|
+
* |---|---|---|
|
|
21
|
+
* | `ssl`, `socketPath`, `serverPublicKey` or `allowPublicKeyRetrieval` | the URL decides | the URL decides |
|
|
22
|
+
* | nothing | key retrieval allowed (no one sits in the path of a developer's or a runner's own network) | **refused at once** on MySQL, naming the ways out; MariaDB (`mysql_native_password` by default) is left alone |
|
|
23
|
+
*
|
|
24
|
+
* `?allowPublicKeyRetrieval=false` is the explicit answer for an account that needs no RSA key
|
|
25
|
+
* (`mysql_native_password`): it silences the refusal and allows nothing.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** URL parameters with which a project states how the password travels on a connection without TLS */
|
|
29
|
+
export const MYSQL_TRANSPORT_PARAMETERS = ['allowPublicKeyRetrieval', 'serverPublicKey', 'socketPath', 'ssl'] as const;
|
|
30
|
+
|
|
31
|
+
/** A deployed MySQL source whose URL does not say how the password travels (12.15.0) */
|
|
32
|
+
export class MysqlTransportUndecidedError extends Error {
|
|
33
|
+
override readonly name = 'MysqlTransportUndecidedError';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The environment the running configuration names, else `NODE_ENV` (the migrate CLI runs without a configuration); an
|
|
38
|
+
* unset `NODE_ENV` means `local`, as in `getEnvironmentConfig()`
|
|
39
|
+
*/
|
|
40
|
+
export function currentMysqlEnvironment(): string {
|
|
41
|
+
return ConfigService.configFastButReadOnly?.env || process.env.NODE_ENV || 'local';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The option the framework adds to a connection's options: `allowPublicKeyRetrieval: true` in `local` / `ci` / `e2e`
|
|
46
|
+
* when the URL states nothing, otherwise none — the URL's own parameters reach mysql2 unchanged and decide. Throws
|
|
47
|
+
* `MysqlTransportUndecidedError` for a MySQL URL that states nothing on any other environment.
|
|
48
|
+
*
|
|
49
|
+
* @param url - the source's URL (`mysql://` or `mariadb://`)
|
|
50
|
+
* @param variant - the server the URL reaches
|
|
51
|
+
* @param env - the configured environment; defaults to the running one
|
|
52
|
+
*/
|
|
53
|
+
export function mysqlKeyRetrievalOption(
|
|
54
|
+
url: string,
|
|
55
|
+
variant: MysqlVariant,
|
|
56
|
+
env: string | undefined = currentMysqlEnvironment(),
|
|
57
|
+
): { allowPublicKeyRetrieval?: true } {
|
|
58
|
+
const stated = statedTransportParameters(url);
|
|
59
|
+
if (stated === null || stated.length > 0) {
|
|
60
|
+
// The URL decides (an unparsable URL fails in the driver with its own message)
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
if (isLocalEnv(env)) {
|
|
64
|
+
return { allowPublicKeyRetrieval: true };
|
|
65
|
+
}
|
|
66
|
+
if (variant === 'mysql') {
|
|
67
|
+
throw new MysqlTransportUndecidedError(
|
|
68
|
+
`The MySQL source ${redactUrl(url)} does not say how the password travels, and the environment ` +
|
|
69
|
+
`"${env ?? ''}" is not local. mysql2 fetches the server's RSA key over a connection without TLS only when ` +
|
|
70
|
+
'allowed, so the first login after the next MySQL restart would fail with PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED. ' +
|
|
71
|
+
'Add one parameter to the URL: ?ssl={"rejectUnauthorized":true,"verifyIdentity":true} (TLS, recommended: verifyIdentity makes mysql2 ' +
|
|
72
|
+
'check that the certificate names the URL host, which must be a DNS name; with your CA add "ca":"<PEM>"), ' +
|
|
73
|
+
"?serverPublicKey=<PEM of the server's RSA public key>, " +
|
|
74
|
+
'?allowPublicKeyRetrieval=true (accepts that a host in the network path can read the password), or ' +
|
|
75
|
+
'?allowPublicKeyRetrieval=false when the account does not use caching_sha2_password. ' +
|
|
76
|
+
'See migration-guides/12.14.x-to-12.15.x.md.',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The transport parameters the URL carries, or `null` when it cannot be parsed */
|
|
83
|
+
function statedTransportParameters(url: string): null | string[] {
|
|
84
|
+
let parameters: URLSearchParams;
|
|
85
|
+
try {
|
|
86
|
+
parameters = new URL(url).searchParams;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return MYSQL_TRANSPORT_PARAMETERS.filter((name) => parameters.has(name));
|
|
91
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -113,6 +113,7 @@ export * from './core/common/persistence/sync-model.js';
|
|
|
113
113
|
export * from './core/common/persistence/unsupported-capability.error.js';
|
|
114
114
|
export * from './core/common/persistence/sql/mysql/mysql-data-store.js';
|
|
115
115
|
export * from './core/common/persistence/sql/mysql/mysql-lock-store.js';
|
|
116
|
+
export * from './core/common/persistence/sql/mysql/mysql-transport.js';
|
|
116
117
|
export * from './core/common/persistence/sql/postgres/postgres-lock-store.js';
|
|
117
118
|
export * from './core/common/persistence/sql/sql-data-store.js';
|
|
118
119
|
export * from './core/common/persistence/sql/sql-errors.js';
|