@cloudsecuritylt/fw-check-core
v1.1.0
Published
Firewall rule risk analysis engine -- compliance checks, risk scoring, and custom rules
Maintainers
Readme
@cloudsecuritylt/fw-check-core
Firewall Rule Check engine by cloudsecurity.lt. Formerly published as @netbobr/core.
Firewall rule risk analysis engine. Analyzes network flows against 6 compliance frameworks (PCI-DSS, CIS Controls, NIST 800-53, NIS2, DORA, MITRE ATT&CK) and produces risk scores -- stateless analysis, zero dependencies. The only process-wide setting is the optional js-yaml loader for Kubernetes YAML (setYamlLoader, see below).
Install
npm install @cloudsecuritylt/fw-check-coreUsage
import { analyze } from '@cloudsecuritylt/fw-check-core';
const result = analyze(
{ src: '10.0.0.1', dst: '0.0.0.0/0', proto: 'TCP', port: '22' },
{ /* optional config */ }
);
console.log(result.riskScore); // { score: 73, label: 'High', factors: [...] }
console.log(result.overallRisk); // 'HIGH'
console.log(result.pciFindings); // [{ ruleId, severity, finding, ... }]API
analyze(flow, config?)
flow { src, dst, proto, port, appName? } -- the firewall rule to analyze.
config (all optional):
disabledRuleIds--Set<string>of rule IDs to suppresszoneInfo-- zone matrix lookup result (pre-computed)zones-- raw zone config (zone-matrix JSON shape); analyze() will perform zone matching internallycustomRules-- array of custom rule objectsweights--{ srcMax, dstMax, portMax, zoneMax }per-factor caps, each an integer 0-100. Defaults: 25/30/25/20. They need not sum to 100 (the score is clamped to 0-100).analyze()uses the values as given; check user input withvalidateRiskConfigfirstthresholds--[{ max, label }, ...]: exactly 4 tiers (Low, Medium, High, Critical), integermaxvalues strictly ascending with the last one 100, and unique non-empty labels (seevalidateThresholds)zoneAttributes--{ src: {...}, dst: {...} }zone attribute objects, or a map keyed by zone name ({ "<zone name>": {...} }) that is resolved against the flow's matched zones
Returns: { ok, overallRisk, riskScore, pciFindings, cisFindings, nistFindings, nis2Findings, doraFindings, mitreFindings, customFindings, advice, breakdownRows, verdictOverride, ... }
Cloud parsers
The same parsers the Firewall Rule Check browser app uses. They turn cloud firewall exports into flows for analyze(). Also available as the subpath @cloudsecuritylt/fw-check-core/cloud-parsers, which is the same module instance as the main entry.
Format ids: aws-sg, azure-nsg, gcp-fw, tf-plan, tf-hcl, k8s-netpol.
parseCloudConfig(content, format?): async. Returns{ flows, warnings }.formatis a format id; omit it or pass'auto'to detect. Each flow is{ src, dst, proto, port, appName, metadata }, andmetadatacarriessource(the format id),groupName,ruleName,ruleId,descriptionanddirection. Each warning is{ type, message, ... }. Rejects on input it cannot parse.detectCloudFormat(content): returns a format id, ornull.setYamlLoader(loader): Kubernetes YAML needs js-yaml. By default it is loaded from a CDN (browser only). In Node, inject it before parsing YAML.loaderis a function returning js-yaml or a promise of it (a module namespace with adefaultexport also works). It is called once, on first use, and the result is cached.nullrestores the CDN default. The setting is process-wide.
import { parseCloudConfig, setYamlLoader } from '@cloudsecuritylt/fw-check-core';
setYamlLoader(() => import('js-yaml')); // npm install js-yaml (only needed for k8s-netpol)
const { flows, warnings } = await parseCloudConfig(yamlText, 'k8s-netpol');If js-yaml cannot be loaded, the error has err.code === 'YAML_LOADER_UNAVAILABLE'.
Other exports
| Export | Purpose |
|---|---|
| parseIP(value), parsePort(value) | Input parsing and validation used by analyze() |
| computeRiskScore(...) | The 0-100 risk score on its own |
| buildFlowContext, evaluateCustomRules, FIELD_CATALOG | Custom-rule engine |
| normalizeCustomRules(state) | Validate a saved custom-rule state. Returns { rules, nextId, warnings } |
| DEFAULT_WEIGHTS, DEFAULT_THRESHOLDS | Default risk weights and the 4 score thresholds |
| validateRiskConfig({ weights, thresholds }) | Returns { ok, errors, warnings, weights, thresholds }. Treat ok === false as a configuration error |
| validateWeights(w), validateThresholds(t) | The two halves of validateRiskConfig |
| validateZoneConfig(state) | Validate a zone config (zone-matrix JSON shape) without side effects. Returns { errors, warnings, zones, active } |
| resolveZoneInfoFromConfig(state, src, dst) | Zone lookup for one flow against a zone config |
| ATTRIBUTE_DEFS | Zone attribute definitions |
| normalizeZoneAttributes(raw, { keyedBy, saveOrderNames, knownZones }) | Validate zone attributes. Returns { attributes, warnings } keyed by zone name. keyedBy is 'name', 'id' or 'auto' |
| convertLegacyZoneAttributes(idKeyedMap, zoneNamesInSaveOrder) | Convert legacy id-keyed (z1, z2, ...) attributes to name-keyed |
| ZONE_ATTRIBUTES_KEYED_BY | 'name': the key type of saved zone attributes |
| ALL_RULES, ACTIVE_RULES, isDormantRule(ruleOrId) | Rule registry. ACTIVE_RULES excludes dormant (not evaluated) rules |
| parseFlowCSV(text, { rowLimit }) | Parse a flow CSV (source, destination, protocol, port, optional purpose) |
| readCSVRecords(text, delimiter, { skipComments }), isHeaderRecord(cells) | Lower-level CSV reading |
| escapeCSVCell(value), neutralizeFormula(value) | CSV output escaping with spreadsheet-formula neutralization (OWASP CSV injection) |
| RESULTS_CSV_COLUMNS | Column order of the Firewall Rule Check results CSV |
License
MIT
