Fix review findings: proto smuggling, trade-leg recall, escrow cap, static headers, rate limits, rankings DoS

Fixed: validator rejects __proto__/constructor keys at any depth (transport capacity bypass); trade and site shipments
cannot be recalled; trade escrow refund capped by Rack hall; CSP/nosniff on static files and connect-src 'self';
IPv6 /64 limiter keys + LRU eviction + per-username login bucket + scrypt concurrency cap; 5 s footprint cache for
rankings; rename uses text.cleanText; 429s no longer pinned in the idempotency store; 30-day notification prune;
units_offline notification on first offline. Accepted items listed in docs/DECISIONS.md R1.
Tested: npm test 182/182 incl. test/review-fixes.test.js (regression tests). Not re-reviewed after the fixes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
jvanvik 2026-10-11 19:06:51 +02:00
parent b18645dca1
commit d84b0c9d12
11 changed files with 190 additions and 17 deletions

View file

@ -6,6 +6,15 @@
* is true. With coerce: true, strings are turned into numbers/booleans first (query strings).
*/
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
// JSON.parse makes "__proto__" an OWN key; copying it with plain assignment would swap the prototype of the result.
// Reject these keys everywhere, including inside pass-through (additionalProperties) values.
const BAD_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
function hasBadKey(v, depth) {
if (v === null || typeof v !== 'object') return false;
if (depth > 8) return true;
for (const k of Object.keys(v)) if (BAD_KEYS.has(k) || hasBadKey(v[k], (depth || 0) + 1)) return true;
return false;
}
function check(schema, v, path, errors, coerce) {
if (coerce && typeof v === 'string') {
@ -42,8 +51,9 @@ function check(schema, v, path, errors, coerce) {
const props = schema.properties || {};
for (const k of schema.required || []) if (!hasOwn(v, k) || v[k] === undefined) errors.push({ path: path ? path + '.' + k : k, message: 'is required' });
for (const k of Object.keys(v)) {
if (BAD_KEYS.has(k)) { errors.push({ path: path ? path + '.' + k : k, message: 'is not a known field' }); continue; }
if (hasOwn(props, k)) out[k] = check(props[k], v[k], path ? path + '.' + k : k, errors, coerce);
else if (schema.additionalProperties) out[k] = v[k];
else if (schema.additionalProperties) { if (hasBadKey(v[k], 0)) errors.push({ path: path ? path + '.' + k : k, message: 'contains a forbidden key' }); else out[k] = v[k]; }
else errors.push({ path: path ? path + '.' + k : k, message: 'is not a known field' });
}
return out;