Skip to content

Commit 4f306bb

Browse files
fix: major haul of lint errors
1 parent 2c29b8d commit 4f306bb

File tree

12 files changed

+263
-119
lines changed

12 files changed

+263
-119
lines changed

packages/backend/src/blacklists.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ export class BlacklistManager {
176176

177177
// Check if path matches any vulnerable paths
178178
if (
179-
path &&
179+
path !== undefined &&
180+
path.trim() !== "" &&
180181
vulnHost.paths.some((vulnPath) => path.includes(vulnPath))
181182
) {
182183
return { isVulnerable: true, risk: vulnHost.risk };
@@ -207,7 +208,7 @@ export class BlacklistManager {
207208
results.push({
208209
type: "vulnerable-js",
209210
risk:
210-
vulnCheck.risk ||
211+
vulnCheck.risk ??
211212
"Domain hosts known vulnerable JavaScript libraries",
212213
});
213214
}

packages/backend/src/bypass-database.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { readFileSync } from "fs";
55
import { dirname, join } from "path";
66
import { fileURLToPath } from "url";
77

8-
let cachedData: string | null = null;
9-
let cachedCount: number | null = null;
8+
let cachedData: string | undefined = undefined;
9+
let cachedCount: number | undefined = undefined;
1010

1111
export const getCSPBypassData = (): string => {
12-
if (cachedData === null) {
12+
if (cachedData === undefined) {
1313
try {
1414
// Read the TSV file from the project root
1515
const tsvPath = join(process.cwd(), "data", "csp-bypass-data.tsv");
@@ -36,7 +36,7 @@ export const getCSPBypassData = (): string => {
3636
);
3737
} catch (finalError) {
3838
console.error(
39-
"Failed to load TSV data from all paths: " + finalError,
39+
"Failed to load TSV data from all paths: " + String(finalError),
4040
);
4141
cachedData = "Domain\tCode\n"; // Empty TSV with header
4242
}
@@ -47,7 +47,7 @@ export const getCSPBypassData = (): string => {
4747
};
4848

4949
export const getBypassCount = (): number => {
50-
if (cachedCount === null) {
50+
if (cachedCount === undefined) {
5151
const data = getCSPBypassData();
5252
const lines = data.trim().split("\n");
5353
cachedCount = Math.max(0, lines.length - 1); // Subtract 1 for header

packages/backend/src/csp-parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class CspParser {
7777
if (parts.length === 0) continue;
7878

7979
const directiveName = parts[0]?.toLowerCase();
80-
if (!directiveName) continue;
80+
if (directiveName === undefined || directiveName.trim() === "") continue;
8181
const directiveValues = parts.slice(1);
8282

8383
const directive: CspDirective = {
@@ -187,14 +187,14 @@ export class CspParser {
187187
}
188188
}
189189

190-
static computeEffectivePolicy(policies: CspPolicy[]): CspPolicy | null {
191-
if (policies.length === 0) return null;
192-
if (policies.length === 1) return policies[0] ?? null;
190+
static computeEffectivePolicy(policies: CspPolicy[]): CspPolicy | undefined {
191+
if (policies.length === 0) return undefined;
192+
if (policies.length === 1) return policies[0] ?? undefined;
193193

194194
// For multiple policies, we need to intersect the directives
195195
// This is a simplified approach - real CSP combination is complex
196196
const firstPolicy = policies[0];
197-
if (!firstPolicy) return null;
197+
if (!firstPolicy) return undefined;
198198

199199
const effectivePolicy = { ...firstPolicy };
200200
effectivePolicy.id = generateId();

packages/backend/src/enhanced-analyzer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export class EnhancedCspAnalyzer {
282282
type: "permissive-base-uri",
283283
severity: "medium",
284284
directive: "base-uri",
285-
value: baseUri?.values.join(" ") || "missing",
285+
value: baseUri?.values.join(" ") ?? "missing",
286286
title: "Permissive Base URI Policy",
287287
description: "Unrestricted base URI can enable injection attacks",
288288
remediation: "Set base-uri to 'self' or specific trusted origins",

packages/backend/src/enhanced-blacklists.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,12 @@ export class EnhancedBlacklistManager {
361361
for (const vulnJs of ENHANCED_VULNERABLE_JS) {
362362
if (cleanDomain.includes(vulnJs.domain)) {
363363
// Check path matching if specified
364-
if (vulnJs.paths && path) {
364+
if (
365+
vulnJs.paths &&
366+
vulnJs.paths.length > 0 &&
367+
path !== undefined &&
368+
path.trim() !== ""
369+
) {
365370
const pathMatch = vulnJs.paths.some((vulnPath) =>
366371
path.includes(vulnPath),
367372
);
@@ -412,26 +417,45 @@ export class EnhancedBlacklistManager {
412417
if (supplyChain.isRisky) {
413418
threats.push({
414419
type: "supply-chain",
415-
severity: supplyChain.severity || "medium",
416-
risk: supplyChain.risk || "Supply chain risk detected",
420+
severity:
421+
supplyChain.severity !== undefined &&
422+
supplyChain.severity.trim() !== ""
423+
? supplyChain.severity
424+
: "medium",
425+
risk:
426+
supplyChain.risk !== undefined && supplyChain.risk.trim() !== ""
427+
? supplyChain.risk
428+
: "Supply chain risk detected",
417429
});
418430
}
419431

420432
const aiMl = this.checkAiMlServiceRisk(domain);
421433
if (aiMl.isRisky) {
422434
threats.push({
423435
type: "ai-ml-service",
424-
severity: aiMl.severity || "medium",
425-
risk: aiMl.risk || "AI/ML service integration risk",
436+
severity:
437+
aiMl.severity !== undefined && aiMl.severity.trim() !== ""
438+
? aiMl.severity
439+
: "medium",
440+
risk:
441+
aiMl.risk !== undefined && aiMl.risk.trim() !== ""
442+
? aiMl.risk
443+
: "AI/ML service integration risk",
426444
});
427445
}
428446

429447
const web3 = this.checkWeb3Risk(domain);
430448
if (web3.isRisky) {
431449
threats.push({
432450
type: "web3-integration",
433-
severity: web3.severity || "high",
434-
risk: web3.risk || "Web3/Cryptocurrency integration risk",
451+
severity:
452+
web3.severity !== undefined && web3.severity.trim() !== ""
453+
? web3.severity
454+
: "high",
455+
risk:
456+
web3.risk !== undefined && web3.risk.trim() !== ""
457+
? web3.risk
458+
: "Web3/Cryptocurrency integration risk",
435459
});
436460
}
437461

@@ -440,7 +464,10 @@ export class EnhancedBlacklistManager {
440464
threats.push({
441465
type: "vulnerable-js",
442466
severity: "high",
443-
risk: vulnJs.risk || "Vulnerable JavaScript library detected",
467+
risk:
468+
vulnJs.risk !== undefined && vulnJs.risk.trim() !== ""
469+
? vulnJs.risk
470+
: "Vulnerable JavaScript library detected",
444471
cve: vulnJs.cve,
445472
});
446473
}

packages/backend/src/enhanced-policy-generator.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ export class EnhancedPolicyGenerator {
2626
// Enhanced script-src with modern security
2727
let scriptSrc = "script-src 'self'";
2828

29-
if (options.useStrictDynamic) {
29+
if (options.useStrictDynamic === true) {
3030
// CSP Level 3 strict-dynamic for modern apps
3131
scriptSrc += " 'strict-dynamic'";
3232
}
3333

34-
if (options.allowInlineScripts) {
34+
if (options.allowInlineScripts === true) {
3535
// Discouraged but provide guidance
3636
scriptSrc += " 'unsafe-inline'";
3737
} else {
3838
// Recommend nonce/hash approach
3939
scriptSrc += " 'nonce-{GENERATED_NONCE}'";
4040
}
4141

42-
if (!options.allowDataUris) {
42+
if (options.allowDataUris !== true) {
4343
// Block data: URIs by default
4444
scriptSrc += " 'unsafe-eval'"; // Remove this - typo, should not add unsafe-eval when blocking data
4545
scriptSrc = scriptSrc.replace(" 'unsafe-eval'", ""); // Fix the typo
@@ -49,7 +49,7 @@ export class EnhancedPolicyGenerator {
4949

5050
// Modern style-src
5151
let styleSrc = "style-src 'self'";
52-
if (options.allowInlineStyles) {
52+
if (options.allowInlineStyles === true) {
5353
styleSrc += " 'unsafe-inline'";
5454
} else {
5555
styleSrc += " 'nonce-{GENERATED_NONCE}'";
@@ -64,7 +64,10 @@ export class EnhancedPolicyGenerator {
6464
directives.push("upgrade-insecure-requests"); // Force HTTPS
6565

6666
// CSP Level 3 features
67-
if (options.enableTrustedTypes && options.includeCsp3Features) {
67+
if (
68+
options.enableTrustedTypes === true &&
69+
options.includeCsp3Features === true
70+
) {
6871
directives.push("trusted-types default");
6972
directives.push("require-trusted-types-for 'script'");
7073
}
@@ -376,7 +379,7 @@ export class EnhancedPolicyGenerator {
376379
const parts = directive.split(/\s+/);
377380
const name = parts[0];
378381
const values = parts.slice(1);
379-
if (name) {
382+
if (name !== undefined && name.trim() !== "") {
380383
directiveMap.set(name, values);
381384
}
382385
}
@@ -396,7 +399,8 @@ export class EnhancedPolicyGenerator {
396399
}
397400

398401
// Security features (30 points total)
399-
if (directiveMap.get("object-src")?.includes("'none'")) {
402+
const objectSrc = directiveMap.get("object-src");
403+
if (objectSrc && objectSrc.includes("'none'")) {
400404
score += 10;
401405
strengths.push("Objects/plugins completely blocked");
402406
}

packages/backend/src/findings-generator.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SDK } from "caido:plugin";
2+
import type { Request, Response } from "caido:utils";
23

34
import type { CspVulnerability } from "./types";
45
import { VULNERABILITY_RULES } from "./vulnerability-rules";
@@ -8,8 +9,8 @@ export class FindingsGenerator {
89

910
static async createFinding(
1011
vulnerability: CspVulnerability,
11-
request: any, // Caido Request object
12-
response: any, // Caido Response object
12+
request: unknown, // Caido Request object
13+
response: unknown, // Caido Response object
1314
sdk: SDK,
1415
): Promise<void> {
1516
try {
@@ -19,8 +20,8 @@ export class FindingsGenerator {
1920
title: rule.title,
2021
description: this.generateDetailedDescription(vulnerability, rule),
2122
reporter: this.REPORTER_NAME,
22-
request: request,
23-
response: response,
23+
request: request as Request,
24+
response: response as Response,
2425
severity: this.mapSeverityToCaido(vulnerability.severity),
2526
};
2627

@@ -37,15 +38,16 @@ export class FindingsGenerator {
3738

3839
static async createMultipleFindings(
3940
vulnerabilities: CspVulnerability[],
40-
request: any,
41-
response: any,
41+
request: unknown,
42+
response: unknown,
4243
sdk: SDK,
4344
): Promise<void> {
4445
const promises = vulnerabilities.map((vuln) =>
4546
this.createFinding(vuln, request, response, sdk),
4647
);
4748

4849
try {
50+
// eslint-disable-next-line compat/compat
4951
await Promise.all(promises);
5052
sdk.console.log(`Created ${vulnerabilities.length} CSP findings`);
5153
} catch (error) {
@@ -73,7 +75,7 @@ export class FindingsGenerator {
7375
];
7476

7577
// Add CWE information if available
76-
if (rule.cweId) {
78+
if (typeof rule.cweId === "number" && rule.cweId > 0) {
7779
sections.push(
7880
`<h3>References</h3>`,
7981
`<p><strong>CWE:</strong> <a href="https://cwe.mitre.org/data/definitions/${rule.cweId}.html">CWE-${rule.cweId}</a></p>`,
@@ -232,10 +234,10 @@ export class FindingsGenerator {
232234
return grouped;
233235
}
234236

235-
static async cleanupOldFindings(
237+
static cleanupOldFindings(
236238
sdk: SDK,
237239
maxAge: number = 24 * 60 * 60 * 1000,
238-
): Promise<void> {
240+
): void {
239241
// This would need to be implemented based on Caido's findings API
240242
// For now, we'll just log the intent
241243
sdk.console.log(`Would cleanup CSP findings older than ${maxAge}ms`);

0 commit comments

Comments
 (0)