@aiwg/flue 2026.11.2 → 2026.11.4
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/package.json +9 -1
- package/skills/address-issues/SKILL.md +30 -24
- package/skills/address-issues/references/milestone.md +208 -0
- package/skills/address-issues/scripts/milestone-plan.mjs +109 -0
- package/skills/aiwg-issue/SKILL.md +18 -0
- package/skills/aiwg-pr/SKILL.md +18 -0
- package/skills/aiwg-refresh/SKILL.md +3 -0
- package/skills/aiwg-utils-quickref/SKILL.md +7 -0
- package/skills/commit-and-push/SKILL.md +18 -0
- package/skills/exposure-analysis/SKILL.md +144 -0
- package/skills/exposure-analysis/SKILL.md.d.ts +3 -0
- package/skills/exposure-analysis/scripts/analyze.mjs +133 -0
- package/skills/exposure-analysis/scripts/firewall.mjs +113 -0
- package/skills/forensics-quickref/SKILL.md +17 -0
- package/skills/host-hardening/SKILL.md +150 -0
- package/skills/host-hardening/SKILL.md.d.ts +3 -0
- package/skills/host-hardening/scripts/bindings.mjs +48 -0
- package/skills/host-hardening/scripts/check.mjs +71 -0
- package/skills/issue-create/SKILL.md +5 -5
- package/skills/sdlc-quickref/SKILL.md +7 -0
- package/skills/security-engineering-quickref/SKILL.md +20 -0
- package/skills/use/SKILL.md +3 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
namespace: aiwg
|
|
3
|
+
name: exposure-analysis
|
|
4
|
+
platforms: [flue]
|
|
5
|
+
description: Read-only firewall analysis and effective host exposure reconstruction for Docker published ports, UFW bypass, stale rules, CDN scope, IPv6 asymmetry and external probe allowlists.
|
|
6
|
+
triggers:
|
|
7
|
+
- "firewall analysis"
|
|
8
|
+
- "docker published ports"
|
|
9
|
+
- "what is reachable from the internet"
|
|
10
|
+
- "reconstruct host exposure"
|
|
11
|
+
tools: Read, Bash, Write
|
|
12
|
+
requires:
|
|
13
|
+
- operator-named host and authorized local or SSH read-only collection
|
|
14
|
+
- sanitized timestamped listener, Docker and firewall captures
|
|
15
|
+
ensures:
|
|
16
|
+
- effective exposure report with evidence hashes, limitations and pass/fail/unknown summary
|
|
17
|
+
invariants:
|
|
18
|
+
- never changes host firewall rules, services, containers or credentials
|
|
19
|
+
- unknown or incomplete evidence never proves a port closed
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
# Exposure Analysis
|
|
23
|
+
|
|
24
|
+
## Purpose
|
|
25
|
+
|
|
26
|
+
Relate listener inventory from `sys-host-audit` / Sys Host Profiler to host
|
|
27
|
+
firewall and Docker paths. Explain why a port is exposed, rather than trusting
|
|
28
|
+
`ufw status`. Use `container-forensics` for compromise indicators. This skill
|
|
29
|
+
produces reports and recommendations only, locally or over explicitly authorized
|
|
30
|
+
SSH. Do not install tools, elevate privileges, alter rules or probe unnamed hosts.
|
|
31
|
+
|
|
32
|
+
## Triggers
|
|
33
|
+
|
|
34
|
+
- "firewall analysis"
|
|
35
|
+
- "docker published ports"
|
|
36
|
+
- "UFW says closed but Docker publishes it"
|
|
37
|
+
- "CDN origin exposure" / "stale firewall rules"
|
|
38
|
+
|
|
39
|
+
## Behavior
|
|
40
|
+
|
|
41
|
+
1. Confirm host, interface/address inventory, capture time in UTC, permitted
|
|
42
|
+
collection scope and artifact destination (`aiwg artifacts path --json --check-write`).
|
|
43
|
+
Load `evidence-integrity`, `non-destructive`, `ops-safety` and
|
|
44
|
+
`ops-information-governance` before collection. Keep this workflow read-only
|
|
45
|
+
even when a caller asks to fix findings.
|
|
46
|
+
2. Reuse the existing host inventory when available. Within authorized scope,
|
|
47
|
+
collect bounded metadata using `ss -ltnup`, `ip -j address show`,
|
|
48
|
+
`iptables-save`, `ip6tables-save`, `ufw status numbered`,
|
|
49
|
+
`nft -j list ruleset` or `firewall-cmd --list-all-zones` as applicable.
|
|
50
|
+
Review runtime and persistent firewalld configuration separately. Record
|
|
51
|
+
permission failures as UNKNOWN; never interpret a failed command as no rules.
|
|
52
|
+
For SSH use the operator-named host with batch mode and a bounded connect
|
|
53
|
+
timeout; no fleet expansion or private configuration searches.
|
|
54
|
+
3. Narrow Docker inspection to Name, NetworkMode, PortBindings,
|
|
55
|
+
NetworkSettings.Ports and Networks. NEVER capture full `docker inspect`,
|
|
56
|
+
process environments, datastore secrets, private keys or container Env.
|
|
57
|
+
Route collected bytes through the existing information-governance boundary
|
|
58
|
+
before terminal, artifact or report emission. Operator-held raw evidence is
|
|
59
|
+
hashed at acquisition; sanitized derivatives have separate hashes and custody
|
|
60
|
+
links. The helper only accepts already sanitized snapshots.
|
|
61
|
+
4. Classify every listener by address family, protocol and bind scope:
|
|
62
|
+
loopback, private, named VPN address, all interfaces, public or unknown.
|
|
63
|
+
Record owning process/PID from ss and correlate its unit/container using
|
|
64
|
+
approved inventory metadata. Missing process/unit ownership stays unknown.
|
|
65
|
+
5. Trace new inbound traffic in actual rule order. Docker rootful bridge traffic
|
|
66
|
+
normally traverses PREROUTING DNAT → FORWARD → DOCKER-USER → DOCKER.
|
|
67
|
+
INPUT/UFW denies do not protect this forwarding path. Include earlier raw,
|
|
68
|
+
mangle and native nft hooks, interface matches, conntrack and default policies.
|
|
69
|
+
Record each rule's listener/publish match; flag missing bind addresses, empty
|
|
70
|
+
DOCKER-USER guards, unused allows, earlier covering terminal rules, public-IP
|
|
71
|
+
allow-all and CDN ranges permitting ports beyond the reviewed 80/443 scope.
|
|
72
|
+
A stale rule is a review candidate: check socket activation, maintenance and
|
|
73
|
+
standby services before recommending removal.
|
|
74
|
+
6. Review IPv4 and IPv6 independently, including IPv6 Docker publishing,
|
|
75
|
+
wildcard dual-stack sockets and differing defaults. Different family rules
|
|
76
|
+
are a review signal, not proof of equivalent reachability. Never infer IPv6
|
|
77
|
+
closure from an IPv4-only capture.
|
|
78
|
+
7. External verification is optional and requires the operator to name the
|
|
79
|
+
vantage, source addresses, target and bounded port set. Compare the probe's
|
|
80
|
+
actual public egress/NAT source to all source allowlists, including CDN/VPN
|
|
81
|
+
and both address families. If the source matches an allow rule, explicitly
|
|
82
|
+
warn that a closed result proves nothing about ordinary internet sources.
|
|
83
|
+
A clean probe is still limited to that vantage/protocol/time. The helper
|
|
84
|
+
consumes supplied results; it never launches probes.
|
|
85
|
+
8. Hash-check evidence before analysis and again before report finalization.
|
|
86
|
+
Include capture times, commands, collection failures, custody links and
|
|
87
|
+
rule paths. For "reachable on date X", use dated config history/backups
|
|
88
|
+
with their own hashes and distinguish reconstructed historical configuration
|
|
89
|
+
from observed reachability; today's captures cannot establish past exposure.
|
|
90
|
+
|
|
91
|
+
## Offline helper
|
|
92
|
+
|
|
93
|
+
Run the bundled helper against an operator-supplied JSON snapshot:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
node "$AIWG_ROOT/agentic/code/frameworks/forensics-complete/skills/exposure-analysis/scripts/analyze.mjs" --snapshot sanitized-snapshot.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Required metadata: `host`, `capturedAt` (ISO UTC). Capture fields are strings:
|
|
100
|
+
`ss`, `docker` (JSON array of narrowed inspect records), `iptables4`,
|
|
101
|
+
`iptables6`, `ufw`. Supply `ingressInterface`, `vpnAddresses`, `cdnRanges`
|
|
102
|
+
(operator-reviewed CIDRs), and `hashes` mapping capture names to acquisition
|
|
103
|
+
SHA-256 values. Omitted hashes are explicitly unverified; a supplied mismatch
|
|
104
|
+
stops analysis. Optional `external` entries contain `source`, `port`, `protocol`,
|
|
105
|
+
`result`, capture time and vantage identity.
|
|
106
|
+
|
|
107
|
+
The helper supports ordered iptables/ip6tables filter and DNAT paths with
|
|
108
|
+
simple source/destination, protocol, port, interface and NEW-state selectors.
|
|
109
|
+
Unsupported selectors/chains, extra hook tables, native nftables/firewalld,
|
|
110
|
+
rootless/userland proxies and routed/host networks require manual analysis;
|
|
111
|
+
helper verdicts remain UNKNOWN. A host-path verdict never establishes upstream
|
|
112
|
+
internet routing or cloud controls. Do not represent the helper as a complete
|
|
113
|
+
Linux firewall evaluator. Cloud/Kubernetes controls are out of scope; attach
|
|
114
|
+
separately reviewed adapter findings to the existing network-audit report.
|
|
115
|
+
|
|
116
|
+
## Examples
|
|
117
|
+
|
|
118
|
+
Input: `-p 6379:6379`, UFW deny 6379, matching DNAT and forwarding accepts,
|
|
119
|
+
empty DOCKER-USER. Output: **internet-reachable via Docker** on the captured
|
|
120
|
+
host path; `docker-ufw-bypass`, `missing-bind`, `empty-docker-user` findings.
|
|
121
|
+
A DOCKER-USER DROP before the Docker accept instead reports the captured path
|
|
122
|
+
blocked. An unused 5432 allow is stale; a CDN source allowing all ports is
|
|
123
|
+
`over-broad-cdn`. See sanitized fixtures in `test/fixtures/host-exposure/`.
|
|
124
|
+
|
|
125
|
+
## Output and recurring checks
|
|
126
|
+
|
|
127
|
+
Use the existing `network-audit-report` template for the human report, storing
|
|
128
|
+
it under the resolved `.aiwg/forensics/reports/` and evidence/custody under
|
|
129
|
+
`.aiwg/forensics/evidence/`. The helper writes JSON only to stdout; caller owns
|
|
130
|
+
sanitization and artifact routing. Include a compact operations-log record:
|
|
131
|
+
`host, capturedAt, status, failed, unknown, report reference`.
|
|
132
|
+
Exit codes: 0 PASS, 2 FAIL, 3 UNKNOWN, 1 input/integrity error. Alert on any
|
|
133
|
+
nonzero result, not only FAIL. Post-deploy and monthly callers use existing
|
|
134
|
+
operator scheduling; every run needs fresh captures. No timer or service is
|
|
135
|
+
installed by this skill.
|
|
136
|
+
|
|
137
|
+
## References
|
|
138
|
+
|
|
139
|
+
- ../../rules/evidence-integrity.md
|
|
140
|
+
- ../../rules/non-destructive.md
|
|
141
|
+
- ../../../ops-complete/rules/ops-safety.md
|
|
142
|
+
- ../container-forensics/SKILL.md
|
|
143
|
+
- ../../../../extensions/net/templates/network-audit-report.md
|
|
144
|
+
- ../../../security-engineering/skills/host-hardening/SKILL.md
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Reconstruct exposure from operator-supplied sanitized captures without host access.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { isIP } from 'node:net';
|
|
6
|
+
import { inRange, scope, parseFirewall, trace, listeners } from './firewall.mjs';
|
|
7
|
+
|
|
8
|
+
export function analyze(data) {
|
|
9
|
+
if (!data.host || !Number.isFinite(Date.parse(data.capturedAt))) throw new Error('host and ISO capturedAt are required');
|
|
10
|
+
const findings = [];
|
|
11
|
+
const add = (code, detail, extra = {}) => findings.push({ code, detail, ...extra });
|
|
12
|
+
const evidence = {};
|
|
13
|
+
for (const key of ['ss', 'docker', 'iptables4', 'iptables6', 'ufw', 'nftables', 'firewalld']) {
|
|
14
|
+
if (typeof data[key] === 'string') {
|
|
15
|
+
const sha256 = createHash('sha256').update(data[key]).digest('hex');
|
|
16
|
+
if (data.hashes?.[key] && data.hashes[key] !== sha256) throw new Error(`Integrity mismatch for ${key}`);
|
|
17
|
+
evidence[key] = { sha256, verification: data.hashes?.[key] ? 'matched supplied collection hash' : 'collection hash not supplied' };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const sockets = listeners(data.ss, data.vpnAddresses ?? []);
|
|
21
|
+
const firewalls = { 4: parseFirewall(data.iptables4, 4), 6: parseFirewall(data.iptables6, 6) };
|
|
22
|
+
const rules = Object.values(firewalls).flatMap(firewall => firewall.rules);
|
|
23
|
+
for (const [key, code] of [['ss', 'missing-listener-evidence'], ['docker', 'missing-docker-evidence'],
|
|
24
|
+
['iptables4', 'missing-ipv4-evidence'], ['iptables6', 'missing-ipv6-evidence']]) {
|
|
25
|
+
if (!data[key]) add(code, `${key} unavailable; absence is not proof of closure`);
|
|
26
|
+
}
|
|
27
|
+
if (data.nftables || data.firewalld) add('manual-backend-review', 'Native nftables/firewalld order and hook priorities need manual correlation; automated verdicts are unknown');
|
|
28
|
+
const containers = JSON.parse(data.docker ?? '[]');
|
|
29
|
+
const exposures = [];
|
|
30
|
+
for (const container of containers) {
|
|
31
|
+
for (const [containerPort, bindings] of Object.entries(container.NetworkSettings?.Ports ?? {})) {
|
|
32
|
+
if (!bindings) continue;
|
|
33
|
+
const [targetPort, protocol] = containerPort.split('/');
|
|
34
|
+
for (const binding of bindings) {
|
|
35
|
+
const address = binding.HostIp ?? '';
|
|
36
|
+
const family = isIP(address) || 4;
|
|
37
|
+
const port = Number(binding.HostPort);
|
|
38
|
+
const firewall = firewalls[family];
|
|
39
|
+
const bindScope = scope(address, data.vpnAddresses ?? []);
|
|
40
|
+
const requested = container.HostConfig?.PortBindings?.[containerPort] ?? [];
|
|
41
|
+
if (!address || requested.some(entry => !entry.HostIp)) add('missing-bind', 'Publish omitted a bind address', { port, family });
|
|
42
|
+
const guard = firewall.tables.filter?.['DOCKER-USER'];
|
|
43
|
+
if (!guard || guard.rules.every(rule => rule.target === 'RETURN')) add('empty-docker-user', 'DOCKER-USER has no effective guard', { family, port });
|
|
44
|
+
const packet = { port, protocol, source: '*', destination: scope(address) === 'all-interfaces' ? '*' : address, input: data.ingressInterface };
|
|
45
|
+
const nat = trace(firewall, 'nat', 'PREROUTING', packet);
|
|
46
|
+
const translated = nat.rule?.dnat?.match(/^(?:\[([^\]]+)\]|([^:]+)):(\d+)$/);
|
|
47
|
+
const destination = translated?.[1] ?? translated?.[2];
|
|
48
|
+
const networkAddresses = Object.values(container.NetworkSettings?.Networks ?? {}).flatMap(network => [network.IPAddress, network.GlobalIPv6Address]);
|
|
49
|
+
const forward = trace(firewall, 'filter', 'FORWARD', { ...packet, destination, port: Number(translated?.[3]) });
|
|
50
|
+
let verdict = 'unknown';
|
|
51
|
+
const unsupported = data.nftables || data.firewalld || Object.keys(firewall.tables).some(table => !['filter', 'nat'].includes(table));
|
|
52
|
+
if (!unsupported && nat.verdict === 'DNAT' && Number(translated?.[3]) === Number(targetPort) && networkAddresses.includes(destination)) {
|
|
53
|
+
if (['DROP', 'REJECT'].includes(forward.verdict)) verdict = 'blocked on captured host path';
|
|
54
|
+
if (forward.verdict === 'ACCEPT' && ['all-interfaces', 'public'].includes(bindScope)) verdict = 'internet-reachable via Docker';
|
|
55
|
+
if (forward.verdict === 'ACCEPT' && ['private', 'vpn', 'loopback'].includes(bindScope)) verdict = 'restricted bind; routing requires review';
|
|
56
|
+
}
|
|
57
|
+
const entry = { container: container.Name, port, protocol, address, family, scope: bindScope,
|
|
58
|
+
verdict, path: [...nat.path, ...forward.path], limitation: 'Captured host path only; upstream routing and cloud controls unverified' };
|
|
59
|
+
exposures.push(entry);
|
|
60
|
+
const input = trace(firewall, 'filter', 'INPUT', packet);
|
|
61
|
+
const ufwDeny = (data.ufw ?? '').split('\n').some(line => new RegExp(`^${port}(?:/${protocol})?\\s+DENY`).test(line));
|
|
62
|
+
if (verdict === 'internet-reachable via Docker' && (ufwDeny || ['DROP', 'REJECT'].includes(input.verdict))) {
|
|
63
|
+
add('docker-ufw-bypass', 'UFW/INPUT deny is bypassed by Docker DNAT and FORWARD', { port, family });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const rule of rules) {
|
|
69
|
+
if (rule.target === 'ACCEPT' && rule.port && /^\d+$/.test(rule.port) && rule.chain === 'INPUT' && data.ss) {
|
|
70
|
+
const active = sockets.some(socket => (socket.family === rule.family || socket.family === 0) && socket.port === Number(rule.port)
|
|
71
|
+
&& (!rule.protocol || socket.protocol === rule.protocol));
|
|
72
|
+
const published = exposures.some(entry => entry.family === rule.family && entry.port === Number(rule.port));
|
|
73
|
+
if (!active && !published) add('stale-rule', 'No captured listener or publish; validate standby/activation before removal', { port: Number(rule.port), family: rule.family, rule: rule.raw });
|
|
74
|
+
}
|
|
75
|
+
if (rule.target === 'ACCEPT' && rule.source && !rule.port && !rule.unknown) {
|
|
76
|
+
if ((data.cdnRanges ?? []).includes(rule.source)) add('over-broad-cdn', 'CDN source range permits all ports; recommend reviewed 80/443 scope', { rule: rule.raw });
|
|
77
|
+
else if (['public', 'all-interfaces'].includes(scope(rule.source.split('/')[0]))) add('over-broad-source', 'Public source permits all ports', { rule: rule.raw });
|
|
78
|
+
}
|
|
79
|
+
const chainRules = firewalls[rule.family].tables[rule.table][rule.chain].rules;
|
|
80
|
+
const earlier = chainRules.slice(0, chainRules.indexOf(rule));
|
|
81
|
+
const selectors = ['source', 'destination', 'protocol', 'port', 'input', 'output', 'state', 'dstType'];
|
|
82
|
+
if (!rule.unknown && earlier.some(first => !first.unknown && ['ACCEPT', 'DROP', 'REJECT'].includes(first.target)
|
|
83
|
+
&& selectors.every(key => !first[key] || first[key] === rule[key]))) add('shadowed-rule', 'Earlier terminal rule covers these selectors', { family: rule.family, rule: rule.raw });
|
|
84
|
+
}
|
|
85
|
+
if (data.iptables4 && data.iptables6) {
|
|
86
|
+
const signature = family => JSON.stringify({ policy: firewalls[family].tables.filter?.INPUT?.policy,
|
|
87
|
+
rules: rules.filter(rule => rule.family === family && rule.table === 'filter').map(rule => rule.raw) });
|
|
88
|
+
if (signature(4) !== signature(6)) add('v4-v6-asymmetry', 'IPv4/IPv6 policy or rule coverage differs; review family-specific listener reachability');
|
|
89
|
+
}
|
|
90
|
+
const hostExposures = sockets.flatMap(socket => {
|
|
91
|
+
const families = socket.family ? [socket.family] : [4, 6];
|
|
92
|
+
return families.map(family => {
|
|
93
|
+
const firewall = firewalls[family];
|
|
94
|
+
const packet = { port: socket.port, protocol: socket.protocol, source: '*',
|
|
95
|
+
destination: socket.scope === 'all-interfaces' ? '*' : socket.address, input: data.ingressInterface };
|
|
96
|
+
const result = trace(firewall, 'filter', 'INPUT', packet);
|
|
97
|
+
const unsupported = data.nftables || data.firewalld || Object.keys(firewall.tables).some(table => !['filter', 'nat'].includes(table));
|
|
98
|
+
const verdict = unsupported ? 'unknown' : ['loopback', 'vpn', 'private'].includes(socket.scope) ? 'restricted bind; routing requires review'
|
|
99
|
+
: result.verdict === 'ACCEPT' ? 'accepted on captured host path'
|
|
100
|
+
: ['DROP', 'REJECT'].includes(result.verdict) ? 'blocked on captured host path' : 'unknown';
|
|
101
|
+
return { ...socket, family, verdict, path: result.path };
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
const policies = Object.entries(firewalls).flatMap(([family, firewall]) => Object.entries(firewall.tables).flatMap(([table, chains]) =>
|
|
105
|
+
Object.entries(chains).filter(([, body]) => body.policy !== '-').map(([chain, body]) =>
|
|
106
|
+
({ family: Number(family), table, chain, type: 'policy', target: body.policy }))));
|
|
107
|
+
const mappedRules = rules.map(rule => ({ ...rule, listenerMatches: sockets.filter(socket =>
|
|
108
|
+
(socket.family === rule.family || !socket.family) && (!rule.port || Number(rule.port) === socket.port)
|
|
109
|
+
&& (!rule.protocol || rule.protocol === socket.protocol)).map(socket => `${socket.address}:${socket.port}/${socket.protocol}`) }));
|
|
110
|
+
const external = (data.external ?? []).map(probe => {
|
|
111
|
+
const family = isIP(probe.source);
|
|
112
|
+
const allow = rules.find(rule => rule.family === family && rule.target === 'ACCEPT' && rule.source
|
|
113
|
+
&& !['0.0.0.0/0', '::/0'].includes(rule.source) && inRange(probe.source, rule.source));
|
|
114
|
+
if (allow) add('allowlisted-vantage', 'Probe source matches an allowlist; external coverage is unrepresentative', { family, port: probe.port });
|
|
115
|
+
return { ...probe, provesClosed: false, reason: allow
|
|
116
|
+
? 'Probe source matches an allowlist; closed result proves nothing about ordinary internet sources'
|
|
117
|
+
: 'Result is limited to this vantage, protocol, port and capture time; it cannot prove general closure' };
|
|
118
|
+
});
|
|
119
|
+
const unknown = findings.filter(finding => /missing-.*evidence|manual-backend/.test(finding.code)).length + exposures.filter(entry => entry.verdict === 'unknown').length;
|
|
120
|
+
const failed = findings.length - findings.filter(finding => /missing-.*evidence|manual-backend/.test(finding.code)).length;
|
|
121
|
+
return { host: data.host, capturedAt: data.capturedAt, mode: 'read-only', evidence,
|
|
122
|
+
listeners: sockets, rules: [...mappedRules, ...policies], exposures, hostExposures, findings, external,
|
|
123
|
+
summary: { status: failed ? 'FAIL' : unknown ? 'UNKNOWN' : 'PASS', failed, unknown } };
|
|
124
|
+
}
|
|
125
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
126
|
+
try {
|
|
127
|
+
const args = process.argv.slice(2);
|
|
128
|
+
if (args.length !== 2 || args[0] !== '--snapshot') throw new Error('Usage: analyze.mjs --snapshot sanitized-snapshot.json');
|
|
129
|
+
const report = analyze(JSON.parse(readFileSync(args[1], 'utf8')));
|
|
130
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
131
|
+
process.exitCode = report.summary.status === 'FAIL' ? 2 : report.summary.status === 'UNKNOWN' ? 3 : 0;
|
|
132
|
+
} catch (error) { process.stderr.write(`${error.message}\n`); process.exitCode = 1; }
|
|
133
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Parse captured iptables rules and conservatively trace a new inbound packet.
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
|
+
|
|
4
|
+
function addressNumber(address) {
|
|
5
|
+
if (isIP(address) === 4) return address.split('.').reduce((n, part) => (n << 8n) + BigInt(part), 0n);
|
|
6
|
+
if (isIP(address) !== 6) return undefined;
|
|
7
|
+
let text = address;
|
|
8
|
+
if (text.includes('.')) {
|
|
9
|
+
const split = text.lastIndexOf(':');
|
|
10
|
+
const v4 = addressNumber(text.slice(split + 1));
|
|
11
|
+
text = `${text.slice(0, split)}:${(v4 >> 16n).toString(16)}:${(v4 & 65535n).toString(16)}`;
|
|
12
|
+
}
|
|
13
|
+
const halves = text.split('::');
|
|
14
|
+
const left = halves[0] ? halves[0].split(':') : [];
|
|
15
|
+
const right = halves[1] ? halves[1].split(':') : [];
|
|
16
|
+
const groups = halves.length === 2 ? [...left, ...Array(8 - left.length - right.length).fill('0'), ...right] : left;
|
|
17
|
+
return groups.reduce((n, group) => (n << 16n) + BigInt(`0x${group}`), 0n);
|
|
18
|
+
}
|
|
19
|
+
export function inRange(address, cidr) {
|
|
20
|
+
const [base, mask] = cidr.split('/');
|
|
21
|
+
const family = isIP(base);
|
|
22
|
+
if (!family || isIP(address) !== family) return false;
|
|
23
|
+
const bits = family === 4 ? 32 : 128;
|
|
24
|
+
const prefix = mask === undefined ? bits : Number(mask);
|
|
25
|
+
if (!Number.isInteger(prefix) || prefix < 0 || prefix > bits) return false;
|
|
26
|
+
const shift = BigInt(bits - prefix);
|
|
27
|
+
return addressNumber(address) >> shift === addressNumber(base) >> shift;
|
|
28
|
+
}
|
|
29
|
+
export function scope(address, vpn = []) {
|
|
30
|
+
if (vpn.includes(address)) return 'vpn';
|
|
31
|
+
if (['*', '0.0.0.0', '::', ''].includes(address)) return 'all-interfaces';
|
|
32
|
+
if (inRange(address, '127.0.0.0/8') || address === '::1') return 'loopback';
|
|
33
|
+
if (['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '169.254.0.0/16', 'fc00::/7', 'fe80::/10'].some(range => inRange(address, range))) return 'private';
|
|
34
|
+
return isIP(address) ? 'public' : 'unknown';
|
|
35
|
+
}
|
|
36
|
+
export function parseFirewall(raw, family) {
|
|
37
|
+
const tables = {};
|
|
38
|
+
const rules = [];
|
|
39
|
+
let table;
|
|
40
|
+
for (const line of (raw ?? '').split('\n')) {
|
|
41
|
+
if (line.startsWith('*')) { table = line.slice(1); tables[table] = {}; }
|
|
42
|
+
if (line.startsWith(':') && table) {
|
|
43
|
+
const [name, policy] = line.slice(1).split(/\s+/);
|
|
44
|
+
tables[table][name] = { policy, rules: [] };
|
|
45
|
+
}
|
|
46
|
+
if (!line.startsWith('-A ') || !table) continue;
|
|
47
|
+
const tokens = line.match(/"[^"]*"|\S+/g) ?? [];
|
|
48
|
+
const rule = { family, table, chain: tokens[1], raw: line, unknown: false };
|
|
49
|
+
for (let i = 2; i < tokens.length; i++) {
|
|
50
|
+
const token = tokens[i];
|
|
51
|
+
const fields = { '-s': 'source', '-d': 'destination', '-p': 'protocol', '--dport': 'port',
|
|
52
|
+
'-j': 'target', '--to-destination': 'dnat', '-i': 'input', '-o': 'output', '--ctstate': 'state', '--dst-type': 'dstType' };
|
|
53
|
+
if (fields[token]) rule[fields[token]] = tokens[++i];
|
|
54
|
+
else if (token === '-m') { if (!['tcp', 'udp', 'conntrack', 'addrtype', 'comment'].includes(tokens[++i])) rule.unknown = true; }
|
|
55
|
+
else if (token === '--comment') i++;
|
|
56
|
+
else rule.unknown = true;
|
|
57
|
+
}
|
|
58
|
+
if (!tables[table][rule.chain]) tables[table][rule.chain] = { policy: '-', rules: [] };
|
|
59
|
+
tables[table][rule.chain].rules.push(rule);
|
|
60
|
+
rules.push(rule);
|
|
61
|
+
}
|
|
62
|
+
return { tables, rules };
|
|
63
|
+
}
|
|
64
|
+
function match(rule, packet) {
|
|
65
|
+
let unknown = rule.unknown;
|
|
66
|
+
for (const key of ['source', 'destination']) {
|
|
67
|
+
if (!rule[key] || ['0.0.0.0/0', '::/0'].includes(rule[key])) continue;
|
|
68
|
+
if (!packet[key] || packet[key] === '*') unknown = true;
|
|
69
|
+
else if (!inRange(packet[key], rule[key])) return false;
|
|
70
|
+
}
|
|
71
|
+
if (rule.protocol && rule.protocol !== 'all' && rule.protocol !== packet.protocol) return false;
|
|
72
|
+
if (rule.port) {
|
|
73
|
+
if (!/^\d+$/.test(rule.port)) unknown = true;
|
|
74
|
+
else if (Number(rule.port) !== packet.port) return false;
|
|
75
|
+
}
|
|
76
|
+
for (const key of ['input', 'output']) {
|
|
77
|
+
if (!rule[key]) continue;
|
|
78
|
+
if (!packet[key]) unknown = true;
|
|
79
|
+
else if (rule[key] !== packet[key]) return false;
|
|
80
|
+
}
|
|
81
|
+
if (rule.state && !rule.state.split(',').includes('NEW')) return false;
|
|
82
|
+
if (rule.dstType && rule.dstType !== 'LOCAL') unknown = true;
|
|
83
|
+
return unknown ? 'unknown' : true;
|
|
84
|
+
}
|
|
85
|
+
export function trace(firewall, table, chain, packet, seen = []) {
|
|
86
|
+
const name = `${table}/${chain}`;
|
|
87
|
+
const path = [name];
|
|
88
|
+
const body = firewall.tables[table]?.[chain];
|
|
89
|
+
if (!body || seen.includes(name)) return { verdict: 'UNKNOWN', path };
|
|
90
|
+
for (const rule of body.rules) {
|
|
91
|
+
const matches = match(rule, packet);
|
|
92
|
+
if (matches === false) continue;
|
|
93
|
+
if (matches === 'unknown') return { verdict: 'UNKNOWN', path };
|
|
94
|
+
const target = rule.target;
|
|
95
|
+
if (['ACCEPT', 'DROP', 'REJECT', 'RETURN', 'DNAT'].includes(target)) return { verdict: target, path, rule };
|
|
96
|
+
if (['LOG', 'NFLOG'].includes(target)) continue;
|
|
97
|
+
const nested = trace(firewall, table, target, packet, [...seen, name]);
|
|
98
|
+
path.push(...nested.path);
|
|
99
|
+
if (nested.verdict !== 'RETURN') return { ...nested, path };
|
|
100
|
+
}
|
|
101
|
+
return { verdict: body.policy === '-' ? 'RETURN' : body.policy, path };
|
|
102
|
+
}
|
|
103
|
+
export function listeners(raw, vpn) {
|
|
104
|
+
return (raw ?? '').split('\n').flatMap(line => {
|
|
105
|
+
const columns = line.trim().split(/\s+/);
|
|
106
|
+
if (!['tcp', 'udp'].includes(columns[0]) || !['LISTEN', 'UNCONN'].includes(columns[1])) return [];
|
|
107
|
+
const endpoint = columns[4]?.match(/^(?:\[([^\]]+)\]|(.+)):(\d+)$/);
|
|
108
|
+
if (!endpoint) return [];
|
|
109
|
+
const address = endpoint[1] ?? endpoint[2];
|
|
110
|
+
return [{ protocol: columns[0], address, port: Number(endpoint[3]), family: isIP(address) || 0,
|
|
111
|
+
scope: scope(address, vpn), owner: line.match(/users:\(\((.*)\)\)/)?.[1] ?? 'unknown' }];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -46,6 +46,8 @@ Digital forensics & incident response. RFC 3227-aligned triage, multi-source tim
|
|
|
46
46
|
| **Threat hunting** | Sigma rule application across log sources |
|
|
47
47
|
| **Reporting** | Investigation reports with evidence, timeline reconstruction |
|
|
48
48
|
|
|
49
|
+
| **Host exposure** | Listener/firewall/Docker correlation, stale and over-broad rules, IPv6 and probe allowlists |
|
|
50
|
+
|
|
49
51
|
## Curated discovery phrases
|
|
50
52
|
|
|
51
53
|
### Triage & acquisition
|
|
@@ -67,6 +69,21 @@ aiwg discover "container forensics" # → container-forensics
|
|
|
67
69
|
aiwg discover "supply chain compromise" # → supply-chain-forensics
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
### Host exposure reconstruction
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
aiwg discover "firewall analysis" # → exposure-analysis
|
|
76
|
+
aiwg discover "docker published ports" # → exposure-analysis
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`exposure-analysis` is read-only. It correlates listeners, ordered host firewall
|
|
80
|
+
rules, Docker DNAT/FORWARD paths, IPv4/IPv6 and probe-source allowlists. The
|
|
81
|
+
bundled offline helper consumes sanitized captures and emits evidence hashes
|
|
82
|
+
plus PASS/FAIL/UNKNOWN summaries for post-deploy and monthly operator checks.
|
|
83
|
+
Unsupported native firewall semantics require manual review. Route preventive
|
|
84
|
+
baseline and remediation recommendations to `security-engineering/host-hardening`;
|
|
85
|
+
neither skill changes host firewall rules or services.
|
|
86
|
+
|
|
70
87
|
### Investigation orchestration
|
|
71
88
|
|
|
72
89
|
```bash
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
namespace: aiwg
|
|
3
|
+
name: host-hardening
|
|
4
|
+
platforms: [flue]
|
|
5
|
+
description: Read-only system hardening baseline and plan-first host hardening recommendations for SSH, Docker bind addresses, firewall persistence, datastores, exporters and audit retention.
|
|
6
|
+
triggers:
|
|
7
|
+
- "system hardening"
|
|
8
|
+
- "host hardening baseline"
|
|
9
|
+
- "plan host remediation"
|
|
10
|
+
- "check compose port bindings"
|
|
11
|
+
tools: Read, Bash, Write
|
|
12
|
+
requires:
|
|
13
|
+
- sanitized host baseline and operator-defined service health checks
|
|
14
|
+
ensures:
|
|
15
|
+
- baseline report with diff-style recommendations, backup plan, access gates and re-verification checklist
|
|
16
|
+
invariants:
|
|
17
|
+
- never changes host firewall rules or services, even with an apply request
|
|
18
|
+
- never collects secrets, SSH key material or datastore passwords
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Host Hardening
|
|
22
|
+
|
|
23
|
+
## Purpose
|
|
24
|
+
|
|
25
|
+
Review a Linux host after exposure reconstruction or as a recurring baseline.
|
|
26
|
+
Extend `security-assessment` with concrete host checks, using existing
|
|
27
|
+
`sys-host-audit` inventory and `exposure-analysis` findings. Recommendations
|
|
28
|
+
are plan-first and read-only under `ops-safety`: this skill never applies a
|
|
29
|
+
firewall, SSH, datastore or service change. `--apply` is rejected.
|
|
30
|
+
|
|
31
|
+
## Triggers
|
|
32
|
+
|
|
33
|
+
- "system hardening"
|
|
34
|
+
- "host hardening baseline"
|
|
35
|
+
- "lockout-safe SSH remediation plan"
|
|
36
|
+
- "compose ports without bind address"
|
|
37
|
+
|
|
38
|
+
## Behavior
|
|
39
|
+
|
|
40
|
+
1. Identify the operator-authorized host, timestamp, role and service owners.
|
|
41
|
+
Resolve report destination with `aiwg artifacts path --json --check-write`.
|
|
42
|
+
Apply `ops-information-governance` to collected metadata before emission.
|
|
43
|
+
Reuse sanitized inventory and exposure reports. Missing or restricted data
|
|
44
|
+
means UNKNOWN, never PASS. Do not read auth/token files, authorized_keys,
|
|
45
|
+
datastore passwords or environment values; operators provide safe boolean
|
|
46
|
+
assessments for sensitive controls.
|
|
47
|
+
2. Assess the baseline below, recording evidence references and exceptions.
|
|
48
|
+
Confirm effective sshd settings in relevant Match contexts, including
|
|
49
|
+
included files; checking one config line cannot establish effective policy.
|
|
50
|
+
3. Prepare a reviewable diff-style recommendation per failed control. Map
|
|
51
|
+
stale/over-broad firewall rule removal candidates to exact rule identifiers,
|
|
52
|
+
listeners, container publishing and named service owners. Specify public,
|
|
53
|
+
private or VPN binds for proposed Compose changes. Do not assume a standby
|
|
54
|
+
rule is disposable because the listener is currently absent.
|
|
55
|
+
4. Include dated backup requirements, pre-change SHA-256, verified restore
|
|
56
|
+
procedure and rollback deadline for every affected file/ruleset. Backups
|
|
57
|
+
stay in operator-controlled restricted storage, not in reports. The helper
|
|
58
|
+
produces backup instructions only; it never creates host backups.
|
|
59
|
+
5. Gate any separately performed SSH change on verified key-based access
|
|
60
|
+
(second session with intended account) AND verified console break-glass
|
|
61
|
+
access. A key file existing is insufficient. Require explicit operator
|
|
62
|
+
authorization for exact changes, `sshd -t` and effective Match review,
|
|
63
|
+
an open recovery session and timed rollback before password/root restriction.
|
|
64
|
+
Network, boot and authentication changes have at least HIGH blast radius.
|
|
65
|
+
6. Hand the plan to the operator for a separate authorized operational change.
|
|
66
|
+
Even explicit apply authorization does not make this read-only skill a
|
|
67
|
+
mutation tool. Do not run reload/restart, firewall writes or datastore DDL.
|
|
68
|
+
7. After the operator reports application, obtain fresh captures. Re-run
|
|
69
|
+
exposure analysis, SSH checks and the baseline. Re-verify listeners,
|
|
70
|
+
IPv4/IPv6 firewall, Docker forwarding/binds, a new key-based session and
|
|
71
|
+
every named health check (queue ready, monitoring targets still up, CDN
|
|
72
|
+
origin HTTP/HTTPS). Record failures and recommend rollback; never claim
|
|
73
|
+
verification from the pre-change snapshot. Missing results remain UNKNOWN.
|
|
74
|
+
|
|
75
|
+
## Baseline
|
|
76
|
+
|
|
77
|
+
| Area | Checks and safe metadata fields under `baseline` |
|
|
78
|
+
|---|---|
|
|
79
|
+
| SSH | `ssh.passwordAuthentication: no`, `permitRootLogin: no`, `maxAuthTries <= 3`, `caTrustReviewed`, `authorizedKeysFromRestricted` (from= review) |
|
|
80
|
+
| Firewall | `firewall.defaultDeny4`, `defaultDeny6`, `persistent` across reboot; compare runtime/persistent rules and default policy |
|
|
81
|
+
| Docker | `docker.userGuard`, `afterVpn` (readiness + startup/restart dependency), `liveRestore`, `explicitBinds` |
|
|
82
|
+
| Datastores | `datastores.authAcl`, `redisDangerousCommandsRestricted`, `postgresConnectionLogging`, `appRolesNotSuperuser` |
|
|
83
|
+
| Exporters | `exporters.privateBind`, `fixedTargets` (no caller-chosen multi-target scrapes) |
|
|
84
|
+
| Audit | `audit.rulesLoaded`, `retentionReviewed` (auditd rules, journal/rotation capacity and preservation) |
|
|
85
|
+
|
|
86
|
+
Boolean controls require `true` for PASS. Use `null`/omission for unknown,
|
|
87
|
+
not an assumed value; mark non-applicable controls with a documented operator
|
|
88
|
+
exception in the report. The helper leaves omitted controls UNKNOWN. Redis ACL
|
|
89
|
+
restrictions should deny dangerous commands for application users; do not
|
|
90
|
+
blindly rename commands or lock out maintenance/replication. Review SSH CA
|
|
91
|
+
principals and role privileges without exposing key or credential values.
|
|
92
|
+
|
|
93
|
+
## Offline helper and static check
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
node "$AIWG_ROOT/agentic/code/frameworks/security-engineering/skills/host-hardening/scripts/check.mjs" --snapshot baseline.json --compose compose.yaml
|
|
97
|
+
node "$AIWG_ROOT/agentic/code/frameworks/security-engineering/skills/host-hardening/scripts/check.mjs" --snapshot baseline.json --docker-run reviewed-commands.txt
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Snapshot requires `host`, `capturedAt`, optional `baseline` and `healthChecks`
|
|
101
|
+
(array of safe named checks). Compose parsing uses the existing YAML dependency.
|
|
102
|
+
Short and long syntax require explicit literal `host_ip`/bind addresses;
|
|
103
|
+
wildcards receive a separate review finding. Render interpolation and merged
|
|
104
|
+
Compose files through an operator-approved process before static checking;
|
|
105
|
+
never execute shell substitutions from files. `expose:` alone does not publish
|
|
106
|
+
host ports. Host networking and publish-all require explicit listener review.
|
|
107
|
+
The docker-run checker covers literal `-p`, `--publish`, `-P`; shell-generated,
|
|
108
|
+
multiline or computed commands require manual review.
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
Input: `PasswordAuthentication yes`, `PermitRootLogin yes`, six auth tries.
|
|
113
|
+
Output: failed SSH controls with `-PasswordAuthentication yes` /
|
|
114
|
+
`+PasswordAuthentication no`, dated operator-backup requirements, key and
|
|
115
|
+
console gates, explicit authorization and fresh-capture rechecks. Nothing is
|
|
116
|
+
changed. `--apply` fails with the read-only boundary explanation.
|
|
117
|
+
|
|
118
|
+
Input: Compose `ports: ["6379:6379"]` or long syntax without `host_ip`.
|
|
119
|
+
Output: `missing-bind`. `"10.8.0.2:6379:6379"` names the VPN bind;
|
|
120
|
+
`"[::1]:6379:6379"` names IPv6 loopback. `0.0.0.0` and `::` require public
|
|
121
|
+
service justification. An explicit address alone does not establish safety.
|
|
122
|
+
|
|
123
|
+
## Output and recurring checks
|
|
124
|
+
|
|
125
|
+
Write the sanitized report beneath resolved
|
|
126
|
+
`.aiwg/security-engineering/reviews/`. The helper emits JSON to stdout with
|
|
127
|
+
checks, findings, plan and `summary: {status, passed, failed, unknown}`.
|
|
128
|
+
Exit codes: 0 PASS, 2 FAIL, 3 UNKNOWN, 1 invalid input or prohibited apply.
|
|
129
|
+
Use existing operator scheduling for post-deploy and monthly checks; emit
|
|
130
|
+
`host, capturedAt, status, failed, unknown, report reference` to the operations
|
|
131
|
+
log and alert on nonzero status. This skill installs no schedules or services.
|
|
132
|
+
|
|
133
|
+
## Tool selection and limits
|
|
134
|
+
|
|
135
|
+
Suggested default: existing `ss`, Docker metadata and native firewall read
|
|
136
|
+
commands, with offline helper for reproducible narrow checks. Use nftables or
|
|
137
|
+
firewalld's native views when those own the host; review hook order manually
|
|
138
|
+
when the exposure helper reports unsupported semantics. Existing benchmark
|
|
139
|
+
reports may supply baseline evidence, with their scope and capture time.
|
|
140
|
+
For newer backend versions evaluate read-only behavior, both address families,
|
|
141
|
+
Docker integration and lockout recovery against sanitized fixtures before
|
|
142
|
+
trusting their results. No package vulnerability scanner is added here.
|
|
143
|
+
|
|
144
|
+
## References
|
|
145
|
+
|
|
146
|
+
- ../../rules/published-port-binding.md
|
|
147
|
+
- ../../../ops-complete/rules/ops-safety.md
|
|
148
|
+
- ../../../forensics-complete/skills/exposure-analysis/SKILL.md
|
|
149
|
+
- ../dfir-readiness/SKILL.md
|
|
150
|
+
- ../../docs/network-control-review.md
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Check Compose and docker run publishes without executing or rewriting them.
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import { isIP } from 'node:net';
|
|
4
|
+
|
|
5
|
+
function bindOf(value) {
|
|
6
|
+
if (typeof value === 'object' && value !== null) return value.host_ip;
|
|
7
|
+
const text = String(value).replace(/\/(tcp|udp|sctp)$/, '');
|
|
8
|
+
const ipv6 = text.match(/^\[([^\]]+)\]:[^:]+:[^:]+$/);
|
|
9
|
+
if (ipv6) return ipv6[1];
|
|
10
|
+
const parts = text.split(':');
|
|
11
|
+
return parts.length === 3 ? parts[0] : undefined;
|
|
12
|
+
}
|
|
13
|
+
function finding(value, location) {
|
|
14
|
+
const address = bindOf(value);
|
|
15
|
+
if (!address || !isIP(address)) return { code: 'missing-bind', location,
|
|
16
|
+
detail: 'Explicit literal bind address required; unresolved variables require rendered Compose review' };
|
|
17
|
+
if (['0.0.0.0', '::'].includes(address)) return { code: 'wildcard-bind', location,
|
|
18
|
+
detail: 'All-interface publish needs documented public-service justification and firewall review' };
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function checkCompose(text) {
|
|
22
|
+
const document = yaml.load(text);
|
|
23
|
+
if (!document || typeof document !== 'object' || !document.services) throw new Error('Compose services mapping required');
|
|
24
|
+
const findings = [];
|
|
25
|
+
for (const [name, service] of Object.entries(document.services)) {
|
|
26
|
+
if (!service || typeof service !== 'object') continue;
|
|
27
|
+
if (service.network_mode === 'host') findings.push({ code: 'host-network', location: name, detail: 'Host networking requires listener review; ports do not constrain it' });
|
|
28
|
+
if (service.ports !== undefined && !Array.isArray(service.ports)) throw new Error('Compose ports must be an array');
|
|
29
|
+
for (const [index, port] of (service.ports ?? []).entries()) {
|
|
30
|
+
const issue = finding(port, `services.${name}.ports[${index}]`);
|
|
31
|
+
if (issue) findings.push(issue);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return findings;
|
|
35
|
+
}
|
|
36
|
+
export function checkDockerRun(text) {
|
|
37
|
+
const findings = [];
|
|
38
|
+
for (const [index, line] of text.split('\n').entries()) {
|
|
39
|
+
// A bounded lexical check; shell expansion and generated commands require manual review.
|
|
40
|
+
const publishes = line.matchAll(/(?:^|\s)(?:-p\s*|--publish(?:=|\s+))('[^']*'|"[^"]*"|\S+)/g);
|
|
41
|
+
for (const match of publishes) {
|
|
42
|
+
const issue = finding(match[1].replace(/^['"]|['"]$/g, ''), `line ${index + 1}`);
|
|
43
|
+
if (issue) findings.push(issue);
|
|
44
|
+
}
|
|
45
|
+
if (/(?:^|\s)(?:-P|--publish-all)(?:\s|$)/.test(line)) findings.push({ code: 'missing-bind', location: `line ${index + 1}`, detail: 'Publish-all has no explicit bind address' });
|
|
46
|
+
}
|
|
47
|
+
return findings;
|
|
48
|
+
}
|