Consent log endpoint: body capped at 4 KiB (413), version bounded by the policy version; consent-log-migration a warning
Review C-1: the endpoint, on on every site, parsed a 20 MB body. It now refuses a content-length over CONSENT_LOG_MAX_BYTES (4096) before reading and reads the stream only up to the cap (readCappedBody), so a missing or false length cannot make it hold more. A version above Cookie settings' policy version is 400 (the cached version is read again once, for an editor's fresh raise); versions from 1 up are accepted (pages rendered before a raise). Review C-2: consent-log-migration is a warning, like every consent check of 1.17.0 (the owner's decision). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a448ba5df
commit
963464d6cb
@@ -287,25 +287,25 @@ describe('one-call helpers — layout, page, GEO routes', () => {
|
||||
})
|
||||
|
||||
describe('consent log', () => {
|
||||
// a real Request, as Payload passes one (the endpoint reads the body stream with a cap)
|
||||
const post = (body: unknown, ip = '10.6.0.1') =>
|
||||
buildConsentLogEndpoint().handler({
|
||||
headers: new Headers({ 'x-real-ip': ip }),
|
||||
json: async () => body,
|
||||
payload,
|
||||
} as never) as Promise<Response>
|
||||
buildConsentLogEndpoint().handler(
|
||||
Object.assign(new Request('http://localhost/api/ipal/consent', { body: JSON.stringify(body), headers: { 'content-type': 'application/json', 'x-real-ip': ip }, method: 'POST' }), { payload }) as never,
|
||||
) as Promise<Response>
|
||||
const state = { analytics: true, functional: false, marketing: false, necessary: true }
|
||||
|
||||
test('stores id, choices and version only', async () => {
|
||||
const res = await post({ id: 'a1b2c3d4e5f6a7b8c9d0e1f2', state, version: 2 })
|
||||
// the site's policy version is 1 (Cookie settings not changed): a decision carries 1 at most (1.17.0)
|
||||
const res = await post({ id: 'a1b2c3d4e5f6a7b8c9d0e1f2', state, version: 1 })
|
||||
expect(res.status).toBe(201)
|
||||
const { docs } = await payload.find({ collection: 'consent-records' as never, where: { consentId: { equals: 'a1b2c3d4e5f6a7b8c9d0e1f2' } } })
|
||||
const rec = docs[0] as unknown as Record<string, unknown>
|
||||
expect(rec).toMatchObject({ choices: state, version: 2 })
|
||||
expect(rec).toMatchObject({ choices: state, version: 1 })
|
||||
expect(Object.keys(rec).filter((k) => /ip|agent|email/i.test(k))).toEqual([])
|
||||
})
|
||||
|
||||
test('rejects malformed records', async () => {
|
||||
for (const bad of [{}, { id: 'x', state, version: 1 }, { id: 'a1b2c3d4e5f6a7b8', state: { analytics: 'yes' }, version: 1 }, { id: 'a1b2c3d4e5f6a7b8', state, version: 0 }]) {
|
||||
for (const bad of [{}, { id: 'x', state, version: 1 }, { id: 'a1b2c3d4e5f6a7b8', state: { analytics: 'yes' }, version: 1 }, { id: 'a1b2c3d4e5f6a7b8', state, version: 0 }, { id: 'a1b2c3d4e5f6a7b8', state, version: 2 }]) {
|
||||
expect((await post(bad, '10.6.0.2')).status).toBe(400)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user