@simmalugnt-se/payload-consent 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.js +6 -0
- package/dist/scans.js +23 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
- Adding a scan's finding to a service keeps what the scan could not see (`summary.problems`):
|
|
6
|
+
judging the scan again wrote over it, so an incomplete scan looked complete (0.5.0).
|
|
7
|
+
- Adding a finding to a service writes as the editor, so a project's own access on the services
|
|
8
|
+
applies, in one of the site's languages, and with a known category (`necessary` otherwise).
|
|
9
|
+
- Evidence larger than 8 MB is refused before it is read; the scanner sends files up to 4 MB.
|
|
10
|
+
|
|
3
11
|
## 0.5.1
|
|
4
12
|
|
|
5
13
|
- What a visitor was shown is kept when it changes: a reworded banner text or a service's new
|
package/dist/evidence.d.ts
CHANGED
|
@@ -8,5 +8,7 @@ import { type ConsentPluginOptions } from "./types.ts";
|
|
|
8
8
|
export declare function evidenceCollection(options: ConsentPluginOptions): CollectionConfig;
|
|
9
9
|
/** Deletes the evidence of all but the latest `keep` finished scans, and any without a scan. */
|
|
10
10
|
export declare function pruneEvidence(payload: Payload, keep: number): Promise<void>;
|
|
11
|
+
/** The scanner sends files up to 4 MB; anything far larger is not its evidence. */
|
|
12
|
+
export declare const MAX_EVIDENCE_BYTES: number;
|
|
11
13
|
/** The scanner posts each evidence file here after the result, one file per request. */
|
|
12
14
|
export declare function evidenceEndpoint(options: ConsentPluginOptions, checkToken: (req: PayloadRequest) => boolean): Endpoint;
|
package/dist/evidence.js
CHANGED
|
@@ -69,6 +69,8 @@ export async function pruneEvidence(payload, keep) {
|
|
|
69
69
|
overrideAccess: true,
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
/** The scanner sends files up to 4 MB; anything far larger is not its evidence. */
|
|
73
|
+
export const MAX_EVIDENCE_BYTES = 8 * 1024 * 1024;
|
|
72
74
|
/** The scanner posts each evidence file here after the result, one file per request. */
|
|
73
75
|
export function evidenceEndpoint(options, checkToken) {
|
|
74
76
|
return {
|
|
@@ -95,9 +97,13 @@ export function evidenceEndpoint(options, checkToken) {
|
|
|
95
97
|
return Response.json({ error: "Unknown scan" }, { status: 404 });
|
|
96
98
|
if (scan.status !== "done")
|
|
97
99
|
return Response.json({ error: "The scan has no result yet" }, { status: 409 });
|
|
100
|
+
if (Number(req.headers.get("content-length") ?? 0) > MAX_EVIDENCE_BYTES)
|
|
101
|
+
return Response.json({ error: "Too large" }, { status: 413 });
|
|
98
102
|
const data = Buffer.from((await req.arrayBuffer?.()) ?? new ArrayBuffer(0));
|
|
99
103
|
if (!data.length)
|
|
100
104
|
return Response.json({ error: "Empty file" }, { status: 400 });
|
|
105
|
+
if (data.length > MAX_EVIDENCE_BYTES)
|
|
106
|
+
return Response.json({ error: "Too large" }, { status: 413 });
|
|
101
107
|
const [, state, , extension] = match;
|
|
102
108
|
const pdf = extension === "pdf";
|
|
103
109
|
const doc = await req.payload.create({
|
package/dist/scans.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { canManage, manageAccess } from "./access.js";
|
|
3
|
+
import { CATEGORIES } from "./defaults.js";
|
|
3
4
|
import { evaluateScan, scanProblems, } from "./evaluate.js";
|
|
4
5
|
import { evidenceEndpoint } from "./evidence.js";
|
|
5
6
|
import { notifyScan } from "./notify.js";
|
|
@@ -335,14 +336,25 @@ function endpoints(options) {
|
|
|
335
336
|
!serviceName ||
|
|
336
337
|
(kind !== "cookie" && kind !== "localStorage" && kind !== "host"))
|
|
337
338
|
return Response.json({ error: "Name the finding and the service" }, { status: 400 });
|
|
338
|
-
|
|
339
|
+
// The site's own languages only; anything else writes the default one.
|
|
340
|
+
const localization = req.payload.config.localization;
|
|
341
|
+
const locale = localization &&
|
|
342
|
+
localization.localeCodes.includes(String(body?.locale)) &&
|
|
343
|
+
typeof body?.locale === "string"
|
|
344
|
+
? body.locale
|
|
345
|
+
: undefined;
|
|
346
|
+
const category = CATEGORIES.includes(body?.category)
|
|
347
|
+
? body?.category
|
|
348
|
+
: "necessary";
|
|
349
|
+
// As the editor: a project's own access on the services still applies.
|
|
350
|
+
const asEditor = { overrideAccess: false, user: req.user, req };
|
|
339
351
|
const existing = (await req.payload.find({
|
|
340
352
|
collection: CONSENT_SERVICES,
|
|
341
353
|
where: { name: { equals: serviceName } },
|
|
342
354
|
limit: 1,
|
|
343
355
|
depth: 0,
|
|
344
356
|
locale: locale,
|
|
345
|
-
|
|
357
|
+
...asEditor,
|
|
346
358
|
})).docs[0];
|
|
347
359
|
const entry = kind === "host"
|
|
348
360
|
? { hosts: [...(existing?.hosts ?? []), { host: name }] }
|
|
@@ -358,21 +370,21 @@ function endpoints(options) {
|
|
|
358
370
|
id: existing.id,
|
|
359
371
|
data: entry,
|
|
360
372
|
locale: locale,
|
|
361
|
-
|
|
373
|
+
...asEditor,
|
|
362
374
|
})
|
|
363
375
|
: await req.payload.create({
|
|
364
376
|
collection: CONSENT_SERVICES,
|
|
365
377
|
data: {
|
|
366
378
|
name: serviceName,
|
|
367
379
|
provider: body?.provider || undefined,
|
|
368
|
-
category
|
|
380
|
+
category,
|
|
369
381
|
purpose: body?.purpose || serviceName,
|
|
370
382
|
policyUrl: body?.policyUrl || undefined,
|
|
371
383
|
loading: "code",
|
|
372
384
|
...entry,
|
|
373
385
|
},
|
|
374
386
|
locale: locale,
|
|
375
|
-
|
|
387
|
+
...asEditor,
|
|
376
388
|
});
|
|
377
389
|
const latest = await latestDone(req);
|
|
378
390
|
if (latest) {
|
|
@@ -384,10 +396,15 @@ function endpoints(options) {
|
|
|
384
396
|
services: await allServices(req),
|
|
385
397
|
previousKeys: (previous?.findings ?? []).map((f) => f.key),
|
|
386
398
|
});
|
|
399
|
+
// Judged again against the services; what the scan could not see stays as it was.
|
|
400
|
+
const problems = latest.summary?.problems;
|
|
387
401
|
await req.payload.update({
|
|
388
402
|
collection: CONSENT_SCANS,
|
|
389
403
|
id: latest.id,
|
|
390
|
-
data: {
|
|
404
|
+
data: {
|
|
405
|
+
findings: evaluated.findings,
|
|
406
|
+
summary: { ...evaluated.summary, ...(problems?.length ? { problems } : {}) },
|
|
407
|
+
},
|
|
391
408
|
overrideAccess: true,
|
|
392
409
|
req,
|
|
393
410
|
});
|