mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
fix(db): drop NUL from every request value before any logic runs
The database stores no NUL on either engine, but the application still held the value a client sent. A key or a check made from it was then a different value from the one the database compared: `victim@x.test` followed by NUL was a fresh key for the per-email password-reset throttle while the lookup found the victim's row, so every spelling mailed a new link and voided the last one. Every input now loses its NUL where it enters TREK: the nulFreeRequest middleware after the body parsers (path, query string, body, cookies), the first global pipe for what a route parses itself (a multipart body), the websocket adapter for every frame, and the MCP registry through a new host-supplied input mapper, since /mcp keeps its raw body. Headers need nothing: Node refuses a NUL in one with a 400. A string under a key naming a password stays as sent: it is only ever hashed, and stripping it would lock out an account whose password was set with one. The stripping in the database layer stays as the backstop for what does not come from a request.
This commit is contained in:
@@ -4,6 +4,7 @@ import { applyGlobalMiddleware, routingCspOrigins } from './middleware/globalMid
|
||||
import { httpConfig } from './nest/app-config';
|
||||
import { AppModule } from './nest/app.module';
|
||||
import { apiDocsEnabled } from './nest/common/api-docs.kill-switch';
|
||||
import { nulFreeRequest } from './nest/common/nul-free-input';
|
||||
import { validateBodyContracts } from './nest/common/validate-body-contracts';
|
||||
import { validateManagedRoutes } from './nest/common/validate-managed-routes';
|
||||
import { PUBLIC_ROUTE_ALLOW_LIST, validateRouteGuards } from './nest/common/validate-route-guards';
|
||||
@@ -49,6 +50,7 @@ import nodeHttp from 'node:http';
|
||||
* 4b. setupApiDocs — Swagger UI/spec at /api/docs* when TREK_API_DOCS_ENABLED.
|
||||
* 4c. the named body-parser wrappers — the global 100kb JSON/urlencoded
|
||||
* parsers, exempting /mcp so the MCP SDK reads the raw stream.
|
||||
* 4d. nulFreeRequest — drops NUL from the path, query, body and cookies.
|
||||
* 5. app.init() — every domain controller, including the transport surface
|
||||
* that used to live pre-init: /api/health (FeaturesController), OAuth
|
||||
* discovery documents (DiscoveryController), the /oauth/consent COOP
|
||||
@@ -228,6 +230,11 @@ export async function buildApp(): Promise<INestApplication> {
|
||||
instance.use(function urlencodedParser(req: Request, res: Response, next: NextFunction) {
|
||||
return isMcp(req) ? next() : urlencoded(req, res, next);
|
||||
});
|
||||
// Every request value without NUL from here on (nest/common/nul-free-input.ts):
|
||||
// the path, the query string, the parsed body and the cookies, before any
|
||||
// guard, interceptor or controller reads them, so a key or a check made from
|
||||
// a value matches what the database stores for it.
|
||||
instance.use(nulFreeRequest);
|
||||
if (apiDocsEnabled()) setupApiDocs(app);
|
||||
// The per-request EntityManager fork every Nest route runs inside (D6). This
|
||||
// used to be @mikro-orm/nestjs's own middleware, which Nest 11 mounts as an
|
||||
|
||||
Reference in New Issue
Block a user