mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +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:
@@ -1,3 +1,4 @@
|
||||
import { nulFreeInput } from '../db/nul-free';
|
||||
import {
|
||||
demoDenied,
|
||||
errorResult,
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
type McpAccessPolicy,
|
||||
type McpAccessValidator,
|
||||
type McpErrorMapper,
|
||||
type McpInputMapper,
|
||||
type McpToolGate,
|
||||
type ToolOptions,
|
||||
} from '../nest-mcp';
|
||||
@@ -106,3 +108,14 @@ export function trekDemoToolGate(isDemoUser: (userId: number) => Promise<boolean
|
||||
*/
|
||||
export const trekMcpErrorMapper: McpErrorMapper = (err) =>
|
||||
err instanceof DomainError ? errorResult(err.mcpMessage ?? err.publicMessage) : undefined;
|
||||
|
||||
/**
|
||||
* What a client sends over MCP, without NUL characters, before any tool,
|
||||
* prompt or resource template reads it: the same rule as every HTTP request
|
||||
* (`nest/common/nul-free-input.ts`), so a key or a check a tool makes from an
|
||||
* argument sees the value the database stores. /mcp keeps its raw body for the
|
||||
* SDK, so the registry is where a tool's input enters TREK. Given to
|
||||
* McpModule.forRoot (AppModule), which the transport and the in-app assistant
|
||||
* both attach through.
|
||||
*/
|
||||
export const trekMcpInputMapper: McpInputMapper = nulFreeInput;
|
||||
|
||||
Reference in New Issue
Block a user