IAWL ideas, group B: sizes before work, one link rule, no stand-in locale, strict switches
- Request bodies from strangers are read only up to a cap, declared length or not: mail-service confirm, CSP reports, page views, MCP (maxBytes, 413). readCappedBody moves to shared/ (the consent log keeps exporting it). - searchContent / createSearchRoute / MCP search: queryLimit (default 200 characters, 10 words) before the database; an unknown ?locale is the default locale throughout. - Rich text: autolinks and links marked internal pass safeHref too; lexicalToMarkdown drops unsafe link targets. - truncate() never returns more than its limit (summary / meta autofill after validation). - resolveRoute answers null for a locale the site does not have (xx, all, *): no default-locale page under another code (page route past the proxy, /md/xx, MCP). - A 404 page that is a draft is not shown (resolveNotFoundPage, getNotFoundPage). - readPublished() access rule (exported); Site integrations readVersions: admin. - Plugin switches, buildCsp, buildSecurityHeaders and the seed guard refuse nonsense values at start; an unknown role name is met by nobody, requireRole throws on one. - Docs, AGENT.md, iapl-collection and iapl-audit skills. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e821d52d19
commit
ecf03c8dc0
@@ -3,6 +3,7 @@ import type { Endpoint, PayloadRequest } from 'payload'
|
||||
import type { RelayOptions } from './options.js'
|
||||
|
||||
import { clientIp, consumeRateLimit, tooManyRequests } from '../../shared/rateLimit.js'
|
||||
import { readCappedBody } from '../../shared/readCappedBody.js'
|
||||
import { RELAY_CONFIRM_PATH, RELAY_DEFAULTS } from './constants.js'
|
||||
import { sha256Hex, takeNonce, writeRelayCandidate } from './store.js'
|
||||
|
||||
@@ -14,13 +15,17 @@ const MAX_BODY = 2048
|
||||
const notFound = () => new Response(null, { headers: { 'cache-control': 'no-store' }, status: 404 })
|
||||
|
||||
async function readBody(req: PayloadRequest): Promise<unknown> {
|
||||
const length = Number(req.headers.get('content-length') ?? 0)
|
||||
if (length > MAX_BODY) {return null}
|
||||
try {
|
||||
// read only up to the cap, whether or not the call declares its length (a chunked body has none)
|
||||
const text = (req as unknown as Request).body ? await readCappedBody(req as unknown as Request, MAX_BODY) : null
|
||||
if (text !== null) {return JSON.parse(text) as unknown}
|
||||
if ((req as unknown as Request).body) {return null}
|
||||
// a request without a stream (a double in a test, a body Payload already read)
|
||||
if (Number(req.headers.get('content-length') ?? 0) > MAX_BODY) {return null}
|
||||
const read = (req as { text?: () => Promise<string> }).text
|
||||
if (typeof read !== 'function') {return (await req.json?.()) as unknown}
|
||||
const text = await read.call(req)
|
||||
return text.length <= MAX_BODY ? (JSON.parse(text) as unknown) : null
|
||||
const whole = await read.call(req)
|
||||
return whole.length <= MAX_BODY ? (JSON.parse(whole) as unknown) : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user