laxy-verify 1.2.3 → 1.3.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.
@@ -1,17 +1,17 @@
1
- export interface SecurityAuditResult {
2
- totalVulnerabilities: number;
3
- critical: number;
4
- high: number;
5
- moderate: number;
6
- low: number;
7
- summary: string;
8
- missingHeaders: string[];
9
- headerCheckUrl?: string;
10
- headerCheckError?: string;
11
- }
12
- export declare function auditSecurityHeaders(url: string): Promise<{
13
- missingHeaders: string[];
14
- checkedUrl: string;
15
- error?: string;
16
- }>;
17
- export declare function runSecurityAudit(cwd: string, appUrl?: string, timeoutMs?: number): Promise<SecurityAuditResult>;
1
+ export interface SecurityAuditResult {
2
+ totalVulnerabilities: number;
3
+ critical: number;
4
+ high: number;
5
+ moderate: number;
6
+ low: number;
7
+ summary: string;
8
+ missingHeaders: string[];
9
+ headerCheckUrl?: string;
10
+ headerCheckError?: string;
11
+ }
12
+ export declare function auditSecurityHeaders(url: string): Promise<{
13
+ missingHeaders: string[];
14
+ checkedUrl: string;
15
+ error?: string;
16
+ }>;
17
+ export declare function runSecurityAudit(cwd: string, appUrl?: string, timeoutMs?: number): Promise<SecurityAuditResult>;
@@ -1,127 +1,127 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.auditSecurityHeaders = auditSecurityHeaders;
4
- exports.runSecurityAudit = runSecurityAudit;
5
- /**
6
- * npm audit wrapper plus runtime security-header checks.
7
- *
8
- * The package audit catches known dependency vulnerabilities.
9
- * The header audit adds shallow runtime coverage for common missing
10
- * browser-enforced protections on the running app.
11
- */
12
- const node_child_process_1 = require("node:child_process");
13
- async function runNpmAudit(cwd, timeoutMs) {
14
- return new Promise((resolve) => {
15
- const chunks = [];
16
- const proc = process.platform === "win32"
17
- ? (0, node_child_process_1.spawn)(process.env.ComSpec || "cmd.exe", ["/d", "/c", "npm audit --json"], {
18
- stdio: ["ignore", "pipe", "pipe"],
19
- cwd,
20
- })
21
- : (0, node_child_process_1.spawn)("npm", ["audit", "--json"], {
22
- shell: true,
23
- stdio: ["ignore", "pipe", "pipe"],
24
- cwd,
25
- });
26
- const timer = setTimeout(() => {
27
- try {
28
- proc.kill();
29
- }
30
- catch { }
31
- resolve({ totalVulnerabilities: 0, critical: 0, high: 0, moderate: 0, low: 0 });
32
- }, timeoutMs);
33
- proc.stdout?.on("data", (chunk) => chunks.push(chunk.toString()));
34
- proc.stderr?.on("data", () => { });
35
- proc.on("exit", () => {
36
- clearTimeout(timer);
37
- try {
38
- const json = JSON.parse(chunks.join(""));
39
- const meta = json.metadata?.vulnerabilities ?? json.vulnerabilities ?? {};
40
- const critical = meta.critical ?? 0;
41
- const high = meta.high ?? 0;
42
- const moderate = meta.moderate ?? 0;
43
- const low = meta.low ?? 0;
44
- resolve({
45
- totalVulnerabilities: critical + high + moderate + low,
46
- critical,
47
- high,
48
- moderate,
49
- low,
50
- });
51
- }
52
- catch {
53
- resolve({ totalVulnerabilities: 0, critical: 0, high: 0, moderate: 0, low: 0 });
54
- }
55
- });
56
- });
57
- }
58
- async function auditSecurityHeaders(url) {
59
- const requiredHeaders = ["X-Frame-Options", "Content-Security-Policy"];
60
- const urlObj = new URL(url);
61
- if (urlObj.protocol === "https:") {
62
- requiredHeaders.push("Strict-Transport-Security");
63
- }
64
- let response;
65
- try {
66
- response = await fetch(url, {
67
- method: "HEAD",
68
- redirect: "follow",
69
- signal: AbortSignal.timeout(5000),
70
- });
71
- }
72
- catch {
73
- try {
74
- response = await fetch(url, {
75
- method: "GET",
76
- redirect: "follow",
77
- signal: AbortSignal.timeout(5000),
78
- });
79
- }
80
- catch (error) {
81
- return {
82
- missingHeaders: [],
83
- checkedUrl: url,
84
- error: error instanceof Error ? error.message : String(error),
85
- };
86
- }
87
- }
88
- const missingHeaders = requiredHeaders.filter((headerName) => !response.headers.get(headerName));
89
- return {
90
- missingHeaders,
91
- checkedUrl: response.url || url,
92
- };
93
- }
94
- async function runSecurityAudit(cwd, appUrl, timeoutMs = 30000) {
95
- console.log(" Running security audit (npm audit + runtime headers)...");
96
- const [npmAudit, headerAudit] = await Promise.all([
97
- runNpmAudit(cwd, timeoutMs),
98
- appUrl ? auditSecurityHeaders(appUrl) : Promise.resolve(null),
99
- ]);
100
- const parts = [];
101
- if (npmAudit.critical > 0)
102
- parts.push(`${npmAudit.critical} critical`);
103
- if (npmAudit.high > 0)
104
- parts.push(`${npmAudit.high} high`);
105
- if (npmAudit.moderate > 0)
106
- parts.push(`${npmAudit.moderate} moderate`);
107
- if (npmAudit.low > 0)
108
- parts.push(`${npmAudit.low} low`);
109
- const missingHeaders = headerAudit?.missingHeaders ?? [];
110
- if (missingHeaders.length > 0) {
111
- parts.push(`missing headers: ${missingHeaders.join(", ")}`);
112
- }
113
- if (headerAudit?.error) {
114
- parts.push(`header check skipped: ${headerAudit.error}`);
115
- }
116
- const summary = parts.length > 0
117
- ? parts.join(" | ")
118
- : "No known vulnerabilities or missing security headers";
119
- console.log(` Security: ${summary}`);
120
- return {
121
- ...npmAudit,
122
- summary,
123
- missingHeaders,
124
- headerCheckUrl: headerAudit?.checkedUrl,
125
- headerCheckError: headerAudit?.error,
126
- };
127
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.auditSecurityHeaders = auditSecurityHeaders;
4
+ exports.runSecurityAudit = runSecurityAudit;
5
+ /**
6
+ * npm audit wrapper plus runtime security-header checks.
7
+ *
8
+ * The package audit catches known dependency vulnerabilities.
9
+ * The header audit adds shallow runtime coverage for common missing
10
+ * browser-enforced protections on the running app.
11
+ */
12
+ const node_child_process_1 = require("node:child_process");
13
+ async function runNpmAudit(cwd, timeoutMs) {
14
+ return new Promise((resolve) => {
15
+ const chunks = [];
16
+ const proc = process.platform === "win32"
17
+ ? (0, node_child_process_1.spawn)(process.env.ComSpec || "cmd.exe", ["/d", "/c", "npm audit --json"], {
18
+ stdio: ["ignore", "pipe", "pipe"],
19
+ cwd,
20
+ })
21
+ : (0, node_child_process_1.spawn)("npm", ["audit", "--json"], {
22
+ shell: true,
23
+ stdio: ["ignore", "pipe", "pipe"],
24
+ cwd,
25
+ });
26
+ const timer = setTimeout(() => {
27
+ try {
28
+ proc.kill();
29
+ }
30
+ catch { }
31
+ resolve({ totalVulnerabilities: 0, critical: 0, high: 0, moderate: 0, low: 0 });
32
+ }, timeoutMs);
33
+ proc.stdout?.on("data", (chunk) => chunks.push(chunk.toString()));
34
+ proc.stderr?.on("data", () => { });
35
+ proc.on("exit", () => {
36
+ clearTimeout(timer);
37
+ try {
38
+ const json = JSON.parse(chunks.join(""));
39
+ const meta = json.metadata?.vulnerabilities ?? json.vulnerabilities ?? {};
40
+ const critical = meta.critical ?? 0;
41
+ const high = meta.high ?? 0;
42
+ const moderate = meta.moderate ?? 0;
43
+ const low = meta.low ?? 0;
44
+ resolve({
45
+ totalVulnerabilities: critical + high + moderate + low,
46
+ critical,
47
+ high,
48
+ moderate,
49
+ low,
50
+ });
51
+ }
52
+ catch {
53
+ resolve({ totalVulnerabilities: 0, critical: 0, high: 0, moderate: 0, low: 0 });
54
+ }
55
+ });
56
+ });
57
+ }
58
+ async function auditSecurityHeaders(url) {
59
+ const requiredHeaders = ["X-Frame-Options", "Content-Security-Policy"];
60
+ const urlObj = new URL(url);
61
+ if (urlObj.protocol === "https:") {
62
+ requiredHeaders.push("Strict-Transport-Security");
63
+ }
64
+ let response;
65
+ try {
66
+ response = await fetch(url, {
67
+ method: "HEAD",
68
+ redirect: "follow",
69
+ signal: AbortSignal.timeout(5000),
70
+ });
71
+ }
72
+ catch {
73
+ try {
74
+ response = await fetch(url, {
75
+ method: "GET",
76
+ redirect: "follow",
77
+ signal: AbortSignal.timeout(5000),
78
+ });
79
+ }
80
+ catch (error) {
81
+ return {
82
+ missingHeaders: [],
83
+ checkedUrl: url,
84
+ error: error instanceof Error ? error.message : String(error),
85
+ };
86
+ }
87
+ }
88
+ const missingHeaders = requiredHeaders.filter((headerName) => !response.headers.get(headerName));
89
+ return {
90
+ missingHeaders,
91
+ checkedUrl: response.url || url,
92
+ };
93
+ }
94
+ async function runSecurityAudit(cwd, appUrl, timeoutMs = 30000) {
95
+ console.log(" Running security audit (npm audit + runtime headers)...");
96
+ const [npmAudit, headerAudit] = await Promise.all([
97
+ runNpmAudit(cwd, timeoutMs),
98
+ appUrl ? auditSecurityHeaders(appUrl) : Promise.resolve(null),
99
+ ]);
100
+ const parts = [];
101
+ if (npmAudit.critical > 0)
102
+ parts.push(`${npmAudit.critical} critical`);
103
+ if (npmAudit.high > 0)
104
+ parts.push(`${npmAudit.high} high`);
105
+ if (npmAudit.moderate > 0)
106
+ parts.push(`${npmAudit.moderate} moderate`);
107
+ if (npmAudit.low > 0)
108
+ parts.push(`${npmAudit.low} low`);
109
+ const missingHeaders = headerAudit?.missingHeaders ?? [];
110
+ if (missingHeaders.length > 0) {
111
+ parts.push(`missing headers: ${missingHeaders.join(", ")}`);
112
+ }
113
+ if (headerAudit?.error) {
114
+ parts.push(`header check skipped: ${headerAudit.error}`);
115
+ }
116
+ const summary = parts.length > 0
117
+ ? parts.join(" | ")
118
+ : "No known vulnerabilities or missing security headers";
119
+ console.log(` Security: ${summary}`);
120
+ return {
121
+ ...npmAudit,
122
+ summary,
123
+ missingHeaders,
124
+ headerCheckUrl: headerAudit?.checkedUrl,
125
+ headerCheckError: headerAudit?.error,
126
+ };
127
+ }