@sentriflow/cli 0.10.0 → 0.11.0-rc.1
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/README.md +5 -5
- package/dist/index.js +906 -486
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -8244,11 +8244,12 @@ var getManagementApiNodes = (ast) => {
|
|
|
8244
8244
|
};
|
|
8245
8245
|
var hasHttpsTransport = (apiNode) => {
|
|
8246
8246
|
if (!apiNode?.children) return false;
|
|
8247
|
+
const enabled = (child) => !!child?.id && !/^no\s/i.test(child.id.trim());
|
|
8247
8248
|
const hasProtocolHttps = apiNode.children.some(
|
|
8248
|
-
(child) => child
|
|
8249
|
+
(child) => enabled(child) && includesIgnoreCase(child.id, "protocol https")
|
|
8249
8250
|
);
|
|
8250
8251
|
const hasTransportHttps = apiNode.children.some(
|
|
8251
|
-
(child) => child
|
|
8252
|
+
(child) => enabled(child) && includesIgnoreCase(child.id, "transport https")
|
|
8252
8253
|
);
|
|
8253
8254
|
return hasProtocolHttps || hasTransportHttps;
|
|
8254
8255
|
};
|
|
@@ -16238,484 +16239,19 @@ function applySuppressions(results, options) {
|
|
|
16238
16239
|
return { kept, suppressed };
|
|
16239
16240
|
}
|
|
16240
16241
|
|
|
16242
|
+
// ../core/src/ruleDocs.ts
|
|
16243
|
+
var RULE_DOCS_BASE = "https://www.sentriflow.com.au/rules/";
|
|
16244
|
+
var BUILT_IN_RULE_ID = /^[A-Z0-9][A-Z0-9-]*$/;
|
|
16245
|
+
function ruleDocsUrl(ruleId) {
|
|
16246
|
+
return BUILT_IN_RULE_ID.test(ruleId) ? `${RULE_DOCS_BASE}${ruleId}/` : void 0;
|
|
16247
|
+
}
|
|
16248
|
+
|
|
16241
16249
|
// index.ts
|
|
16242
16250
|
import { readFile as readFile2 } from "fs/promises";
|
|
16243
16251
|
import { statSync as statSync4 } from "fs";
|
|
16244
16252
|
import { basename as basename2 } from "path";
|
|
16245
16253
|
import { isMainThread, parentPort, workerData } from "worker_threads";
|
|
16246
16254
|
|
|
16247
|
-
// src/sarif.ts
|
|
16248
|
-
import { relative } from "path";
|
|
16249
|
-
import { createHash } from "crypto";
|
|
16250
|
-
|
|
16251
|
-
// src/cliOptions.ts
|
|
16252
|
-
import { readFileSync } from "fs";
|
|
16253
|
-
var FAIL_ON_LEVELS = ["error", "warning", "info", "never"];
|
|
16254
|
-
var SEVERITY_RANK = {
|
|
16255
|
-
info: 0,
|
|
16256
|
-
warning: 1,
|
|
16257
|
-
error: 2
|
|
16258
|
-
};
|
|
16259
|
-
function parseFailOn(value) {
|
|
16260
|
-
const v = value.trim().toLowerCase();
|
|
16261
|
-
const match = FAIL_ON_LEVELS.find((l) => l === v);
|
|
16262
|
-
if (!match) {
|
|
16263
|
-
throw new Error(
|
|
16264
|
-
`Invalid --fail-on value '${value}'. Expected one of: ${FAIL_ON_LEVELS.join(", ")}`
|
|
16265
|
-
);
|
|
16266
|
-
}
|
|
16267
|
-
return match;
|
|
16268
|
-
}
|
|
16269
|
-
var OUTPUT_FORMATS = ["json", "human", "sarif"];
|
|
16270
|
-
function parseFormat(value) {
|
|
16271
|
-
const v = value.trim().toLowerCase();
|
|
16272
|
-
const match = OUTPUT_FORMATS.find((f) => f === v);
|
|
16273
|
-
if (!match) {
|
|
16274
|
-
throw new Error(
|
|
16275
|
-
`Invalid --format value '${value}'. Expected one of: ${OUTPUT_FORMATS.join(", ")}`
|
|
16276
|
-
);
|
|
16277
|
-
}
|
|
16278
|
-
return match;
|
|
16279
|
-
}
|
|
16280
|
-
var LIST_FORMATS = ["table", "json", "csv"];
|
|
16281
|
-
function parseListFormat(value) {
|
|
16282
|
-
const v = value.trim().toLowerCase();
|
|
16283
|
-
const match = LIST_FORMATS.find((f) => f === v);
|
|
16284
|
-
if (!match) {
|
|
16285
|
-
throw new Error(
|
|
16286
|
-
`Invalid --list-format value '${value}'. Expected one of: ${LIST_FORMATS.join(", ")}`
|
|
16287
|
-
);
|
|
16288
|
-
}
|
|
16289
|
-
return match;
|
|
16290
|
-
}
|
|
16291
|
-
function shouldFail(results, threshold) {
|
|
16292
|
-
if (threshold === "never") return false;
|
|
16293
|
-
const min = SEVERITY_RANK[threshold];
|
|
16294
|
-
return results.some((r) => !r.passed && SEVERITY_RANK[r.level] >= min);
|
|
16295
|
-
}
|
|
16296
|
-
function normalizeExtensions(value) {
|
|
16297
|
-
return value.split(",").map((e) => e.trim().replace(/^\.+/, "").toLowerCase()).filter((e) => e.length > 0);
|
|
16298
|
-
}
|
|
16299
|
-
function resolveVersion(injected) {
|
|
16300
|
-
if (injected !== void 0) return injected;
|
|
16301
|
-
try {
|
|
16302
|
-
const pkg = JSON.parse(
|
|
16303
|
-
readFileSync(new URL("../package.json", import.meta.url), "utf-8")
|
|
16304
|
-
);
|
|
16305
|
-
if (pkg && typeof pkg === "object" && "version" in pkg && typeof pkg.version === "string") {
|
|
16306
|
-
return pkg.version;
|
|
16307
|
-
}
|
|
16308
|
-
} catch {
|
|
16309
|
-
}
|
|
16310
|
-
return "unknown";
|
|
16311
|
-
}
|
|
16312
|
-
|
|
16313
|
-
// src/sarif.ts
|
|
16314
|
-
var TOOL_VERSION = resolveVersion(
|
|
16315
|
-
true ? "0.10.0" : void 0
|
|
16316
|
-
);
|
|
16317
|
-
var CWE_GUID = "1A0F2A4E-3B93-4C4E-8CC7-9A4E3A5B9A3A";
|
|
16318
|
-
function cweNumber(cweId) {
|
|
16319
|
-
return cweId.replace(/^cwe-/i, "").trim();
|
|
16320
|
-
}
|
|
16321
|
-
var LEVEL_SECURITY_SEVERITY = {
|
|
16322
|
-
error: "8.0",
|
|
16323
|
-
warning: "5.0",
|
|
16324
|
-
info: "2.0"
|
|
16325
|
-
};
|
|
16326
|
-
function securitySeverity(rule) {
|
|
16327
|
-
const sec = rule.metadata.security;
|
|
16328
|
-
if (sec?.cvssScore !== void 0) return String(sec.cvssScore);
|
|
16329
|
-
if (sec?.cwe && sec.cwe.length > 0) return LEVEL_SECURITY_SEVERITY[rule.metadata.level];
|
|
16330
|
-
return void 0;
|
|
16331
|
-
}
|
|
16332
|
-
function toUri(filePath, options) {
|
|
16333
|
-
return options.relativePaths ? relative(options.baseDir ?? process.cwd(), filePath) : filePath;
|
|
16334
|
-
}
|
|
16335
|
-
function fingerprintPath(filePath, options) {
|
|
16336
|
-
if (filePath.startsWith("<")) return filePath;
|
|
16337
|
-
return relative(options.baseDir ?? process.cwd(), filePath).replace(
|
|
16338
|
-
/\\/g,
|
|
16339
|
-
"/"
|
|
16340
|
-
);
|
|
16341
|
-
}
|
|
16342
|
-
function normaliseText(text) {
|
|
16343
|
-
return text.trim().replace(/\s+/g, " ");
|
|
16344
|
-
}
|
|
16345
|
-
function fingerprintLine(lineText, nodeId) {
|
|
16346
|
-
const line = normaliseText(maskSecretWords(lineText));
|
|
16347
|
-
const at2 = nodeId.indexOf(SECRET_MASK);
|
|
16348
|
-
if (at2 < 0 || line.includes(SECRET_MASK)) return line;
|
|
16349
|
-
const shown2 = normaliseText(nodeId.slice(0, at2));
|
|
16350
|
-
if (shown2 === "" || !line.startsWith(shown2)) return line;
|
|
16351
|
-
const snmp = normaliseText(maskSecretWords(lineText, { snmp: true }));
|
|
16352
|
-
return snmp.includes(SECRET_MASK) ? snmp : `${shown2} ${SECRET_MASK}`;
|
|
16353
|
-
}
|
|
16354
|
-
function normaliseMessage(message) {
|
|
16355
|
-
return normaliseText(message).replace(/\d+/g, "#");
|
|
16356
|
-
}
|
|
16357
|
-
function buildSarifResults(results, filePath, sourceText, ruleIndexById, options, suppressed = []) {
|
|
16358
|
-
const uri = toUri(filePath, options);
|
|
16359
|
-
const fpPath = fingerprintPath(filePath, options);
|
|
16360
|
-
const lines = sourceText?.split(/\r\n|\r|\n/);
|
|
16361
|
-
const occurrences = /* @__PURE__ */ new Map();
|
|
16362
|
-
const items = [
|
|
16363
|
-
...results.filter((result2) => options.includePassed || !result2.passed).map((result2) => ({ result: result2 })),
|
|
16364
|
-
...suppressed
|
|
16365
|
-
];
|
|
16366
|
-
const hashes = items.map(({ result: result2 }) => {
|
|
16367
|
-
const lineText = result2.loc ? lines?.[result2.loc.startLine] : void 0;
|
|
16368
|
-
const where = result2.absent ? "" : lineText !== void 0 && lineText.trim() !== "" ? fingerprintLine(lineText, result2.nodeId) : normaliseText(result2.nodeId);
|
|
16369
|
-
return createHash("sha256").update(`${result2.ruleId}
|
|
16370
|
-
${normaliseMessage(result2.message)}
|
|
16371
|
-
${where}
|
|
16372
|
-
${fpPath}`).digest("hex").slice(0, 32);
|
|
16373
|
-
});
|
|
16374
|
-
const occurrenceOf = new Array(items.length).fill(1);
|
|
16375
|
-
const byLine = items.map((item, i) => ({ i, line: item.result.loc?.startLine ?? Number.POSITIVE_INFINITY })).sort((a, b) => a.line - b.line || a.i - b.i);
|
|
16376
|
-
for (const { i } of byLine) {
|
|
16377
|
-
const hash = hashes[i] ?? "";
|
|
16378
|
-
const occurrence = (occurrences.get(hash) ?? 0) + 1;
|
|
16379
|
-
occurrences.set(hash, occurrence);
|
|
16380
|
-
occurrenceOf[i] = occurrence;
|
|
16381
|
-
}
|
|
16382
|
-
return items.map(({ result: result2, suppression }, i) => {
|
|
16383
|
-
const hash = hashes[i] ?? "";
|
|
16384
|
-
const occurrence = occurrenceOf[i] ?? 1;
|
|
16385
|
-
const ruleIndex = ruleIndexById.get(result2.ruleId);
|
|
16386
|
-
return {
|
|
16387
|
-
ruleId: result2.ruleId,
|
|
16388
|
-
...ruleIndex !== void 0 && { ruleIndex },
|
|
16389
|
-
...result2.passed && { kind: "pass" },
|
|
16390
|
-
level: result2.level === "info" ? "note" : result2.level,
|
|
16391
|
-
message: {
|
|
16392
|
-
text: result2.message
|
|
16393
|
-
},
|
|
16394
|
-
locations: result2.loc ? [
|
|
16395
|
-
{
|
|
16396
|
-
physicalLocation: {
|
|
16397
|
-
artifactLocation: { uri },
|
|
16398
|
-
region: {
|
|
16399
|
-
startLine: result2.loc.startLine + 1,
|
|
16400
|
-
// SARIF is 1-based
|
|
16401
|
-
endLine: result2.loc.endLine + 1
|
|
16402
|
-
}
|
|
16403
|
-
}
|
|
16404
|
-
}
|
|
16405
|
-
] : [],
|
|
16406
|
-
partialFingerprints: {
|
|
16407
|
-
primaryLocationLineHash: `${hash}:${occurrence}`
|
|
16408
|
-
},
|
|
16409
|
-
...suppression && {
|
|
16410
|
-
suppressions: [
|
|
16411
|
-
{
|
|
16412
|
-
kind: suppression.kind,
|
|
16413
|
-
status: "accepted",
|
|
16414
|
-
justification: suppression.justification
|
|
16415
|
-
}
|
|
16416
|
-
]
|
|
16417
|
-
}
|
|
16418
|
-
};
|
|
16419
|
-
});
|
|
16420
|
-
}
|
|
16421
|
-
function buildRulesAndTaxonomy(rules) {
|
|
16422
|
-
const cweIds = /* @__PURE__ */ new Set();
|
|
16423
|
-
const sarifRules = rules?.map((rule) => {
|
|
16424
|
-
const base = {
|
|
16425
|
-
id: rule.id,
|
|
16426
|
-
name: rule.id,
|
|
16427
|
-
shortDescription: { text: rule.metadata.remediation ?? rule.id },
|
|
16428
|
-
defaultConfiguration: {
|
|
16429
|
-
level: rule.metadata.level === "info" ? "note" : rule.metadata.level
|
|
16430
|
-
}
|
|
16431
|
-
};
|
|
16432
|
-
const secMeta = rule.metadata.security;
|
|
16433
|
-
if (secMeta?.cwe && secMeta.cwe.length > 0) {
|
|
16434
|
-
base.relationships = secMeta.cwe.map((cweId) => {
|
|
16435
|
-
const id = cweNumber(cweId);
|
|
16436
|
-
cweIds.add(id);
|
|
16437
|
-
return {
|
|
16438
|
-
target: { id, toolComponent: { name: "CWE" } },
|
|
16439
|
-
kinds: ["relevant"]
|
|
16440
|
-
};
|
|
16441
|
-
});
|
|
16442
|
-
}
|
|
16443
|
-
const severity = securitySeverity(rule);
|
|
16444
|
-
const hasTags = rule.metadata.tags && rule.metadata.tags.length > 0;
|
|
16445
|
-
const hasCategory = rule.category !== void 0;
|
|
16446
|
-
if (severity !== void 0 || secMeta?.cvssVector || hasTags || hasCategory) {
|
|
16447
|
-
base.properties = {};
|
|
16448
|
-
if (hasCategory) {
|
|
16449
|
-
base.properties.category = rule.category;
|
|
16450
|
-
}
|
|
16451
|
-
if (severity !== void 0) {
|
|
16452
|
-
base.properties["security-severity"] = severity;
|
|
16453
|
-
}
|
|
16454
|
-
if (secMeta?.cvssVector) {
|
|
16455
|
-
base.properties["cvss-vector"] = secMeta.cvssVector;
|
|
16456
|
-
}
|
|
16457
|
-
if (hasTags) {
|
|
16458
|
-
base.properties.tags = rule.metadata.tags.map((t) => t.label);
|
|
16459
|
-
}
|
|
16460
|
-
}
|
|
16461
|
-
return base;
|
|
16462
|
-
}) ?? [];
|
|
16463
|
-
const ruleIndexById = /* @__PURE__ */ new Map();
|
|
16464
|
-
sarifRules.forEach((r, i) => {
|
|
16465
|
-
if (!ruleIndexById.has(r.id)) ruleIndexById.set(r.id, i);
|
|
16466
|
-
});
|
|
16467
|
-
const hasCwe = cweIds.size > 0;
|
|
16468
|
-
const cweTaxonomy = hasCwe ? {
|
|
16469
|
-
name: "CWE",
|
|
16470
|
-
version: "4.13",
|
|
16471
|
-
guid: CWE_GUID,
|
|
16472
|
-
informationUri: "https://cwe.mitre.org/",
|
|
16473
|
-
organization: "MITRE",
|
|
16474
|
-
shortDescription: { text: "Common Weakness Enumeration" },
|
|
16475
|
-
taxa: [...cweIds].sort((a, b) => Number(a) - Number(b) || a.localeCompare(b)).map((id) => ({ id, name: `CWE-${id}` }))
|
|
16476
|
-
} : void 0;
|
|
16477
|
-
const supportedTaxonomies = hasCwe ? [{ name: "CWE", index: 0, guid: CWE_GUID }] : void 0;
|
|
16478
|
-
return { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies };
|
|
16479
|
-
}
|
|
16480
|
-
function buildSarif(results, filePath, rules, options = {}, ipSummary) {
|
|
16481
|
-
const { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies } = buildRulesAndTaxonomy(rules);
|
|
16482
|
-
const sarifResults = buildSarifResults(
|
|
16483
|
-
results,
|
|
16484
|
-
filePath,
|
|
16485
|
-
options.sourceText,
|
|
16486
|
-
ruleIndexById,
|
|
16487
|
-
options,
|
|
16488
|
-
options.suppressed
|
|
16489
|
-
);
|
|
16490
|
-
const report = {
|
|
16491
|
-
version: "2.1.0",
|
|
16492
|
-
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
16493
|
-
runs: [
|
|
16494
|
-
{
|
|
16495
|
-
tool: {
|
|
16496
|
-
driver: {
|
|
16497
|
-
name: "Sentriflow",
|
|
16498
|
-
version: TOOL_VERSION,
|
|
16499
|
-
informationUri: "https://github.com/sentriflow/sentriflow",
|
|
16500
|
-
rules: sarifRules,
|
|
16501
|
-
...supportedTaxonomies && { supportedTaxonomies }
|
|
16502
|
-
}
|
|
16503
|
-
},
|
|
16504
|
-
...cweTaxonomy && { taxonomies: [cweTaxonomy] },
|
|
16505
|
-
results: sarifResults,
|
|
16506
|
-
// Include IP summary in properties if available
|
|
16507
|
-
...ipSummary && {
|
|
16508
|
-
properties: {
|
|
16509
|
-
ipSummary
|
|
16510
|
-
}
|
|
16511
|
-
}
|
|
16512
|
-
}
|
|
16513
|
-
]
|
|
16514
|
-
};
|
|
16515
|
-
return report;
|
|
16516
|
-
}
|
|
16517
|
-
function aggregateIPSummaries(summaries) {
|
|
16518
|
-
if (summaries.length === 0) return void 0;
|
|
16519
|
-
const ipv4Set = /* @__PURE__ */ new Set();
|
|
16520
|
-
const ipv6Set = /* @__PURE__ */ new Set();
|
|
16521
|
-
const ipv4SubnetSet = /* @__PURE__ */ new Set();
|
|
16522
|
-
const ipv6SubnetSet = /* @__PURE__ */ new Set();
|
|
16523
|
-
for (const summary of summaries) {
|
|
16524
|
-
for (const ip of summary.ipv4Addresses) ipv4Set.add(ip);
|
|
16525
|
-
for (const ip of summary.ipv6Addresses) ipv6Set.add(ip);
|
|
16526
|
-
for (const subnet of summary.ipv4Subnets) ipv4SubnetSet.add(subnet);
|
|
16527
|
-
for (const subnet of summary.ipv6Subnets) ipv6SubnetSet.add(subnet);
|
|
16528
|
-
}
|
|
16529
|
-
const ipv4Addresses = [...ipv4Set].sort((a, b) => {
|
|
16530
|
-
const aParts = a.split(".").map(Number);
|
|
16531
|
-
const bParts = b.split(".").map(Number);
|
|
16532
|
-
for (let i = 0; i < 4; i++) {
|
|
16533
|
-
if ((aParts[i] ?? 0) !== (bParts[i] ?? 0)) {
|
|
16534
|
-
return (aParts[i] ?? 0) - (bParts[i] ?? 0);
|
|
16535
|
-
}
|
|
16536
|
-
}
|
|
16537
|
-
return 0;
|
|
16538
|
-
});
|
|
16539
|
-
const ipv6Addresses = [...ipv6Set].sort();
|
|
16540
|
-
const ipv4Subnets = [...ipv4SubnetSet].sort();
|
|
16541
|
-
const ipv6Subnets = [...ipv6SubnetSet].sort();
|
|
16542
|
-
return {
|
|
16543
|
-
ipv4Addresses,
|
|
16544
|
-
ipv6Addresses,
|
|
16545
|
-
ipv4Subnets,
|
|
16546
|
-
ipv6Subnets,
|
|
16547
|
-
counts: {
|
|
16548
|
-
ipv4: ipv4Addresses.length,
|
|
16549
|
-
ipv6: ipv6Addresses.length,
|
|
16550
|
-
ipv4Subnets: ipv4Subnets.length,
|
|
16551
|
-
ipv6Subnets: ipv6Subnets.length,
|
|
16552
|
-
total: ipv4Addresses.length + ipv6Addresses.length + ipv4Subnets.length + ipv6Subnets.length
|
|
16553
|
-
}
|
|
16554
|
-
};
|
|
16555
|
-
}
|
|
16556
|
-
function buildMultiFileSarif(fileResults, rules, options = {}) {
|
|
16557
|
-
const aggregatedIpSummary = aggregateIPSummaries(
|
|
16558
|
-
fileResults.map((fr) => fr.ipSummary).filter((s) => !!s)
|
|
16559
|
-
);
|
|
16560
|
-
const { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies } = buildRulesAndTaxonomy(rules);
|
|
16561
|
-
const allSarifResults = fileResults.flatMap(
|
|
16562
|
-
({ filePath, results, content, suppressed }) => buildSarifResults(results, filePath, content, ruleIndexById, options, suppressed)
|
|
16563
|
-
);
|
|
16564
|
-
const skippedNotifications = fileResults.filter((fr) => fr.skipped).map((fr) => ({
|
|
16565
|
-
level: "error",
|
|
16566
|
-
message: {
|
|
16567
|
-
text: `Skipped ${options.relativePaths ? relative(options.baseDir ?? process.cwd(), fr.filePath) : fr.filePath}: ${fr.skipped?.reason ?? "not scanned"}. Re-run with --vendor <vendor>.`
|
|
16568
|
-
}
|
|
16569
|
-
}));
|
|
16570
|
-
const artifactUris = [
|
|
16571
|
-
...new Set(
|
|
16572
|
-
fileResults.map(
|
|
16573
|
-
({ filePath }) => options.relativePaths ? relative(options.baseDir ?? process.cwd(), filePath) : filePath
|
|
16574
|
-
)
|
|
16575
|
-
)
|
|
16576
|
-
];
|
|
16577
|
-
const report = {
|
|
16578
|
-
version: "2.1.0",
|
|
16579
|
-
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
16580
|
-
runs: [
|
|
16581
|
-
{
|
|
16582
|
-
tool: {
|
|
16583
|
-
driver: {
|
|
16584
|
-
name: "Sentriflow",
|
|
16585
|
-
version: TOOL_VERSION,
|
|
16586
|
-
informationUri: "https://github.com/sentriflow/sentriflow",
|
|
16587
|
-
rules: sarifRules,
|
|
16588
|
-
...supportedTaxonomies && { supportedTaxonomies }
|
|
16589
|
-
}
|
|
16590
|
-
},
|
|
16591
|
-
// Include artifacts array for multi-file reports
|
|
16592
|
-
artifacts: artifactUris.map((uri) => ({
|
|
16593
|
-
location: { uri }
|
|
16594
|
-
})),
|
|
16595
|
-
...cweTaxonomy && { taxonomies: [cweTaxonomy] },
|
|
16596
|
-
results: allSarifResults,
|
|
16597
|
-
...skippedNotifications.length > 0 && {
|
|
16598
|
-
invocations: [
|
|
16599
|
-
{
|
|
16600
|
-
executionSuccessful: false,
|
|
16601
|
-
toolExecutionNotifications: skippedNotifications
|
|
16602
|
-
}
|
|
16603
|
-
]
|
|
16604
|
-
},
|
|
16605
|
-
// Include aggregated IP summary in properties if available
|
|
16606
|
-
...aggregatedIpSummary && {
|
|
16607
|
-
properties: {
|
|
16608
|
-
ipSummary: aggregatedIpSummary
|
|
16609
|
-
}
|
|
16610
|
-
}
|
|
16611
|
-
}
|
|
16612
|
-
]
|
|
16613
|
-
};
|
|
16614
|
-
return report;
|
|
16615
|
-
}
|
|
16616
|
-
|
|
16617
|
-
// src/human.ts
|
|
16618
|
-
var COLORS = {
|
|
16619
|
-
red: "\x1B[31m",
|
|
16620
|
-
yellow: "\x1B[33m",
|
|
16621
|
-
blue: "\x1B[34m",
|
|
16622
|
-
gray: "\x1B[90m",
|
|
16623
|
-
bold: "\x1B[1m",
|
|
16624
|
-
reset: "\x1B[0m"
|
|
16625
|
-
};
|
|
16626
|
-
var SEVERITY_COLORS = {
|
|
16627
|
-
error: COLORS.red,
|
|
16628
|
-
warning: COLORS.yellow,
|
|
16629
|
-
info: COLORS.blue
|
|
16630
|
-
};
|
|
16631
|
-
function countSeverities(results) {
|
|
16632
|
-
const counts = { error: 0, warning: 0, info: 0, total: 0 };
|
|
16633
|
-
for (const r of results) {
|
|
16634
|
-
if (!r.passed) {
|
|
16635
|
-
if (r.level === "error" || r.level === "warning" || r.level === "info") {
|
|
16636
|
-
counts[r.level]++;
|
|
16637
|
-
}
|
|
16638
|
-
counts.total++;
|
|
16639
|
-
}
|
|
16640
|
-
}
|
|
16641
|
-
return counts;
|
|
16642
|
-
}
|
|
16643
|
-
function formatFinding(result2, color) {
|
|
16644
|
-
const line = result2.loc ? result2.loc.startLine + 1 : 0;
|
|
16645
|
-
const col = 1;
|
|
16646
|
-
const location = `${line}:${col}`.padEnd(8);
|
|
16647
|
-
const severityColor = color ? SEVERITY_COLORS[result2.level] ?? "" : "";
|
|
16648
|
-
const reset = color ? COLORS.reset : "";
|
|
16649
|
-
const severityText = result2.level.padEnd(7);
|
|
16650
|
-
const severity = `${severityColor}${severityText}${reset}`;
|
|
16651
|
-
const ruleColor = color ? COLORS.gray : "";
|
|
16652
|
-
const ruleId = `${ruleColor}${result2.ruleId}${reset}`;
|
|
16653
|
-
return ` ${location} ${severity} ${result2.message} ${ruleId}`;
|
|
16654
|
-
}
|
|
16655
|
-
function formatSummary(counts, color) {
|
|
16656
|
-
if (counts.total === 0) {
|
|
16657
|
-
const check = color ? `${COLORS.bold}\u2714${COLORS.reset}` : "\u2714";
|
|
16658
|
-
return `
|
|
16659
|
-
${check} No problems found
|
|
16660
|
-
`;
|
|
16661
|
-
}
|
|
16662
|
-
const x = color ? `${COLORS.red}\u2716${COLORS.reset}` : "\u2716";
|
|
16663
|
-
const parts = [];
|
|
16664
|
-
if (counts.error > 0) {
|
|
16665
|
-
parts.push(`${counts.error} error${counts.error !== 1 ? "s" : ""}`);
|
|
16666
|
-
}
|
|
16667
|
-
if (counts.warning > 0) {
|
|
16668
|
-
parts.push(`${counts.warning} warning${counts.warning !== 1 ? "s" : ""}`);
|
|
16669
|
-
}
|
|
16670
|
-
if (counts.info > 0) {
|
|
16671
|
-
parts.push(`${counts.info} info`);
|
|
16672
|
-
}
|
|
16673
|
-
const problemText = counts.total === 1 ? "problem" : "problems";
|
|
16674
|
-
return `
|
|
16675
|
-
${x} ${counts.total} ${problemText} (${parts.join(", ")})
|
|
16676
|
-
`;
|
|
16677
|
-
}
|
|
16678
|
-
function formatHuman(results, filePath, options) {
|
|
16679
|
-
const color = options?.color ?? false;
|
|
16680
|
-
const failures = results.filter((r) => !r.passed);
|
|
16681
|
-
const lines = [];
|
|
16682
|
-
const header = color ? `${COLORS.bold}${filePath}${COLORS.reset}` : filePath;
|
|
16683
|
-
lines.push(header);
|
|
16684
|
-
for (const result2 of failures) {
|
|
16685
|
-
lines.push(formatFinding(result2, color));
|
|
16686
|
-
}
|
|
16687
|
-
const counts = countSeverities(results);
|
|
16688
|
-
lines.push(formatSummary(counts, color));
|
|
16689
|
-
return lines.join("\n");
|
|
16690
|
-
}
|
|
16691
|
-
function formatMultiFileHuman(files, options) {
|
|
16692
|
-
const color = options?.color ?? false;
|
|
16693
|
-
const lines = [];
|
|
16694
|
-
const totalCounts = { error: 0, warning: 0, info: 0, total: 0 };
|
|
16695
|
-
for (const { file, results } of files) {
|
|
16696
|
-
const failures = results.filter((r) => !r.passed);
|
|
16697
|
-
if (failures.length === 0) continue;
|
|
16698
|
-
const header = color ? `${COLORS.bold}${file}${COLORS.reset}` : file;
|
|
16699
|
-
lines.push(header);
|
|
16700
|
-
for (const result2 of failures) {
|
|
16701
|
-
lines.push(formatFinding(result2, color));
|
|
16702
|
-
}
|
|
16703
|
-
lines.push("");
|
|
16704
|
-
const counts = countSeverities(results);
|
|
16705
|
-
totalCounts.error += counts.error;
|
|
16706
|
-
totalCounts.warning += counts.warning;
|
|
16707
|
-
totalCounts.info += counts.info;
|
|
16708
|
-
totalCounts.total += counts.total;
|
|
16709
|
-
}
|
|
16710
|
-
lines.push(formatSummary(totalCounts, color));
|
|
16711
|
-
return lines.join("\n");
|
|
16712
|
-
}
|
|
16713
|
-
|
|
16714
|
-
// src/parseWarnings.ts
|
|
16715
|
-
function formatParseWarnings(warnings, source) {
|
|
16716
|
-
return warnings.map((warning) => `Warning: ${source}: ${warning.message}`);
|
|
16717
|
-
}
|
|
16718
|
-
|
|
16719
16255
|
// ../rules-default/src/common/network-rules.ts
|
|
16720
16256
|
var isContiguousMask = (mask) => mask !== null && ((~mask >>> 0) + 1 & ~mask >>> 0) === 0;
|
|
16721
16257
|
var NoMulticastBroadcastIp = {
|
|
@@ -17426,7 +16962,7 @@ var VtyNoTelnet = {
|
|
|
17426
16962
|
ruleId: "NET-MGMT-001",
|
|
17427
16963
|
nodeId: node.id,
|
|
17428
16964
|
level: "error",
|
|
17429
|
-
loc:
|
|
16965
|
+
loc: transportCmd.loc
|
|
17430
16966
|
};
|
|
17431
16967
|
}
|
|
17432
16968
|
if (!includesIgnoreCase(transportText, "ssh")) {
|
|
@@ -17436,7 +16972,7 @@ var VtyNoTelnet = {
|
|
|
17436
16972
|
ruleId: "NET-MGMT-001",
|
|
17437
16973
|
nodeId: node.id,
|
|
17438
16974
|
level: "error",
|
|
17439
|
-
loc:
|
|
16975
|
+
loc: transportCmd.loc
|
|
17440
16976
|
};
|
|
17441
16977
|
}
|
|
17442
16978
|
return { passed: true, message: "VTY configured for SSH only.", ruleId: "NET-MGMT-001", nodeId: node.id, level: "info", loc: node.loc };
|
|
@@ -18770,6 +18306,82 @@ var CiscoNoDirectedBroadcast = {
|
|
|
18770
18306
|
return passResult("CISCO-DATA-005", node, "Directed broadcast is disabled (default).");
|
|
18771
18307
|
}
|
|
18772
18308
|
};
|
|
18309
|
+
var CiscoSnmpNoDefaultCommunity = {
|
|
18310
|
+
id: "CISCO-SNMP-001",
|
|
18311
|
+
selector: "snmp-server community",
|
|
18312
|
+
vendor: "cisco-ios",
|
|
18313
|
+
category: "Protocol-Security",
|
|
18314
|
+
metadata: {
|
|
18315
|
+
level: "error",
|
|
18316
|
+
obu: "Security",
|
|
18317
|
+
owner: "SecOps",
|
|
18318
|
+
remediation: "Use complex, non-default SNMP community strings. Preferably migrate to SNMPv3.",
|
|
18319
|
+
security: {
|
|
18320
|
+
cwe: ["CWE-798"],
|
|
18321
|
+
cvssScore: 9.8
|
|
18322
|
+
},
|
|
18323
|
+
tags: [
|
|
18324
|
+
{ type: "general", label: "snmp" },
|
|
18325
|
+
{ type: "general", label: "default-credentials" }
|
|
18326
|
+
]
|
|
18327
|
+
},
|
|
18328
|
+
check: (node) => {
|
|
18329
|
+
const community = node.params[2]?.toLowerCase();
|
|
18330
|
+
if (community && community !== "public" && community !== "private" && isDefaultSnmpCommunity(community)) {
|
|
18331
|
+
return {
|
|
18332
|
+
passed: false,
|
|
18333
|
+
message: `Default SNMP community string "${community}" detected. Use a complex string or migrate to SNMPv3.`,
|
|
18334
|
+
ruleId: "CISCO-SNMP-001",
|
|
18335
|
+
nodeId: node.id,
|
|
18336
|
+
level: "error",
|
|
18337
|
+
loc: node.loc
|
|
18338
|
+
};
|
|
18339
|
+
}
|
|
18340
|
+
return passResult("CISCO-SNMP-001", node, "SNMP community is not a default name.");
|
|
18341
|
+
}
|
|
18342
|
+
};
|
|
18343
|
+
var CiscoHsrpMd5Authentication = {
|
|
18344
|
+
id: "CISCO-CTRL-003",
|
|
18345
|
+
selector: "interface",
|
|
18346
|
+
vendor: "cisco-ios",
|
|
18347
|
+
category: "High-Availability",
|
|
18348
|
+
metadata: {
|
|
18349
|
+
level: "warning",
|
|
18350
|
+
obu: "Network Engineering",
|
|
18351
|
+
owner: "NetOps",
|
|
18352
|
+
remediation: 'Configure "standby <group> authentication md5 key-string <key>" for HSRP.',
|
|
18353
|
+
security: {
|
|
18354
|
+
cwe: ["CWE-306"]
|
|
18355
|
+
},
|
|
18356
|
+
tags: [
|
|
18357
|
+
{ type: "general", label: "fhrp" },
|
|
18358
|
+
{ type: "general", label: "authentication" }
|
|
18359
|
+
]
|
|
18360
|
+
},
|
|
18361
|
+
check: (node) => {
|
|
18362
|
+
const hasHsrp = node.children.some((child) => /^standby(?:\s+\d+)?\s+ip(?:\s|$)/i.test(child.id.trim()));
|
|
18363
|
+
if (!hasHsrp) {
|
|
18364
|
+
return passResult("CISCO-CTRL-003", node, "No HSRP configured.");
|
|
18365
|
+
}
|
|
18366
|
+
const hasAuth = node.children.some(
|
|
18367
|
+
(child) => startsWithIgnoreCase(child.id, "standby") && includesIgnoreCase(child.id, "authentication")
|
|
18368
|
+
);
|
|
18369
|
+
if (!hasAuth) {
|
|
18370
|
+
return passResult("CISCO-CTRL-003", node, "No HSRP authentication (reported by NET-FHRP-002).");
|
|
18371
|
+
}
|
|
18372
|
+
if (!hasHsrpMd5Auth(node)) {
|
|
18373
|
+
return {
|
|
18374
|
+
passed: false,
|
|
18375
|
+
message: `Interface "${node.params.slice(1).join(" ")}" has HSRP authentication that is not MD5. Configure "standby <group> authentication md5 key-string <key>".`,
|
|
18376
|
+
ruleId: "CISCO-CTRL-003",
|
|
18377
|
+
nodeId: node.id,
|
|
18378
|
+
level: "warning",
|
|
18379
|
+
loc: node.loc
|
|
18380
|
+
};
|
|
18381
|
+
}
|
|
18382
|
+
return passResult("CISCO-CTRL-003", node, "HSRP has MD5 authentication configured.");
|
|
18383
|
+
}
|
|
18384
|
+
};
|
|
18773
18385
|
var firstStatementCache = /* @__PURE__ */ new WeakMap();
|
|
18774
18386
|
var firstStatementOf2 = (ast) => {
|
|
18775
18387
|
const cached = firstStatementCache.get(ast);
|
|
@@ -19299,6 +18911,9 @@ var allCiscoRules = [
|
|
|
19299
18911
|
CiscoWanNoIpUnreachables,
|
|
19300
18912
|
CiscoWanNoProxyArp,
|
|
19301
18913
|
CiscoNoDirectedBroadcast,
|
|
18914
|
+
// Paid-only rules opened (gecko#60)
|
|
18915
|
+
CiscoSnmpNoDefaultCommunity,
|
|
18916
|
+
CiscoHsrpMd5Authentication,
|
|
19302
18917
|
// Reference rules on the symbol table (gecko#59, experimental)
|
|
19303
18918
|
CiscoUndefinedFilterAcl,
|
|
19304
18919
|
CiscoUndefinedAclReference,
|
|
@@ -19931,7 +19546,7 @@ var bgpPeerAs = (peer) => {
|
|
|
19931
19546
|
return void 0;
|
|
19932
19547
|
};
|
|
19933
19548
|
var activeBgpPeers = (bgp) => getBgpPeers2(bgp).filter((p) => p.neighborNode || hasChildCommand(p.groupNode, "allow"));
|
|
19934
|
-
var groupPeerFindings = (ruleId, peers, failing, what) => {
|
|
19549
|
+
var groupPeerFindings = (ruleId, peers, failing, what, level = "warning") => {
|
|
19935
19550
|
const findings = [];
|
|
19936
19551
|
const groups = [...new Set(failing.map((p) => p.group))];
|
|
19937
19552
|
for (const group of groups) {
|
|
@@ -19939,12 +19554,12 @@ var groupPeerFindings = (ruleId, peers, failing, what) => {
|
|
|
19939
19554
|
const bad = failing.filter((p) => p.group === group);
|
|
19940
19555
|
const groupNode = bad[0]?.groupNode;
|
|
19941
19556
|
if (bad.length === all.length && groupNode) {
|
|
19942
|
-
findings.push(offenderResult2(ruleId, groupNode, `eBGP group ${group} has ${what}.`,
|
|
19557
|
+
findings.push(offenderResult2(ruleId, groupNode, `eBGP group ${group} has ${what}.`, level));
|
|
19943
19558
|
continue;
|
|
19944
19559
|
}
|
|
19945
19560
|
for (const peer of bad) {
|
|
19946
19561
|
findings.push(
|
|
19947
|
-
offenderResult2(ruleId, peer.neighborNode ?? peer.groupNode, `eBGP group ${group}: neighbor ${peer.neighbor ?? "(dynamic)"} has ${what}.`,
|
|
19562
|
+
offenderResult2(ruleId, peer.neighborNode ?? peer.groupNode, `eBGP group ${group}: neighbor ${peer.neighbor ?? "(dynamic)"} has ${what}.`, level)
|
|
19948
19563
|
);
|
|
19949
19564
|
}
|
|
19950
19565
|
}
|
|
@@ -20965,6 +20580,252 @@ var JunosSecretStorage = {
|
|
|
20965
20580
|
return findings;
|
|
20966
20581
|
})
|
|
20967
20582
|
};
|
|
20583
|
+
var SRX_SECURITY_STATEMENT = /^(zones|policies|screen|nat|flow|address-book|utm|alg|idp|application-firewall|log)\b/i;
|
|
20584
|
+
var isSrxSecurityStanza = (node, context) => isTopLevel(node, context) && node.children.some((child) => SRX_SECURITY_STATEMENT.test(child.id.trim()));
|
|
20585
|
+
var JunosOspfInterfaceAuth = {
|
|
20586
|
+
id: "JUN-CTRL-001",
|
|
20587
|
+
selector: "protocols",
|
|
20588
|
+
vendor: "juniper-junos",
|
|
20589
|
+
category: "Routing",
|
|
20590
|
+
metadata: {
|
|
20591
|
+
level: "warning",
|
|
20592
|
+
obu: "Security",
|
|
20593
|
+
owner: "NetOps",
|
|
20594
|
+
remediation: "Configure OSPF authentication (MD5) on every non-passive OSPF interface in the area.",
|
|
20595
|
+
security: {
|
|
20596
|
+
cwe: ["CWE-287"]
|
|
20597
|
+
},
|
|
20598
|
+
tags: generalTags("routing", "authentication", "ospf")
|
|
20599
|
+
},
|
|
20600
|
+
check: (node, context) => {
|
|
20601
|
+
if (!isTopLevel(node, context)) {
|
|
20602
|
+
return passResult2("JUN-CTRL-001", node, "Not the top-level protocols stanza.");
|
|
20603
|
+
}
|
|
20604
|
+
const ospf = findStanza4(node, "ospf");
|
|
20605
|
+
if (!ospf) {
|
|
20606
|
+
return passResult2("JUN-CTRL-001", node, "OSPF not configured.");
|
|
20607
|
+
}
|
|
20608
|
+
const findings = [];
|
|
20609
|
+
for (const area of findStanzas3(ospf, /^area\s/i)) {
|
|
20610
|
+
const interfaces = findStanzas3(area, /^interface\s/i);
|
|
20611
|
+
if (!interfaces.some((iface) => hasOspfInterfaceAuth(iface))) continue;
|
|
20612
|
+
for (const iface of interfaces) {
|
|
20613
|
+
const ifaceName = iface.id.replace(/^interface\s+/i, "").trim();
|
|
20614
|
+
if (isLoopback3(ifaceName) || hasOspfInterfaceAuth(iface) || hasChildCommand(iface, "passive") || isDisabled(iface)) continue;
|
|
20615
|
+
findings.push(
|
|
20616
|
+
offenderResult2(
|
|
20617
|
+
"JUN-CTRL-001",
|
|
20618
|
+
iface,
|
|
20619
|
+
`OSPF interface ${ifaceName} in ${area.id.trim()} has no authentication while other interfaces in the area do.`,
|
|
20620
|
+
"warning"
|
|
20621
|
+
)
|
|
20622
|
+
);
|
|
20623
|
+
}
|
|
20624
|
+
}
|
|
20625
|
+
if (findings.length > 0) return findings;
|
|
20626
|
+
return passResult2("JUN-CTRL-001", node, "OSPF interfaces are authenticated.");
|
|
20627
|
+
}
|
|
20628
|
+
};
|
|
20629
|
+
var JunosIcmpRateLimit = {
|
|
20630
|
+
id: "JUN-CTRL-004",
|
|
20631
|
+
selector: "system",
|
|
20632
|
+
vendor: "juniper-junos",
|
|
20633
|
+
category: "Protocol-Security",
|
|
20634
|
+
metadata: {
|
|
20635
|
+
level: "info",
|
|
20636
|
+
obu: "Security",
|
|
20637
|
+
owner: "SecOps",
|
|
20638
|
+
remediation: 'Configure ICMP rate limiting under "system internet-options" (icmpv4-rate-limit, icmpv6-rate-limit).',
|
|
20639
|
+
security: {
|
|
20640
|
+
cwe: ["CWE-770"]
|
|
20641
|
+
},
|
|
20642
|
+
tags: generalTags("ddos", "rate-limiting", "icmp")
|
|
20643
|
+
},
|
|
20644
|
+
check: (node, context) => {
|
|
20645
|
+
if (!isTopLevel(node, context)) {
|
|
20646
|
+
return passResult2("JUN-CTRL-004", node, "Not the top-level system stanza.");
|
|
20647
|
+
}
|
|
20648
|
+
const internetOptions = findStanza4(node, "internet-options");
|
|
20649
|
+
if (!internetOptions) {
|
|
20650
|
+
return failResult(
|
|
20651
|
+
"JUN-CTRL-004",
|
|
20652
|
+
node,
|
|
20653
|
+
"System internet-options not configured. Configure ICMP rate limiting.",
|
|
20654
|
+
"info"
|
|
20655
|
+
);
|
|
20656
|
+
}
|
|
20657
|
+
if (!hasChildCommand(internetOptions, "icmpv4-rate-limit") && !hasChildCommand(internetOptions, "icmpv6-rate-limit")) {
|
|
20658
|
+
return failResult(
|
|
20659
|
+
"JUN-CTRL-004",
|
|
20660
|
+
internetOptions,
|
|
20661
|
+
"ICMP rate limiting not configured in internet-options.",
|
|
20662
|
+
"info"
|
|
20663
|
+
);
|
|
20664
|
+
}
|
|
20665
|
+
return passResult2("JUN-CTRL-004", node, "ICMP rate limiting is configured.");
|
|
20666
|
+
}
|
|
20667
|
+
};
|
|
20668
|
+
var isMultihopPeer = (peer) => peer.levels.some((level) => level.children.some((child) => /^multihop\b/i.test(child.id.trim())));
|
|
20669
|
+
var hasGtsmTtl = (peer) => peer.levels.some(
|
|
20670
|
+
(level) => level.children.some((child) => /^ttl\s+255\s*;?$|^apply-macro\s+ttl-security\b/i.test(child.id.trim()))
|
|
20671
|
+
);
|
|
20672
|
+
var JunosBgpTtlSecurity = {
|
|
20673
|
+
id: "JUN-BGP-004",
|
|
20674
|
+
selector: "protocols",
|
|
20675
|
+
vendor: "juniper-junos",
|
|
20676
|
+
category: "Routing",
|
|
20677
|
+
metadata: {
|
|
20678
|
+
level: "warning",
|
|
20679
|
+
obu: "Security",
|
|
20680
|
+
owner: "NetOps",
|
|
20681
|
+
remediation: 'Set "ttl 255" on the eBGP group and apply an inbound firewall filter that discards BGP packets with a TTL below 255 (ttl-except 255).',
|
|
20682
|
+
security: {
|
|
20683
|
+
cwe: ["CWE-346"]
|
|
20684
|
+
},
|
|
20685
|
+
tags: generalTags("bgp", "spoofing", "routing")
|
|
20686
|
+
},
|
|
20687
|
+
check: (node, context) => {
|
|
20688
|
+
if (!isTopLevel(node, context)) {
|
|
20689
|
+
return passResult2("JUN-BGP-004", node, "Not the top-level protocols stanza.");
|
|
20690
|
+
}
|
|
20691
|
+
const bgp = findStanza4(node, "bgp");
|
|
20692
|
+
if (!bgp) {
|
|
20693
|
+
return passResult2("JUN-BGP-004", node, "BGP not configured.");
|
|
20694
|
+
}
|
|
20695
|
+
const external = activeBgpPeers(bgp).filter((p) => p.external);
|
|
20696
|
+
const failing = external.filter((peer) => !hasGtsmTtl(peer));
|
|
20697
|
+
const multihop = failing.filter((peer) => isMultihopPeer(peer));
|
|
20698
|
+
const singleHop = failing.filter((peer) => !isMultihopPeer(peer));
|
|
20699
|
+
const findings = [
|
|
20700
|
+
...groupPeerFindings("JUN-BGP-004", external, singleHop, "no TTL security (ttl 255) configured"),
|
|
20701
|
+
...groupPeerFindings(
|
|
20702
|
+
"JUN-BGP-004",
|
|
20703
|
+
external,
|
|
20704
|
+
multihop,
|
|
20705
|
+
"multihop: TTL security (GTSM) does not apply to multihop sessions; restrict BGP with a TTL-aware firewall filter or suppress",
|
|
20706
|
+
"info"
|
|
20707
|
+
)
|
|
20708
|
+
];
|
|
20709
|
+
if (findings.length > 0) return findings;
|
|
20710
|
+
return passResult2("JUN-BGP-004", node, "eBGP groups have TTL security configured.");
|
|
20711
|
+
}
|
|
20712
|
+
};
|
|
20713
|
+
var JunosSecurityZonesRequired = {
|
|
20714
|
+
id: "JUN-ZONE-001",
|
|
20715
|
+
selector: "security",
|
|
20716
|
+
vendor: "juniper-junos",
|
|
20717
|
+
category: "Network-Segmentation",
|
|
20718
|
+
metadata: {
|
|
20719
|
+
level: "warning",
|
|
20720
|
+
obu: "Security",
|
|
20721
|
+
owner: "SecOps",
|
|
20722
|
+
remediation: "Configure security zones for traffic segmentation on SRX devices.",
|
|
20723
|
+
tags: generalTags("segmentation", "zones")
|
|
20724
|
+
},
|
|
20725
|
+
check: (node, context) => {
|
|
20726
|
+
if (!isSrxSecurityStanza(node, context)) {
|
|
20727
|
+
return passResult2("JUN-ZONE-001", node, "Not an SRX security stanza.");
|
|
20728
|
+
}
|
|
20729
|
+
if (!hasSecurityZones(node)) {
|
|
20730
|
+
return failResult(
|
|
20731
|
+
"JUN-ZONE-001",
|
|
20732
|
+
node,
|
|
20733
|
+
"Security zones not configured. Configure zones for traffic segmentation.",
|
|
20734
|
+
"warning"
|
|
20735
|
+
);
|
|
20736
|
+
}
|
|
20737
|
+
return passResult2("JUN-ZONE-001", node, "Security zones are configured.");
|
|
20738
|
+
}
|
|
20739
|
+
};
|
|
20740
|
+
var JunosSecurityPoliciesRequired = {
|
|
20741
|
+
id: "JUN-ZONE-002",
|
|
20742
|
+
selector: "security",
|
|
20743
|
+
vendor: "juniper-junos",
|
|
20744
|
+
category: "Network-Segmentation",
|
|
20745
|
+
metadata: {
|
|
20746
|
+
level: "warning",
|
|
20747
|
+
obu: "Security",
|
|
20748
|
+
owner: "SecOps",
|
|
20749
|
+
remediation: "Configure security policies for inter-zone traffic control.",
|
|
20750
|
+
tags: generalTags("segmentation", "policies")
|
|
20751
|
+
},
|
|
20752
|
+
check: (node, context) => {
|
|
20753
|
+
if (!isSrxSecurityStanza(node, context)) {
|
|
20754
|
+
return passResult2("JUN-ZONE-002", node, "Not an SRX security stanza.");
|
|
20755
|
+
}
|
|
20756
|
+
if (!hasSecurityPolicies(node)) {
|
|
20757
|
+
return failResult(
|
|
20758
|
+
"JUN-ZONE-002",
|
|
20759
|
+
node,
|
|
20760
|
+
"Security policies not configured. Configure policies for inter-zone traffic.",
|
|
20761
|
+
"warning"
|
|
20762
|
+
);
|
|
20763
|
+
}
|
|
20764
|
+
return passResult2("JUN-ZONE-002", node, "Security policies are configured.");
|
|
20765
|
+
}
|
|
20766
|
+
};
|
|
20767
|
+
var JunosSyslogLocalFile = {
|
|
20768
|
+
id: "JUN-LOG-001",
|
|
20769
|
+
selector: "system",
|
|
20770
|
+
vendor: "juniper-junos",
|
|
20771
|
+
category: "Logging",
|
|
20772
|
+
metadata: {
|
|
20773
|
+
level: "warning",
|
|
20774
|
+
obu: "Security",
|
|
20775
|
+
owner: "SecOps",
|
|
20776
|
+
remediation: 'Configure at least one local syslog "file" in addition to the remote host.',
|
|
20777
|
+
security: {
|
|
20778
|
+
cwe: ["CWE-778"]
|
|
20779
|
+
},
|
|
20780
|
+
tags: generalTags("logging", "monitoring")
|
|
20781
|
+
},
|
|
20782
|
+
check: (node, context) => {
|
|
20783
|
+
if (!isTopLevel(node, context)) {
|
|
20784
|
+
return passResult2("JUN-LOG-001", node, "Not the top-level system stanza.");
|
|
20785
|
+
}
|
|
20786
|
+
const syslog = findStanza4(node, "syslog");
|
|
20787
|
+
if (!syslog) {
|
|
20788
|
+
return passResult2("JUN-LOG-001", node, "No syslog stanza (reported by JUN-SYS-003).");
|
|
20789
|
+
}
|
|
20790
|
+
const hasFile = findStanzas3(syslog, /^file\b/i).length > 0 || hasChildCommand(syslog, "file");
|
|
20791
|
+
if (!hasFile && hasRemoteSyslog(syslog)) {
|
|
20792
|
+
return failResult(
|
|
20793
|
+
"JUN-LOG-001",
|
|
20794
|
+
syslog,
|
|
20795
|
+
"No local syslog file configured; logs go only to the remote host.",
|
|
20796
|
+
"warning"
|
|
20797
|
+
);
|
|
20798
|
+
}
|
|
20799
|
+
return passResult2("JUN-LOG-001", node, "Syslog keeps a local file.");
|
|
20800
|
+
}
|
|
20801
|
+
};
|
|
20802
|
+
var JunosSecurityLogging = {
|
|
20803
|
+
id: "JUN-LOG-002",
|
|
20804
|
+
selector: "security",
|
|
20805
|
+
vendor: "juniper-junos",
|
|
20806
|
+
category: "Logging",
|
|
20807
|
+
metadata: {
|
|
20808
|
+
level: "warning",
|
|
20809
|
+
obu: "Security",
|
|
20810
|
+
owner: "SecOps",
|
|
20811
|
+
remediation: "Configure security log with stream destination for traffic analysis.",
|
|
20812
|
+
tags: generalTags("logging", "monitoring")
|
|
20813
|
+
},
|
|
20814
|
+
check: (node, context) => {
|
|
20815
|
+
if (!isSrxSecurityStanza(node, context)) {
|
|
20816
|
+
return passResult2("JUN-LOG-002", node, "Not an SRX security stanza.");
|
|
20817
|
+
}
|
|
20818
|
+
if (!hasSecurityLogging(node)) {
|
|
20819
|
+
return failResult(
|
|
20820
|
+
"JUN-LOG-002",
|
|
20821
|
+
node,
|
|
20822
|
+
"Security logging not configured. Enable security log for traffic analysis.",
|
|
20823
|
+
"warning"
|
|
20824
|
+
);
|
|
20825
|
+
}
|
|
20826
|
+
return passResult2("JUN-LOG-002", node, "Security logging is configured.");
|
|
20827
|
+
}
|
|
20828
|
+
};
|
|
20968
20829
|
var allJuniperRules = [
|
|
20969
20830
|
RootAuthRequired,
|
|
20970
20831
|
SshServiceRequired,
|
|
@@ -21002,7 +20863,15 @@ var allJuniperRules = [
|
|
|
21002
20863
|
JunosIkeDpd,
|
|
21003
20864
|
JunosFlowMonitoring,
|
|
21004
20865
|
JunosNonstopRouting,
|
|
21005
|
-
JunosSecretStorage
|
|
20866
|
+
JunosSecretStorage,
|
|
20867
|
+
// Paid-only rules opened (gecko#60)
|
|
20868
|
+
JunosOspfInterfaceAuth,
|
|
20869
|
+
JunosIcmpRateLimit,
|
|
20870
|
+
JunosBgpTtlSecurity,
|
|
20871
|
+
JunosSecurityZonesRequired,
|
|
20872
|
+
JunosSecurityPoliciesRequired,
|
|
20873
|
+
JunosSyslogLocalFile,
|
|
20874
|
+
JunosSecurityLogging
|
|
21006
20875
|
];
|
|
21007
20876
|
|
|
21008
20877
|
// ../rules-default/src/aruba/ported-shared.ts
|
|
@@ -23784,6 +23653,32 @@ var WlcWpa3Enterprise = {
|
|
|
23784
23653
|
);
|
|
23785
23654
|
}
|
|
23786
23655
|
};
|
|
23656
|
+
var WlcWpa3SaePassphrase = {
|
|
23657
|
+
id: "ARU-WIFI-002",
|
|
23658
|
+
selector: "wlan ssid-profile",
|
|
23659
|
+
vendor: "aruba-wlc",
|
|
23660
|
+
category: "Wireless",
|
|
23661
|
+
metadata: {
|
|
23662
|
+
level: "warning",
|
|
23663
|
+
obu: "Security",
|
|
23664
|
+
owner: "SecOps",
|
|
23665
|
+
remediation: 'Set the SAE passphrase on the SSID profile with "wpa-passphrase <passphrase>". Choose a long, random passphrase; its strength cannot be checked from the configuration.',
|
|
23666
|
+
security: {
|
|
23667
|
+
cwe: ["CWE-521"]
|
|
23668
|
+
},
|
|
23669
|
+
tags: generalTags2("wireless-security", "wpa3", "password-policy")
|
|
23670
|
+
},
|
|
23671
|
+
check: (node) => {
|
|
23672
|
+
if (node.type !== "section") return [];
|
|
23673
|
+
if (!opmodesOf(node).some((m) => m.startsWith("wpa3") && m.includes("sae"))) return [];
|
|
23674
|
+
const name = profileNameOf(node);
|
|
23675
|
+
const hasPassphrase = node.children.some((c) => wordsOf(c)[0] === "wpa-passphrase" && c.params.length > 1);
|
|
23676
|
+
if (!hasPassphrase) {
|
|
23677
|
+
return failAt("ARU-WIFI-002", node, `WPA3-SAE SSID profile "${name}" has no wpa-passphrase configured.`, "warning");
|
|
23678
|
+
}
|
|
23679
|
+
return passAt("ARU-WIFI-002", node, `WPA3-SAE SSID profile "${name}" has a passphrase configured.`);
|
|
23680
|
+
}
|
|
23681
|
+
};
|
|
23787
23682
|
var WlcSsidMaxClients = {
|
|
23788
23683
|
id: "ARUWLC-WLAN-004",
|
|
23789
23684
|
selector: "wlan ssid-profile",
|
|
@@ -23828,6 +23723,7 @@ var allWlcRules = [
|
|
|
23828
23723
|
WlcUserRoleFirewall,
|
|
23829
23724
|
WlcSsidLimit,
|
|
23830
23725
|
WlcWpa3Enterprise,
|
|
23726
|
+
WlcWpa3SaePassphrase,
|
|
23831
23727
|
WlcSsidMaxClients
|
|
23832
23728
|
];
|
|
23833
23729
|
|
|
@@ -25648,6 +25544,10 @@ var VxlanVniMappings = {
|
|
|
25648
25544
|
};
|
|
25649
25545
|
}
|
|
25650
25546
|
};
|
|
25547
|
+
var eapiPlainHttpLine = (node) => {
|
|
25548
|
+
if (node.children.some((child) => /^no\s+protocol\s+http$/i.test(child.id.trim()))) return void 0;
|
|
25549
|
+
return node.children.find((child) => /^protocol\s+http(?:\s+port\s+\d+)?$/i.test(child.id.trim()));
|
|
25550
|
+
};
|
|
25651
25551
|
var ManagementApiHttps = {
|
|
25652
25552
|
id: "ARI-API-001",
|
|
25653
25553
|
selector: "management api",
|
|
@@ -25679,9 +25579,7 @@ var ManagementApiHttps = {
|
|
|
25679
25579
|
loc: node.loc
|
|
25680
25580
|
};
|
|
25681
25581
|
}
|
|
25682
|
-
const hasHttp = node
|
|
25683
|
-
(child) => /protocol\s+http(?!s)/i.test(child.id)
|
|
25684
|
-
);
|
|
25582
|
+
const hasHttp = eapiPlainHttpLine(node) !== void 0;
|
|
25685
25583
|
const hasHttps = hasHttpsTransport(node);
|
|
25686
25584
|
if (hasHttp && !hasHttps) {
|
|
25687
25585
|
return {
|
|
@@ -27362,6 +27260,36 @@ var EosSecretStorage = {
|
|
|
27362
27260
|
return findings;
|
|
27363
27261
|
})
|
|
27364
27262
|
};
|
|
27263
|
+
var EosEapiHttpWithHttps = {
|
|
27264
|
+
id: "ARISTA-MGMT-014",
|
|
27265
|
+
selector: "management api http-commands",
|
|
27266
|
+
vendor: "arista-eos",
|
|
27267
|
+
category: "Authentication",
|
|
27268
|
+
metadata: {
|
|
27269
|
+
level: "error",
|
|
27270
|
+
obu: "Security",
|
|
27271
|
+
owner: "SecOps",
|
|
27272
|
+
remediation: "Configure eAPI with HTTPS only: protocol https / no protocol http",
|
|
27273
|
+
security: {
|
|
27274
|
+
cwe: ["CWE-319"],
|
|
27275
|
+
cvssScore: 7.5,
|
|
27276
|
+
cvssVector: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
|
|
27277
|
+
},
|
|
27278
|
+
tags: generalTags4("api", "unencrypted-transport")
|
|
27279
|
+
},
|
|
27280
|
+
check: (node) => {
|
|
27281
|
+
const httpNode = eapiPlainHttpLine(node);
|
|
27282
|
+
if (httpNode && hasHttpsTransport(node)) {
|
|
27283
|
+
return failResult2(
|
|
27284
|
+
"ARISTA-MGMT-014",
|
|
27285
|
+
httpNode,
|
|
27286
|
+
'eAPI HTTP (insecure) is enabled alongside HTTPS. Disable with "no protocol http" and use HTTPS only.',
|
|
27287
|
+
"error"
|
|
27288
|
+
);
|
|
27289
|
+
}
|
|
27290
|
+
return passResult4("ARISTA-MGMT-014", node, "eAPI does not serve HTTP alongside HTTPS.");
|
|
27291
|
+
}
|
|
27292
|
+
};
|
|
27365
27293
|
var allAristaRules = [
|
|
27366
27294
|
HostnameRequired2,
|
|
27367
27295
|
NtpRequired3,
|
|
@@ -27414,7 +27342,9 @@ var allAristaRules = [
|
|
|
27414
27342
|
EosLoggingSourceInterface,
|
|
27415
27343
|
EosVrrpAuthentication,
|
|
27416
27344
|
EosVirtualRouterMac,
|
|
27417
|
-
EosSecretStorage
|
|
27345
|
+
EosSecretStorage,
|
|
27346
|
+
// Paid-only rules opened (gecko#60)
|
|
27347
|
+
EosEapiHttpWithHttps
|
|
27418
27348
|
];
|
|
27419
27349
|
|
|
27420
27350
|
// ../rules-default/src/arista/index.ts
|
|
@@ -40346,7 +40276,7 @@ var cisco_json_rules_default = {
|
|
|
40346
40276
|
type: "child_not_exists",
|
|
40347
40277
|
selector: "access-class"
|
|
40348
40278
|
},
|
|
40349
|
-
failureMessage: "
|
|
40279
|
+
failureMessage: '"{nodeId}" is missing access-class for SSH access control'
|
|
40350
40280
|
}
|
|
40351
40281
|
]
|
|
40352
40282
|
};
|
|
@@ -40591,6 +40521,10 @@ var allRules = [
|
|
|
40591
40521
|
// JSON-defined rules (compiled from JSON files)
|
|
40592
40522
|
...allJsonRules
|
|
40593
40523
|
];
|
|
40524
|
+
var builtInRuleIds = new Set(allRules.map((rule) => rule.id));
|
|
40525
|
+
function builtInRuleDocsUrl(ruleId) {
|
|
40526
|
+
return builtInRuleIds.has(ruleId) ? ruleDocsUrl(ruleId) : void 0;
|
|
40527
|
+
}
|
|
40594
40528
|
var ciscoRulesFor = (vendorId) => allCiscoRules.filter((rule) => ruleAppliesToVendor(rule, vendorId));
|
|
40595
40529
|
var vendorRulesRegistry = {
|
|
40596
40530
|
// Cisco platforms share one rule array; each rule's `vendor` field says
|
|
@@ -40623,6 +40557,492 @@ function getRulesByVendor(vendorId) {
|
|
|
40623
40557
|
return allRules;
|
|
40624
40558
|
}
|
|
40625
40559
|
|
|
40560
|
+
// src/sarif.ts
|
|
40561
|
+
import { relative } from "path";
|
|
40562
|
+
import { createHash } from "crypto";
|
|
40563
|
+
|
|
40564
|
+
// src/cliOptions.ts
|
|
40565
|
+
import { readFileSync } from "fs";
|
|
40566
|
+
var FAIL_ON_LEVELS = ["error", "warning", "info", "never"];
|
|
40567
|
+
var SEVERITY_RANK = {
|
|
40568
|
+
info: 0,
|
|
40569
|
+
warning: 1,
|
|
40570
|
+
error: 2
|
|
40571
|
+
};
|
|
40572
|
+
function parseFailOn(value) {
|
|
40573
|
+
const v = value.trim().toLowerCase();
|
|
40574
|
+
const match = FAIL_ON_LEVELS.find((l) => l === v);
|
|
40575
|
+
if (!match) {
|
|
40576
|
+
throw new Error(
|
|
40577
|
+
`Invalid --fail-on value '${value}'. Expected one of: ${FAIL_ON_LEVELS.join(", ")}`
|
|
40578
|
+
);
|
|
40579
|
+
}
|
|
40580
|
+
return match;
|
|
40581
|
+
}
|
|
40582
|
+
var OUTPUT_FORMATS = ["json", "human", "sarif"];
|
|
40583
|
+
function parseFormat(value) {
|
|
40584
|
+
const v = value.trim().toLowerCase();
|
|
40585
|
+
const match = OUTPUT_FORMATS.find((f) => f === v);
|
|
40586
|
+
if (!match) {
|
|
40587
|
+
throw new Error(
|
|
40588
|
+
`Invalid --format value '${value}'. Expected one of: ${OUTPUT_FORMATS.join(", ")}`
|
|
40589
|
+
);
|
|
40590
|
+
}
|
|
40591
|
+
return match;
|
|
40592
|
+
}
|
|
40593
|
+
var LIST_FORMATS = ["table", "json", "csv"];
|
|
40594
|
+
function parseListFormat(value) {
|
|
40595
|
+
const v = value.trim().toLowerCase();
|
|
40596
|
+
const match = LIST_FORMATS.find((f) => f === v);
|
|
40597
|
+
if (!match) {
|
|
40598
|
+
throw new Error(
|
|
40599
|
+
`Invalid --list-format value '${value}'. Expected one of: ${LIST_FORMATS.join(", ")}`
|
|
40600
|
+
);
|
|
40601
|
+
}
|
|
40602
|
+
return match;
|
|
40603
|
+
}
|
|
40604
|
+
function shouldFail(results, threshold) {
|
|
40605
|
+
if (threshold === "never") return false;
|
|
40606
|
+
const min = SEVERITY_RANK[threshold];
|
|
40607
|
+
return results.some((r) => !r.passed && SEVERITY_RANK[r.level] >= min);
|
|
40608
|
+
}
|
|
40609
|
+
function normalizeExtensions(value) {
|
|
40610
|
+
return value.split(",").map((e) => e.trim().replace(/^\.+/, "").toLowerCase()).filter((e) => e.length > 0);
|
|
40611
|
+
}
|
|
40612
|
+
function resolveVersion(injected) {
|
|
40613
|
+
if (injected !== void 0) return injected;
|
|
40614
|
+
try {
|
|
40615
|
+
const pkg = JSON.parse(
|
|
40616
|
+
readFileSync(new URL("../package.json", import.meta.url), "utf-8")
|
|
40617
|
+
);
|
|
40618
|
+
if (pkg && typeof pkg === "object" && "version" in pkg && typeof pkg.version === "string") {
|
|
40619
|
+
return pkg.version;
|
|
40620
|
+
}
|
|
40621
|
+
} catch {
|
|
40622
|
+
}
|
|
40623
|
+
return "unknown";
|
|
40624
|
+
}
|
|
40625
|
+
|
|
40626
|
+
// src/sarif.ts
|
|
40627
|
+
var TOOL_VERSION = resolveVersion(
|
|
40628
|
+
true ? "0.11.0-rc.1" : void 0
|
|
40629
|
+
);
|
|
40630
|
+
var CWE_GUID = "1A0F2A4E-3B93-4C4E-8CC7-9A4E3A5B9A3A";
|
|
40631
|
+
function cweNumber(cweId) {
|
|
40632
|
+
return cweId.replace(/^cwe-/i, "").trim();
|
|
40633
|
+
}
|
|
40634
|
+
var LEVEL_SECURITY_SEVERITY = {
|
|
40635
|
+
error: "8.0",
|
|
40636
|
+
warning: "5.0",
|
|
40637
|
+
info: "2.0"
|
|
40638
|
+
};
|
|
40639
|
+
function securitySeverity(rule) {
|
|
40640
|
+
const sec = rule.metadata.security;
|
|
40641
|
+
if (sec?.cvssScore !== void 0) return String(sec.cvssScore);
|
|
40642
|
+
if (sec?.cwe && sec.cwe.length > 0) return LEVEL_SECURITY_SEVERITY[rule.metadata.level];
|
|
40643
|
+
return void 0;
|
|
40644
|
+
}
|
|
40645
|
+
function toUri(filePath, options) {
|
|
40646
|
+
return options.relativePaths ? relative(options.baseDir ?? process.cwd(), filePath) : filePath;
|
|
40647
|
+
}
|
|
40648
|
+
function fingerprintPath(filePath, options) {
|
|
40649
|
+
if (filePath.startsWith("<")) return filePath;
|
|
40650
|
+
return relative(options.baseDir ?? process.cwd(), filePath).replace(
|
|
40651
|
+
/\\/g,
|
|
40652
|
+
"/"
|
|
40653
|
+
);
|
|
40654
|
+
}
|
|
40655
|
+
function normaliseText(text) {
|
|
40656
|
+
return text.trim().replace(/\s+/g, " ");
|
|
40657
|
+
}
|
|
40658
|
+
function fingerprintLine(lineText, nodeId) {
|
|
40659
|
+
const line = normaliseText(maskSecretWords(lineText));
|
|
40660
|
+
const at2 = nodeId.indexOf(SECRET_MASK);
|
|
40661
|
+
if (at2 < 0 || line.includes(SECRET_MASK)) return line;
|
|
40662
|
+
const shown2 = normaliseText(nodeId.slice(0, at2));
|
|
40663
|
+
if (shown2 === "" || !line.startsWith(shown2)) return line;
|
|
40664
|
+
const snmp = normaliseText(maskSecretWords(lineText, { snmp: true }));
|
|
40665
|
+
return snmp.includes(SECRET_MASK) ? snmp : `${shown2} ${SECRET_MASK}`;
|
|
40666
|
+
}
|
|
40667
|
+
function normaliseMessage(message) {
|
|
40668
|
+
return normaliseText(message).replace(/\d+/g, "#");
|
|
40669
|
+
}
|
|
40670
|
+
function buildSarifResults(results, filePath, sourceText, ruleIndexById, options, suppressed = []) {
|
|
40671
|
+
const uri = toUri(filePath, options);
|
|
40672
|
+
const fpPath = fingerprintPath(filePath, options);
|
|
40673
|
+
const lines = sourceText?.split(/\r\n|\r|\n/);
|
|
40674
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
40675
|
+
const items = [
|
|
40676
|
+
...results.filter((result2) => options.includePassed || !result2.passed).map((result2) => ({ result: result2 })),
|
|
40677
|
+
...suppressed
|
|
40678
|
+
];
|
|
40679
|
+
const hashes = items.map(({ result: result2 }) => {
|
|
40680
|
+
const lineText = result2.loc ? lines?.[result2.loc.startLine] : void 0;
|
|
40681
|
+
const where = result2.absent ? "" : lineText !== void 0 && lineText.trim() !== "" ? fingerprintLine(lineText, result2.nodeId) : normaliseText(result2.nodeId);
|
|
40682
|
+
return createHash("sha256").update(`${result2.ruleId}
|
|
40683
|
+
${normaliseMessage(result2.message)}
|
|
40684
|
+
${where}
|
|
40685
|
+
${fpPath}`).digest("hex").slice(0, 32);
|
|
40686
|
+
});
|
|
40687
|
+
const occurrenceOf = new Array(items.length).fill(1);
|
|
40688
|
+
const byLine = items.map((item, i) => ({ i, line: item.result.loc?.startLine ?? Number.POSITIVE_INFINITY })).sort((a, b) => a.line - b.line || a.i - b.i);
|
|
40689
|
+
for (const { i } of byLine) {
|
|
40690
|
+
const hash = hashes[i] ?? "";
|
|
40691
|
+
const occurrence = (occurrences.get(hash) ?? 0) + 1;
|
|
40692
|
+
occurrences.set(hash, occurrence);
|
|
40693
|
+
occurrenceOf[i] = occurrence;
|
|
40694
|
+
}
|
|
40695
|
+
return items.map(({ result: result2, suppression }, i) => {
|
|
40696
|
+
const hash = hashes[i] ?? "";
|
|
40697
|
+
const occurrence = occurrenceOf[i] ?? 1;
|
|
40698
|
+
const ruleIndex = ruleIndexById.get(result2.ruleId);
|
|
40699
|
+
return {
|
|
40700
|
+
ruleId: result2.ruleId,
|
|
40701
|
+
...ruleIndex !== void 0 && { ruleIndex },
|
|
40702
|
+
...result2.passed && { kind: "pass" },
|
|
40703
|
+
level: result2.level === "info" ? "note" : result2.level,
|
|
40704
|
+
message: {
|
|
40705
|
+
text: result2.message
|
|
40706
|
+
},
|
|
40707
|
+
locations: result2.loc ? [
|
|
40708
|
+
{
|
|
40709
|
+
physicalLocation: {
|
|
40710
|
+
artifactLocation: { uri },
|
|
40711
|
+
region: {
|
|
40712
|
+
startLine: result2.loc.startLine + 1,
|
|
40713
|
+
// SARIF is 1-based
|
|
40714
|
+
endLine: result2.loc.endLine + 1
|
|
40715
|
+
}
|
|
40716
|
+
}
|
|
40717
|
+
}
|
|
40718
|
+
] : [],
|
|
40719
|
+
partialFingerprints: {
|
|
40720
|
+
primaryLocationLineHash: `${hash}:${occurrence}`
|
|
40721
|
+
},
|
|
40722
|
+
...suppression && {
|
|
40723
|
+
suppressions: [
|
|
40724
|
+
{
|
|
40725
|
+
kind: suppression.kind,
|
|
40726
|
+
status: "accepted",
|
|
40727
|
+
justification: suppression.justification
|
|
40728
|
+
}
|
|
40729
|
+
]
|
|
40730
|
+
}
|
|
40731
|
+
};
|
|
40732
|
+
});
|
|
40733
|
+
}
|
|
40734
|
+
function buildRulesAndTaxonomy(rules) {
|
|
40735
|
+
const cweIds = /* @__PURE__ */ new Set();
|
|
40736
|
+
const sarifRules = rules?.map((rule) => {
|
|
40737
|
+
const base = {
|
|
40738
|
+
id: rule.id,
|
|
40739
|
+
name: rule.id,
|
|
40740
|
+
shortDescription: { text: rule.metadata.remediation ?? rule.id },
|
|
40741
|
+
defaultConfiguration: {
|
|
40742
|
+
level: rule.metadata.level === "info" ? "note" : rule.metadata.level
|
|
40743
|
+
}
|
|
40744
|
+
};
|
|
40745
|
+
const docsUrl = builtInRuleDocsUrl(rule.id);
|
|
40746
|
+
if (docsUrl !== void 0) {
|
|
40747
|
+
const remediation = rule.metadata.remediation;
|
|
40748
|
+
const link = `[Rule documentation](${docsUrl})`;
|
|
40749
|
+
base.helpUri = docsUrl;
|
|
40750
|
+
base.help = {
|
|
40751
|
+
text: remediation ? `${remediation}
|
|
40752
|
+
|
|
40753
|
+
See ${docsUrl}` : `See ${docsUrl}`,
|
|
40754
|
+
markdown: remediation ? `${remediation}
|
|
40755
|
+
|
|
40756
|
+
${link}` : link
|
|
40757
|
+
};
|
|
40758
|
+
}
|
|
40759
|
+
const secMeta = rule.metadata.security;
|
|
40760
|
+
if (secMeta?.cwe && secMeta.cwe.length > 0) {
|
|
40761
|
+
base.relationships = secMeta.cwe.map((cweId) => {
|
|
40762
|
+
const id = cweNumber(cweId);
|
|
40763
|
+
cweIds.add(id);
|
|
40764
|
+
return {
|
|
40765
|
+
target: { id, toolComponent: { name: "CWE" } },
|
|
40766
|
+
kinds: ["relevant"]
|
|
40767
|
+
};
|
|
40768
|
+
});
|
|
40769
|
+
}
|
|
40770
|
+
const severity = securitySeverity(rule);
|
|
40771
|
+
const hasTags = rule.metadata.tags && rule.metadata.tags.length > 0;
|
|
40772
|
+
const hasCategory = rule.category !== void 0;
|
|
40773
|
+
if (severity !== void 0 || secMeta?.cvssVector || hasTags || hasCategory) {
|
|
40774
|
+
base.properties = {};
|
|
40775
|
+
if (hasCategory) {
|
|
40776
|
+
base.properties.category = rule.category;
|
|
40777
|
+
}
|
|
40778
|
+
if (severity !== void 0) {
|
|
40779
|
+
base.properties["security-severity"] = severity;
|
|
40780
|
+
}
|
|
40781
|
+
if (secMeta?.cvssVector) {
|
|
40782
|
+
base.properties["cvss-vector"] = secMeta.cvssVector;
|
|
40783
|
+
}
|
|
40784
|
+
if (hasTags) {
|
|
40785
|
+
base.properties.tags = rule.metadata.tags.map((t) => t.label);
|
|
40786
|
+
}
|
|
40787
|
+
}
|
|
40788
|
+
return base;
|
|
40789
|
+
}) ?? [];
|
|
40790
|
+
const ruleIndexById = /* @__PURE__ */ new Map();
|
|
40791
|
+
sarifRules.forEach((r, i) => {
|
|
40792
|
+
if (!ruleIndexById.has(r.id)) ruleIndexById.set(r.id, i);
|
|
40793
|
+
});
|
|
40794
|
+
const hasCwe = cweIds.size > 0;
|
|
40795
|
+
const cweTaxonomy = hasCwe ? {
|
|
40796
|
+
name: "CWE",
|
|
40797
|
+
version: "4.13",
|
|
40798
|
+
guid: CWE_GUID,
|
|
40799
|
+
informationUri: "https://cwe.mitre.org/",
|
|
40800
|
+
organization: "MITRE",
|
|
40801
|
+
shortDescription: { text: "Common Weakness Enumeration" },
|
|
40802
|
+
taxa: [...cweIds].sort((a, b) => Number(a) - Number(b) || a.localeCompare(b)).map((id) => ({ id, name: `CWE-${id}` }))
|
|
40803
|
+
} : void 0;
|
|
40804
|
+
const supportedTaxonomies = hasCwe ? [{ name: "CWE", index: 0, guid: CWE_GUID }] : void 0;
|
|
40805
|
+
return { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies };
|
|
40806
|
+
}
|
|
40807
|
+
function buildSarif(results, filePath, rules, options = {}, ipSummary) {
|
|
40808
|
+
const { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies } = buildRulesAndTaxonomy(rules);
|
|
40809
|
+
const sarifResults = buildSarifResults(
|
|
40810
|
+
results,
|
|
40811
|
+
filePath,
|
|
40812
|
+
options.sourceText,
|
|
40813
|
+
ruleIndexById,
|
|
40814
|
+
options,
|
|
40815
|
+
options.suppressed
|
|
40816
|
+
);
|
|
40817
|
+
const report = {
|
|
40818
|
+
version: "2.1.0",
|
|
40819
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
40820
|
+
runs: [
|
|
40821
|
+
{
|
|
40822
|
+
tool: {
|
|
40823
|
+
driver: {
|
|
40824
|
+
name: "Sentriflow",
|
|
40825
|
+
version: TOOL_VERSION,
|
|
40826
|
+
informationUri: "https://github.com/sentriflow/sentriflow",
|
|
40827
|
+
rules: sarifRules,
|
|
40828
|
+
...supportedTaxonomies && { supportedTaxonomies }
|
|
40829
|
+
}
|
|
40830
|
+
},
|
|
40831
|
+
...cweTaxonomy && { taxonomies: [cweTaxonomy] },
|
|
40832
|
+
results: sarifResults,
|
|
40833
|
+
// Include IP summary in properties if available
|
|
40834
|
+
...ipSummary && {
|
|
40835
|
+
properties: {
|
|
40836
|
+
ipSummary
|
|
40837
|
+
}
|
|
40838
|
+
}
|
|
40839
|
+
}
|
|
40840
|
+
]
|
|
40841
|
+
};
|
|
40842
|
+
return report;
|
|
40843
|
+
}
|
|
40844
|
+
function aggregateIPSummaries(summaries) {
|
|
40845
|
+
if (summaries.length === 0) return void 0;
|
|
40846
|
+
const ipv4Set = /* @__PURE__ */ new Set();
|
|
40847
|
+
const ipv6Set = /* @__PURE__ */ new Set();
|
|
40848
|
+
const ipv4SubnetSet = /* @__PURE__ */ new Set();
|
|
40849
|
+
const ipv6SubnetSet = /* @__PURE__ */ new Set();
|
|
40850
|
+
for (const summary of summaries) {
|
|
40851
|
+
for (const ip of summary.ipv4Addresses) ipv4Set.add(ip);
|
|
40852
|
+
for (const ip of summary.ipv6Addresses) ipv6Set.add(ip);
|
|
40853
|
+
for (const subnet of summary.ipv4Subnets) ipv4SubnetSet.add(subnet);
|
|
40854
|
+
for (const subnet of summary.ipv6Subnets) ipv6SubnetSet.add(subnet);
|
|
40855
|
+
}
|
|
40856
|
+
const ipv4Addresses = [...ipv4Set].sort((a, b) => {
|
|
40857
|
+
const aParts = a.split(".").map(Number);
|
|
40858
|
+
const bParts = b.split(".").map(Number);
|
|
40859
|
+
for (let i = 0; i < 4; i++) {
|
|
40860
|
+
if ((aParts[i] ?? 0) !== (bParts[i] ?? 0)) {
|
|
40861
|
+
return (aParts[i] ?? 0) - (bParts[i] ?? 0);
|
|
40862
|
+
}
|
|
40863
|
+
}
|
|
40864
|
+
return 0;
|
|
40865
|
+
});
|
|
40866
|
+
const ipv6Addresses = [...ipv6Set].sort();
|
|
40867
|
+
const ipv4Subnets = [...ipv4SubnetSet].sort();
|
|
40868
|
+
const ipv6Subnets = [...ipv6SubnetSet].sort();
|
|
40869
|
+
return {
|
|
40870
|
+
ipv4Addresses,
|
|
40871
|
+
ipv6Addresses,
|
|
40872
|
+
ipv4Subnets,
|
|
40873
|
+
ipv6Subnets,
|
|
40874
|
+
counts: {
|
|
40875
|
+
ipv4: ipv4Addresses.length,
|
|
40876
|
+
ipv6: ipv6Addresses.length,
|
|
40877
|
+
ipv4Subnets: ipv4Subnets.length,
|
|
40878
|
+
ipv6Subnets: ipv6Subnets.length,
|
|
40879
|
+
total: ipv4Addresses.length + ipv6Addresses.length + ipv4Subnets.length + ipv6Subnets.length
|
|
40880
|
+
}
|
|
40881
|
+
};
|
|
40882
|
+
}
|
|
40883
|
+
function buildMultiFileSarif(fileResults, rules, options = {}) {
|
|
40884
|
+
const aggregatedIpSummary = aggregateIPSummaries(
|
|
40885
|
+
fileResults.map((fr) => fr.ipSummary).filter((s) => !!s)
|
|
40886
|
+
);
|
|
40887
|
+
const { sarifRules, ruleIndexById, cweTaxonomy, supportedTaxonomies } = buildRulesAndTaxonomy(rules);
|
|
40888
|
+
const allSarifResults = fileResults.flatMap(
|
|
40889
|
+
({ filePath, results, content, suppressed }) => buildSarifResults(results, filePath, content, ruleIndexById, options, suppressed)
|
|
40890
|
+
);
|
|
40891
|
+
const skippedNotifications = fileResults.filter((fr) => fr.skipped).map((fr) => ({
|
|
40892
|
+
level: "error",
|
|
40893
|
+
message: {
|
|
40894
|
+
text: `Skipped ${options.relativePaths ? relative(options.baseDir ?? process.cwd(), fr.filePath) : fr.filePath}: ${fr.skipped?.reason ?? "not scanned"}. Re-run with --vendor <vendor>.`
|
|
40895
|
+
}
|
|
40896
|
+
}));
|
|
40897
|
+
const artifactUris = [
|
|
40898
|
+
...new Set(
|
|
40899
|
+
fileResults.map(
|
|
40900
|
+
({ filePath }) => options.relativePaths ? relative(options.baseDir ?? process.cwd(), filePath) : filePath
|
|
40901
|
+
)
|
|
40902
|
+
)
|
|
40903
|
+
];
|
|
40904
|
+
const report = {
|
|
40905
|
+
version: "2.1.0",
|
|
40906
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
40907
|
+
runs: [
|
|
40908
|
+
{
|
|
40909
|
+
tool: {
|
|
40910
|
+
driver: {
|
|
40911
|
+
name: "Sentriflow",
|
|
40912
|
+
version: TOOL_VERSION,
|
|
40913
|
+
informationUri: "https://github.com/sentriflow/sentriflow",
|
|
40914
|
+
rules: sarifRules,
|
|
40915
|
+
...supportedTaxonomies && { supportedTaxonomies }
|
|
40916
|
+
}
|
|
40917
|
+
},
|
|
40918
|
+
// Include artifacts array for multi-file reports
|
|
40919
|
+
artifacts: artifactUris.map((uri) => ({
|
|
40920
|
+
location: { uri }
|
|
40921
|
+
})),
|
|
40922
|
+
...cweTaxonomy && { taxonomies: [cweTaxonomy] },
|
|
40923
|
+
results: allSarifResults,
|
|
40924
|
+
...skippedNotifications.length > 0 && {
|
|
40925
|
+
invocations: [
|
|
40926
|
+
{
|
|
40927
|
+
executionSuccessful: false,
|
|
40928
|
+
toolExecutionNotifications: skippedNotifications
|
|
40929
|
+
}
|
|
40930
|
+
]
|
|
40931
|
+
},
|
|
40932
|
+
// Include aggregated IP summary in properties if available
|
|
40933
|
+
...aggregatedIpSummary && {
|
|
40934
|
+
properties: {
|
|
40935
|
+
ipSummary: aggregatedIpSummary
|
|
40936
|
+
}
|
|
40937
|
+
}
|
|
40938
|
+
}
|
|
40939
|
+
]
|
|
40940
|
+
};
|
|
40941
|
+
return report;
|
|
40942
|
+
}
|
|
40943
|
+
|
|
40944
|
+
// src/human.ts
|
|
40945
|
+
var COLORS = {
|
|
40946
|
+
red: "\x1B[31m",
|
|
40947
|
+
yellow: "\x1B[33m",
|
|
40948
|
+
blue: "\x1B[34m",
|
|
40949
|
+
gray: "\x1B[90m",
|
|
40950
|
+
bold: "\x1B[1m",
|
|
40951
|
+
reset: "\x1B[0m"
|
|
40952
|
+
};
|
|
40953
|
+
var SEVERITY_COLORS = {
|
|
40954
|
+
error: COLORS.red,
|
|
40955
|
+
warning: COLORS.yellow,
|
|
40956
|
+
info: COLORS.blue
|
|
40957
|
+
};
|
|
40958
|
+
function countSeverities(results) {
|
|
40959
|
+
const counts = { error: 0, warning: 0, info: 0, total: 0 };
|
|
40960
|
+
for (const r of results) {
|
|
40961
|
+
if (!r.passed) {
|
|
40962
|
+
if (r.level === "error" || r.level === "warning" || r.level === "info") {
|
|
40963
|
+
counts[r.level]++;
|
|
40964
|
+
}
|
|
40965
|
+
counts.total++;
|
|
40966
|
+
}
|
|
40967
|
+
}
|
|
40968
|
+
return counts;
|
|
40969
|
+
}
|
|
40970
|
+
function formatFinding(result2, color) {
|
|
40971
|
+
const line = result2.loc ? result2.loc.startLine + 1 : 0;
|
|
40972
|
+
const col = 1;
|
|
40973
|
+
const location = `${line}:${col}`.padEnd(8);
|
|
40974
|
+
const severityColor = color ? SEVERITY_COLORS[result2.level] ?? "" : "";
|
|
40975
|
+
const reset = color ? COLORS.reset : "";
|
|
40976
|
+
const severityText = result2.level.padEnd(7);
|
|
40977
|
+
const severity = `${severityColor}${severityText}${reset}`;
|
|
40978
|
+
const ruleColor = color ? COLORS.gray : "";
|
|
40979
|
+
const ruleId = `${ruleColor}${result2.ruleId}${reset}`;
|
|
40980
|
+
return ` ${location} ${severity} ${result2.message} ${ruleId}`;
|
|
40981
|
+
}
|
|
40982
|
+
function formatSummary(counts, color) {
|
|
40983
|
+
if (counts.total === 0) {
|
|
40984
|
+
const check = color ? `${COLORS.bold}\u2714${COLORS.reset}` : "\u2714";
|
|
40985
|
+
return `
|
|
40986
|
+
${check} No problems found
|
|
40987
|
+
`;
|
|
40988
|
+
}
|
|
40989
|
+
const x = color ? `${COLORS.red}\u2716${COLORS.reset}` : "\u2716";
|
|
40990
|
+
const parts = [];
|
|
40991
|
+
if (counts.error > 0) {
|
|
40992
|
+
parts.push(`${counts.error} error${counts.error !== 1 ? "s" : ""}`);
|
|
40993
|
+
}
|
|
40994
|
+
if (counts.warning > 0) {
|
|
40995
|
+
parts.push(`${counts.warning} warning${counts.warning !== 1 ? "s" : ""}`);
|
|
40996
|
+
}
|
|
40997
|
+
if (counts.info > 0) {
|
|
40998
|
+
parts.push(`${counts.info} info`);
|
|
40999
|
+
}
|
|
41000
|
+
const problemText = counts.total === 1 ? "problem" : "problems";
|
|
41001
|
+
return `
|
|
41002
|
+
${x} ${counts.total} ${problemText} (${parts.join(", ")})
|
|
41003
|
+
`;
|
|
41004
|
+
}
|
|
41005
|
+
function formatHuman(results, filePath, options) {
|
|
41006
|
+
const color = options?.color ?? false;
|
|
41007
|
+
const failures = results.filter((r) => !r.passed);
|
|
41008
|
+
const lines = [];
|
|
41009
|
+
const header = color ? `${COLORS.bold}${filePath}${COLORS.reset}` : filePath;
|
|
41010
|
+
lines.push(header);
|
|
41011
|
+
for (const result2 of failures) {
|
|
41012
|
+
lines.push(formatFinding(result2, color));
|
|
41013
|
+
}
|
|
41014
|
+
const counts = countSeverities(results);
|
|
41015
|
+
lines.push(formatSummary(counts, color));
|
|
41016
|
+
return lines.join("\n");
|
|
41017
|
+
}
|
|
41018
|
+
function formatMultiFileHuman(files, options) {
|
|
41019
|
+
const color = options?.color ?? false;
|
|
41020
|
+
const lines = [];
|
|
41021
|
+
const totalCounts = { error: 0, warning: 0, info: 0, total: 0 };
|
|
41022
|
+
for (const { file, results } of files) {
|
|
41023
|
+
const failures = results.filter((r) => !r.passed);
|
|
41024
|
+
if (failures.length === 0) continue;
|
|
41025
|
+
const header = color ? `${COLORS.bold}${file}${COLORS.reset}` : file;
|
|
41026
|
+
lines.push(header);
|
|
41027
|
+
for (const result2 of failures) {
|
|
41028
|
+
lines.push(formatFinding(result2, color));
|
|
41029
|
+
}
|
|
41030
|
+
lines.push("");
|
|
41031
|
+
const counts = countSeverities(results);
|
|
41032
|
+
totalCounts.error += counts.error;
|
|
41033
|
+
totalCounts.warning += counts.warning;
|
|
41034
|
+
totalCounts.info += counts.info;
|
|
41035
|
+
totalCounts.total += counts.total;
|
|
41036
|
+
}
|
|
41037
|
+
lines.push(formatSummary(totalCounts, color));
|
|
41038
|
+
return lines.join("\n");
|
|
41039
|
+
}
|
|
41040
|
+
|
|
41041
|
+
// src/parseWarnings.ts
|
|
41042
|
+
function formatParseWarnings(warnings, source) {
|
|
41043
|
+
return warnings.map((warning) => `Warning: ${source}: ${warning.message}`);
|
|
41044
|
+
}
|
|
41045
|
+
|
|
40626
41046
|
// src/config.ts
|
|
40627
41047
|
import { existsSync as existsSync2 } from "fs";
|
|
40628
41048
|
import { readFile as readFileAsync } from "fs/promises";
|
|
@@ -42659,7 +43079,7 @@ async function exitIfVendorUndetected() {
|
|
|
42659
43079
|
}
|
|
42660
43080
|
}
|
|
42661
43081
|
var program = new Command2();
|
|
42662
|
-
var cliVersion = resolveVersion(true ? "0.
|
|
43082
|
+
var cliVersion = resolveVersion(true ? "0.11.0-rc.1" : void 0);
|
|
42663
43083
|
var pluginPackLoaders = [];
|
|
42664
43084
|
var pluginRequests = pluginRequestsFromEnv(process.env);
|
|
42665
43085
|
program.name("sentriflow").description("SentriFlow Network Configuration Validator").version(cliVersion).argument("[files...]", "Path(s) to configuration file(s) (supports multiple files)").option("--ast", "Output the AST instead of rule results").option(
|