mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* fix(api): sanitize catch-block error.message in middleware/hooks routes POST /api/middleware/hooks and PUT /api/middleware/hooks/[name] returned the raw error?.message in their 500 response bodies (Hard Rule #12), which could leak internal SQLite error text/paths on a DB failure. Both now route through sanitizeErrorMessage() from open-sse/utils/error.ts, matching the pattern already used elsewhere in the codebase. Regression guard: tests/unit/middleware-hooks-error-sanitization.test.ts Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * test(mutation): register middleware-hooks-error-sanitization in stryker tap.testFiles The mutation test-coverage gate (check:mutation-test-coverage --strict) flagged tests/unit/middleware-hooks-error-sanitization.test.ts as covering open-sse/utils/error.ts but missing from stryker.conf.json's tap.testFiles list. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(changelog): restore CHANGELOG bullets eaten by release sync Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(changelog): re-restore CHANGELOG bullet after further release sync Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: Chirag Singhal <chirag127@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
|
|
/**
|
|
* Hard Rule #12: catch-block error responses must route through
|
|
* `sanitizeErrorMessage()` (or `buildErrorBody()`), never return raw
|
|
* `err.message`. See docs/security/ERROR_SANITIZATION.md.
|
|
*
|
|
* These two routes wrap DB writes + registry `registerHook`, whose
|
|
* SQLite failures can surface with internal path fragments (e.g.
|
|
* "SQLITE_ERROR: near /var/lib/omniroute/..."). Guard against
|
|
* regression by asserting the raw `error?.message ||` pattern is
|
|
* absent and `sanitizeErrorMessage` is imported.
|
|
*/
|
|
|
|
const ROUTES = [
|
|
"src/app/api/middleware/hooks/route.ts",
|
|
"src/app/api/middleware/hooks/[name]/route.ts",
|
|
];
|
|
|
|
for (const path of ROUTES) {
|
|
test(`${path} imports sanitizeErrorMessage from open-sse/utils/error`, () => {
|
|
const source = readFileSync(path, "utf8");
|
|
assert.ok(
|
|
/import\s*\{[^}]*\bsanitizeErrorMessage\b[^}]*\}\s*from\s*["']@omniroute\/open-sse\/utils\/error["']/.test(
|
|
source
|
|
),
|
|
`expected ${path} to import sanitizeErrorMessage from "@omniroute/open-sse/utils/error"`
|
|
);
|
|
});
|
|
|
|
test(`${path} does not return raw error?.message in NextResponse.json`, () => {
|
|
const source = readFileSync(path, "utf8");
|
|
assert.ok(
|
|
!/error\?\.message\s*\|\|/.test(source),
|
|
`expected ${path} to have no raw \`error?.message ||\` fallback (Hard Rule #12)`
|
|
);
|
|
});
|
|
}
|