nuxt-csp-report 1.0.0-alpha.3 → 1.0.0
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/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRuntimeConfig, useStorage, readBody, defineEventHandler } from "#imports";
|
|
1
|
+
import { useRuntimeConfig, useStorage, readBody, defineEventHandler, setResponseStatus } from "#imports";
|
|
2
2
|
import { normalizeCspReport } from "../utils/normalizeCspReport.js";
|
|
3
3
|
import { formatCspLog } from "../utils/formatCspLog.js";
|
|
4
4
|
const runtimeConfig = useRuntimeConfig();
|
|
@@ -27,6 +27,7 @@ export default defineEventHandler(async (event) => {
|
|
|
27
27
|
return { ok: true };
|
|
28
28
|
} catch (err) {
|
|
29
29
|
console.error("[nuxt-csp-report]", err);
|
|
30
|
-
|
|
30
|
+
setResponseStatus(event, 500);
|
|
31
|
+
return { ok: false };
|
|
31
32
|
}
|
|
32
33
|
});
|
|
@@ -41,7 +41,7 @@ declare const reportToEntrySchema: z.ZodObject<{
|
|
|
41
41
|
url: z.ZodString;
|
|
42
42
|
user_agent: z.ZodString;
|
|
43
43
|
}, z.core.$loose>;
|
|
44
|
-
declare const
|
|
44
|
+
declare const _reportToSchema: z.ZodArray<z.ZodObject<{
|
|
45
45
|
age: z.ZodNumber;
|
|
46
46
|
body: z.ZodObject<{
|
|
47
47
|
blockedURL: z.ZodString;
|
|
@@ -64,6 +64,6 @@ declare const reportToSchema: z.ZodArray<z.ZodObject<{
|
|
|
64
64
|
user_agent: z.ZodString;
|
|
65
65
|
}, z.core.$loose>>;
|
|
66
66
|
export type ReportToEntryFormat = z.infer<typeof reportToEntrySchema>;
|
|
67
|
-
export type ReportToFormat = z.infer<typeof
|
|
67
|
+
export type ReportToFormat = z.infer<typeof _reportToSchema>;
|
|
68
68
|
export declare function normalizeCspReport(input: unknown): NormalizedCspReport[];
|
|
69
69
|
export {};
|
|
@@ -32,42 +32,45 @@ const reportToEntrySchema = z.object({
|
|
|
32
32
|
type: z.string(),
|
|
33
33
|
url: z.string(),
|
|
34
34
|
user_agent: z.string()
|
|
35
|
-
}).
|
|
36
|
-
const
|
|
35
|
+
}).loose();
|
|
36
|
+
const _reportToSchema = reportToEntrySchema.array();
|
|
37
37
|
export function normalizeCspReport(input) {
|
|
38
|
-
if (!input)
|
|
39
|
-
|
|
38
|
+
if (!input) return [];
|
|
39
|
+
if (typeof input === "object" && input !== null && "csp-report" in input) {
|
|
40
|
+
const parsed = reportUriSchema.safeParse(input);
|
|
41
|
+
if (!parsed.success) return [];
|
|
42
|
+
const report = parsed.data["csp-report"];
|
|
43
|
+
return [{
|
|
44
|
+
raw: parsed.data,
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
documentURL: report["document-uri"],
|
|
47
|
+
blockedURL: report["blocked-uri"],
|
|
48
|
+
directive: report["violated-directive"],
|
|
49
|
+
sourceFile: report["source-file"],
|
|
50
|
+
line: report["line-number"],
|
|
51
|
+
disposition: report["disposition"]
|
|
52
|
+
}];
|
|
40
53
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
if (Array.isArray(input)) {
|
|
55
|
+
const reports = [];
|
|
56
|
+
for (const entry of input) {
|
|
57
|
+
const parsed = reportToEntrySchema.safeParse(entry);
|
|
58
|
+
if (!parsed.success) continue;
|
|
59
|
+
if (parsed.data.type !== "csp-violation") continue;
|
|
60
|
+
const { body } = parsed.data;
|
|
61
|
+
reports.push({
|
|
62
|
+
raw: parsed.data,
|
|
46
63
|
timestamp: Date.now(),
|
|
47
|
-
documentURL:
|
|
48
|
-
blockedURL:
|
|
49
|
-
directive:
|
|
50
|
-
sourceFile:
|
|
51
|
-
line:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
if (Array.isArray(input)) {
|
|
56
|
-
const parsed = reportToSchema.parse(input);
|
|
57
|
-
return parsed.map((item) => {
|
|
58
|
-
return {
|
|
59
|
-
raw: item,
|
|
60
|
-
timestamp: Date.now(),
|
|
61
|
-
documentURL: item.body.documentURL,
|
|
62
|
-
blockedURL: item.body.blockedURL,
|
|
63
|
-
directive: item.body.effectiveDirective,
|
|
64
|
-
sourceFile: item.body.sourceFile,
|
|
65
|
-
line: item.body.lineNumber,
|
|
66
|
-
disposition: item.body.disposition
|
|
67
|
-
};
|
|
64
|
+
documentURL: body.documentURL,
|
|
65
|
+
blockedURL: body.blockedURL,
|
|
66
|
+
directive: body.effectiveDirective,
|
|
67
|
+
sourceFile: body.sourceFile,
|
|
68
|
+
line: body.lineNumber,
|
|
69
|
+
column: body.columnNumber,
|
|
70
|
+
disposition: body.disposition
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
|
-
|
|
73
|
+
return reports;
|
|
71
74
|
}
|
|
72
75
|
return [];
|
|
73
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-csp-report",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A Nuxt module for collecting, normalizing, and persisting Content Security Policy reports",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dev": "pnpm dev:prepare && nuxi dev playground",
|
|
64
64
|
"dev:build": "nuxi build playground",
|
|
65
65
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
66
|
-
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release
|
|
66
|
+
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release && pnpm publish && git push --follow-tags",
|
|
67
67
|
"lint": "eslint .",
|
|
68
68
|
"test": "vitest run",
|
|
69
69
|
"test:watch": "vitest watch",
|