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
@@ -5,6 +5,7 @@ import type { CollectionOverride } from '../shared/collectionOverride.js'
|
||||
import { userMeetsRole } from '../access/predicates.js'
|
||||
import { createDailyPurge } from '../shared/purge.js'
|
||||
import { clientIp, consumeRateLimit } from '../shared/rateLimit.js'
|
||||
import { readCappedBody as readCapped } from '../shared/readCappedBody.js'
|
||||
import { CONSENT_CATEGORIES } from './categories.js'
|
||||
import { CONSENT_CATEGORY_LABELS } from './categoryLabels.js'
|
||||
import { CONSENT_VERSION } from './storage.js'
|
||||
@@ -89,35 +90,9 @@ const missingTableLogged = new WeakSet<object>()
|
||||
/** Largest body the endpoint reads. A decision is about 200 bytes; anything near this is not one. */
|
||||
export const CONSENT_LOG_MAX_BYTES = 4096
|
||||
|
||||
/**
|
||||
* The request body as text, or null when it is larger than `max` bytes: a declared `content-length` over the cap
|
||||
* is refused before anything is read, and the stream is read only up to the cap (a body without a length, or with
|
||||
* a false one, cannot make the server hold more).
|
||||
*/
|
||||
export async function readCappedBody(request: Request, max: number = CONSENT_LOG_MAX_BYTES): Promise<null | string> {
|
||||
const declared = Number(request.headers.get('content-length'))
|
||||
if (Number.isFinite(declared) && declared > max) {return null}
|
||||
if (!request.body) {return ''}
|
||||
const reader = request.body.getReader()
|
||||
const chunks: Uint8Array[] = []
|
||||
let size = 0
|
||||
for (;;) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {break}
|
||||
size += value.byteLength
|
||||
if (size > max) {
|
||||
await reader.cancel().catch(() => {})
|
||||
return null
|
||||
}
|
||||
chunks.push(value)
|
||||
}
|
||||
const all = new Uint8Array(size)
|
||||
let at = 0
|
||||
for (const chunk of chunks) {
|
||||
all.set(chunk, at)
|
||||
at += chunk.byteLength
|
||||
}
|
||||
return new TextDecoder().decode(all)
|
||||
/** The request body as text, or null when it is larger than `max` bytes (shared/readCappedBody.ts). */
|
||||
export function readCappedBody(request: Request, max: number = CONSENT_LOG_MAX_BYTES): Promise<null | string> {
|
||||
return readCapped(request, max)
|
||||
}
|
||||
|
||||
/** Cookie Settings → Policy version per Payload instance, cached for a minute. */
|
||||
|
||||
Reference in New Issue
Block a user