defense-mcp-server 0.9.3 â 0.9.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 +2 -2
- package/build/core/auto-installer.d.ts +0 -102
- package/build/core/auto-installer.d.ts.map +0 -1
- package/build/core/backup-manager.d.ts +0 -63
- package/build/core/backup-manager.d.ts.map +0 -1
- package/build/core/changelog.d.ts +0 -119
- package/build/core/changelog.d.ts.map +0 -1
- package/build/core/command-allowlist.d.ts +0 -129
- package/build/core/command-allowlist.d.ts.map +0 -1
- package/build/core/config.d.ts +0 -107
- package/build/core/config.d.ts.map +0 -1
- package/build/core/dependency-validator.d.ts +0 -106
- package/build/core/dependency-validator.d.ts.map +0 -1
- package/build/core/distro-adapter.d.ts +0 -172
- package/build/core/distro-adapter.d.ts.map +0 -1
- package/build/core/distro.d.ts +0 -57
- package/build/core/distro.d.ts.map +0 -1
- package/build/core/encrypted-state.d.ts +0 -69
- package/build/core/encrypted-state.d.ts.map +0 -1
- package/build/core/executor.d.ts +0 -65
- package/build/core/executor.d.ts.map +0 -1
- package/build/core/installer.d.ts +0 -129
- package/build/core/installer.d.ts.map +0 -1
- package/build/core/logger.d.ts +0 -118
- package/build/core/logger.d.ts.map +0 -1
- package/build/core/metrics.d.ts +0 -74
- package/build/core/metrics.d.ts.map +0 -1
- package/build/core/metrics.js +0 -97
- package/build/core/output-redactor.d.ts +0 -26
- package/build/core/output-redactor.d.ts.map +0 -1
- package/build/core/pam-utils.d.ts +0 -356
- package/build/core/pam-utils.d.ts.map +0 -1
- package/build/core/parsers.d.ts +0 -191
- package/build/core/parsers.d.ts.map +0 -1
- package/build/core/policy-engine.d.ts +0 -170
- package/build/core/policy-engine.d.ts.map +0 -1
- package/build/core/preflight.d.ts +0 -157
- package/build/core/preflight.d.ts.map +0 -1
- package/build/core/privilege-manager.d.ts +0 -108
- package/build/core/privilege-manager.d.ts.map +0 -1
- package/build/core/progress.d.ts +0 -99
- package/build/core/progress.d.ts.map +0 -1
- package/build/core/rate-limiter.d.ts +0 -101
- package/build/core/rate-limiter.d.ts.map +0 -1
- package/build/core/rollback.d.ts +0 -73
- package/build/core/rollback.d.ts.map +0 -1
- package/build/core/run-command.d.ts +0 -14
- package/build/core/run-command.d.ts.map +0 -1
- package/build/core/safeguards.d.ts +0 -58
- package/build/core/safeguards.d.ts.map +0 -1
- package/build/core/sanitizer.d.ts +0 -118
- package/build/core/sanitizer.d.ts.map +0 -1
- package/build/core/secure-fs.d.ts +0 -67
- package/build/core/secure-fs.d.ts.map +0 -1
- package/build/core/spawn-safe.d.ts +0 -55
- package/build/core/spawn-safe.d.ts.map +0 -1
- package/build/core/sudo-guard.d.ts +0 -167
- package/build/core/sudo-guard.d.ts.map +0 -1
- package/build/core/sudo-session.d.ts +0 -143
- package/build/core/sudo-session.d.ts.map +0 -1
- package/build/core/third-party-installer.d.ts +0 -58
- package/build/core/third-party-installer.d.ts.map +0 -1
- package/build/core/third-party-manifest.d.ts +0 -48
- package/build/core/third-party-manifest.d.ts.map +0 -1
- package/build/core/tool-annotations.d.ts +0 -13
- package/build/core/tool-annotations.d.ts.map +0 -1
- package/build/core/tool-dependencies.d.ts +0 -60
- package/build/core/tool-dependencies.d.ts.map +0 -1
- package/build/core/tool-durations.d.ts +0 -71
- package/build/core/tool-durations.d.ts.map +0 -1
- package/build/core/tool-registry.d.ts +0 -112
- package/build/core/tool-registry.d.ts.map +0 -1
- package/build/core/tool-wrapper.d.ts +0 -73
- package/build/core/tool-wrapper.d.ts.map +0 -1
- package/build/index.d.ts +0 -3
- package/build/index.d.ts.map +0 -1
- package/build/tools/access-control.d.ts +0 -11
- package/build/tools/access-control.d.ts.map +0 -1
- package/build/tools/api-security.d.ts +0 -12
- package/build/tools/api-security.d.ts.map +0 -1
- package/build/tools/app-hardening.d.ts +0 -11
- package/build/tools/app-hardening.d.ts.map +0 -1
- package/build/tools/backup.d.ts +0 -8
- package/build/tools/backup.d.ts.map +0 -1
- package/build/tools/cloud-security.d.ts +0 -17
- package/build/tools/cloud-security.d.ts.map +0 -1
- package/build/tools/compliance.d.ts +0 -11
- package/build/tools/compliance.d.ts.map +0 -1
- package/build/tools/container-security.d.ts +0 -14
- package/build/tools/container-security.d.ts.map +0 -1
- package/build/tools/deception.d.ts +0 -13
- package/build/tools/deception.d.ts.map +0 -1
- package/build/tools/dns-security.d.ts +0 -93
- package/build/tools/dns-security.d.ts.map +0 -1
- package/build/tools/ebpf-security.d.ts +0 -15
- package/build/tools/ebpf-security.d.ts.map +0 -1
- package/build/tools/encryption.d.ts +0 -12
- package/build/tools/encryption.d.ts.map +0 -1
- package/build/tools/firewall.d.ts +0 -9
- package/build/tools/firewall.d.ts.map +0 -1
- package/build/tools/hardening.d.ts +0 -8
- package/build/tools/hardening.d.ts.map +0 -1
- package/build/tools/incident-response.d.ts +0 -11
- package/build/tools/incident-response.d.ts.map +0 -1
- package/build/tools/integrity.d.ts +0 -15
- package/build/tools/integrity.d.ts.map +0 -1
- package/build/tools/logging.d.ts +0 -21
- package/build/tools/logging.d.ts.map +0 -1
- package/build/tools/malware.d.ts +0 -10
- package/build/tools/malware.d.ts.map +0 -1
- package/build/tools/meta.d.ts +0 -13
- package/build/tools/meta.d.ts.map +0 -1
- package/build/tools/network-defense.d.ts +0 -11
- package/build/tools/network-defense.d.ts.map +0 -1
- package/build/tools/patch-management.d.ts +0 -3
- package/build/tools/patch-management.d.ts.map +0 -1
- package/build/tools/process-security.d.ts +0 -12
- package/build/tools/process-security.d.ts.map +0 -1
- package/build/tools/secrets.d.ts +0 -8
- package/build/tools/secrets.d.ts.map +0 -1
- package/build/tools/sudo-management.d.ts +0 -17
- package/build/tools/sudo-management.d.ts.map +0 -1
- package/build/tools/supply-chain-security.d.ts +0 -8
- package/build/tools/supply-chain-security.d.ts.map +0 -1
- package/build/tools/threat-intel.d.ts +0 -22
- package/build/tools/threat-intel.d.ts.map +0 -1
- package/build/tools/vulnerability-management.d.ts +0 -11
- package/build/tools/vulnerability-management.d.ts.map +0 -1
- package/build/tools/waf.d.ts +0 -12
- package/build/tools/waf.d.ts.map +0 -1
- package/build/tools/wireless-security.d.ts +0 -19
- package/build/tools/wireless-security.d.ts.map +0 -1
- package/build/tools/zero-trust-network.d.ts +0 -8
- package/build/tools/zero-trust-network.d.ts.map +0 -1
package/build/core/parsers.d.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output parsing utilities for defensive security tool output.
|
|
3
|
-
* Converts raw command output into structured data for MCP responses.
|
|
4
|
-
*/
|
|
5
|
-
/** MCP text content type */
|
|
6
|
-
export interface McpTextContent {
|
|
7
|
-
type: "text";
|
|
8
|
-
text: string;
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Maximum output size constant (retained for backward compatibility in tests).
|
|
13
|
-
* No longer applied globally in formatToolOutput() â tools are responsible for
|
|
14
|
-
* controlling their own output size via truncateWithMetadata() or similar.
|
|
15
|
-
*/
|
|
16
|
-
export declare const MAX_OUTPUT_SIZE: number;
|
|
17
|
-
/** Default max items for truncateWithMetadata() */
|
|
18
|
-
export declare const DEFAULT_MAX_ITEMS = 1000;
|
|
19
|
-
/** Metadata added when an array is truncated */
|
|
20
|
-
export interface TruncationMetadata {
|
|
21
|
-
truncated: boolean;
|
|
22
|
-
total_count: number;
|
|
23
|
-
showing: number;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Truncates an array to `maxItems` and returns the slice plus truncation metadata.
|
|
27
|
-
* Use this in tools to cap findings/results arrays while preserving actionable data
|
|
28
|
-
* and informing the consumer about what was omitted.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* const { items, meta } = truncateWithMetadata(allFindings, 1000);
|
|
32
|
-
* return { findings: items, ...meta };
|
|
33
|
-
*/
|
|
34
|
-
export declare function truncateWithMetadata<T>(items: T[], maxItems?: number): {
|
|
35
|
-
items: T[];
|
|
36
|
-
meta: TruncationMetadata;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Parses key:value pair output into a Record.
|
|
40
|
-
* Lines without the separator are skipped.
|
|
41
|
-
*/
|
|
42
|
-
export declare function parseKeyValue(output: string, separator?: string): Record<string, string>;
|
|
43
|
-
/**
|
|
44
|
-
* Parses whitespace-delimited table output into an array of Records.
|
|
45
|
-
* First non-empty line is treated as the header row.
|
|
46
|
-
*/
|
|
47
|
-
export declare function parseTable(output: string): Record<string, string>[];
|
|
48
|
-
/**
|
|
49
|
-
* Safely parses JSON text. Returns null on parse failure.
|
|
50
|
-
*/
|
|
51
|
-
export declare function parseJsonSafe(text: string): unknown | null;
|
|
52
|
-
/**
|
|
53
|
-
* Formats any data into MCP text content.
|
|
54
|
-
* Objects are JSON-stringified with indentation.
|
|
55
|
-
*
|
|
56
|
-
* NOTE: Global truncation was removed in favor of per-tool smart truncation
|
|
57
|
-
* via truncateWithMetadata(). Tools are responsible for capping their own
|
|
58
|
-
* arrays/findings before calling this function. This preserves complete
|
|
59
|
-
* structured data (findings, results) while avoiding mid-JSON truncation
|
|
60
|
-
* that broke parsing for consumers.
|
|
61
|
-
*/
|
|
62
|
-
export declare function formatToolOutput(data: unknown): McpTextContent;
|
|
63
|
-
/**
|
|
64
|
-
* Creates a simple MCP text content object.
|
|
65
|
-
*/
|
|
66
|
-
export declare function createTextContent(text: string): McpTextContent;
|
|
67
|
-
/**
|
|
68
|
-
* Creates an MCP text content object with an error prefix.
|
|
69
|
-
*/
|
|
70
|
-
export declare function createErrorContent(msg: string): McpTextContent;
|
|
71
|
-
/** Structured iptables rule */
|
|
72
|
-
export interface IptablesRule {
|
|
73
|
-
chain: string;
|
|
74
|
-
policy?: string;
|
|
75
|
-
packets: string;
|
|
76
|
-
bytes: string;
|
|
77
|
-
target: string;
|
|
78
|
-
protocol: string;
|
|
79
|
-
opt: string;
|
|
80
|
-
in: string;
|
|
81
|
-
out: string;
|
|
82
|
-
source: string;
|
|
83
|
-
destination: string;
|
|
84
|
-
extra: string;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Parses `iptables -L -n -v` output into structured rules.
|
|
88
|
-
*/
|
|
89
|
-
export declare function parseIptablesOutput(output: string): IptablesRule[];
|
|
90
|
-
/**
|
|
91
|
-
* Parses `nft list ruleset` output into structured sections.
|
|
92
|
-
*/
|
|
93
|
-
export declare function parseNftOutput(output: string): Record<string, string[]>;
|
|
94
|
-
/** Structured sysctl entry */
|
|
95
|
-
export interface SysctlEntry {
|
|
96
|
-
key: string;
|
|
97
|
-
value: string;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Parses `sysctl -a` output into structured entries.
|
|
101
|
-
*/
|
|
102
|
-
export declare function parseSysctlOutput(output: string): SysctlEntry[];
|
|
103
|
-
/** Structured audit log entry */
|
|
104
|
-
export interface AuditEntry {
|
|
105
|
-
type: string;
|
|
106
|
-
timestamp: string;
|
|
107
|
-
fields: Record<string, string>;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Parses `ausearch` output into structured audit entries.
|
|
111
|
-
*/
|
|
112
|
-
export declare function parseAuditdOutput(output: string): AuditEntry[];
|
|
113
|
-
/** Lynis finding */
|
|
114
|
-
export interface LynisFinding {
|
|
115
|
-
severity: string;
|
|
116
|
-
testId: string;
|
|
117
|
-
description: string;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Parses Lynis audit output for findings/warnings/suggestions.
|
|
121
|
-
*/
|
|
122
|
-
export declare function parseLynisOutput(output: string): LynisFinding[];
|
|
123
|
-
/** OpenSCAP result entry */
|
|
124
|
-
export interface OscapResult {
|
|
125
|
-
ruleId: string;
|
|
126
|
-
result: string;
|
|
127
|
-
severity: string;
|
|
128
|
-
title: string;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Parses OpenSCAP text/XML results output.
|
|
132
|
-
* Handles the common text report format.
|
|
133
|
-
*/
|
|
134
|
-
export declare function parseOscapOutput(output: string): OscapResult[];
|
|
135
|
-
/** ClamAV scan result */
|
|
136
|
-
export interface ClamavResult {
|
|
137
|
-
file: string;
|
|
138
|
-
status: "OK" | "FOUND" | "ERROR";
|
|
139
|
-
virus?: string;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Parses `clamscan` output into structured results.
|
|
143
|
-
*/
|
|
144
|
-
export declare function parseClamavOutput(output: string): ClamavResult[];
|
|
145
|
-
/**
|
|
146
|
-
* Extracts ClamAV's summary section from raw stdout output.
|
|
147
|
-
* ClamAV prints a "----------- SCAN SUMMARY -----------" block at the end.
|
|
148
|
-
* Returns the summary block (max ~500 chars) instead of the full per-file output.
|
|
149
|
-
* Falls back to a generated summary if the summary block isn't found.
|
|
150
|
-
*/
|
|
151
|
-
export declare function extractClamavSummary(stdout: string): string;
|
|
152
|
-
/** Structured socket entry from ss */
|
|
153
|
-
export interface SsEntry {
|
|
154
|
-
state: string;
|
|
155
|
-
recv: string;
|
|
156
|
-
send: string;
|
|
157
|
-
local: string;
|
|
158
|
-
peer: string;
|
|
159
|
-
process: string;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Parses `ss -tulnp` output into structured entries.
|
|
163
|
-
*/
|
|
164
|
-
export declare function parseSsOutput(output: string): SsEntry[];
|
|
165
|
-
/** Structured fail2ban jail status */
|
|
166
|
-
export interface Fail2banJail {
|
|
167
|
-
name: string;
|
|
168
|
-
status: string;
|
|
169
|
-
currentlyFailed: number;
|
|
170
|
-
totalFailed: number;
|
|
171
|
-
currentlyBanned: number;
|
|
172
|
-
totalBanned: number;
|
|
173
|
-
bannedIPs: string[];
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Parses `fail2ban-client status` output.
|
|
177
|
-
*/
|
|
178
|
-
export declare function parseFail2banOutput(output: string): Fail2banJail[];
|
|
179
|
-
/** Structured systemctl unit entry */
|
|
180
|
-
export interface SystemctlUnit {
|
|
181
|
-
unit: string;
|
|
182
|
-
load: string;
|
|
183
|
-
active: string;
|
|
184
|
-
sub: string;
|
|
185
|
-
description: string;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Parses `systemctl list-units` output into structured entries.
|
|
189
|
-
*/
|
|
190
|
-
export declare function parseSystemctlOutput(output: string): SystemctlUnit[];
|
|
191
|
-
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../../src/core/parsers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4BAA4B;AAC5B,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAa,CAAC;AAE1C,mDAAmD;AACnD,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,gDAAgD;AAChD,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,KAAK,EAAE,CAAC,EAAE,EACV,QAAQ,GAAE,MAA0B,GACnC;IAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAY1C;AAID;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAY,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBxB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CA4BnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OA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ACb,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAoFlE;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,CAoCpE"}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Severity levels for policy rules, aligned with common security frameworks.
|
|
3
|
-
*/
|
|
4
|
-
export type PolicySeverity = "critical" | "high" | "medium" | "low" | "info";
|
|
5
|
-
/**
|
|
6
|
-
* A single compliance policy rule defining a check and optional remediation.
|
|
7
|
-
*/
|
|
8
|
-
export interface PolicyRule {
|
|
9
|
-
/** Unique rule identifier (e.g., "CIS-1.1.1") */
|
|
10
|
-
id: string;
|
|
11
|
-
/** Human-readable title */
|
|
12
|
-
title: string;
|
|
13
|
-
/** Detailed description of what this rule checks */
|
|
14
|
-
description: string;
|
|
15
|
-
/** Severity of non-compliance */
|
|
16
|
-
severity: PolicySeverity;
|
|
17
|
-
/** Category (e.g., "filesystem", "network", "authentication") */
|
|
18
|
-
category: string;
|
|
19
|
-
/** Command to run to check compliance (array: [command, ...args]) */
|
|
20
|
-
check: string[];
|
|
21
|
-
/** Expected output pattern (regex string or exact match) */
|
|
22
|
-
expectedOutput?: string;
|
|
23
|
-
/** Command to remediate non-compliance (array: [command, ...args]) */
|
|
24
|
-
remediation?: string[];
|
|
25
|
-
/** Reference IDs (e.g., CIS benchmark, NIST control IDs) */
|
|
26
|
-
references?: string[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Result of evaluating a single policy rule.
|
|
30
|
-
*/
|
|
31
|
-
export interface PolicyResult {
|
|
32
|
-
/** The rule that was evaluated */
|
|
33
|
-
rule: PolicyRule;
|
|
34
|
-
/** Whether the system passed this check */
|
|
35
|
-
passed: boolean;
|
|
36
|
-
/** Actual output from the check command */
|
|
37
|
-
actual: string;
|
|
38
|
-
/** Human-readable result message */
|
|
39
|
-
message: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A collection of policy rules forming a compliance policy set.
|
|
43
|
-
*/
|
|
44
|
-
export interface PolicySet {
|
|
45
|
-
/** Policy set name (e.g., "CIS Level 1 - Server") */
|
|
46
|
-
name: string;
|
|
47
|
-
/** Version of this policy set */
|
|
48
|
-
version: string;
|
|
49
|
-
/** Description of the policy set */
|
|
50
|
-
description: string;
|
|
51
|
-
/** Array of policy rules */
|
|
52
|
-
rules: PolicyRule[];
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Summary of a policy evaluation.
|
|
56
|
-
*/
|
|
57
|
-
export interface PolicyEvaluationSummary {
|
|
58
|
-
/** Policy set that was evaluated */
|
|
59
|
-
policyName: string;
|
|
60
|
-
/** Total number of rules */
|
|
61
|
-
totalRules: number;
|
|
62
|
-
/** Number of rules that passed */
|
|
63
|
-
passed: number;
|
|
64
|
-
/** Number of rules that failed */
|
|
65
|
-
failed: number;
|
|
66
|
-
/** Number of rules with errors */
|
|
67
|
-
errors: number;
|
|
68
|
-
/** Compliance percentage (0-100) */
|
|
69
|
-
compliancePercent: number;
|
|
70
|
-
/** Individual rule results */
|
|
71
|
-
results: PolicyResult[];
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Validates a policy rule's check (or remediation) command array.
|
|
75
|
-
*
|
|
76
|
-
* Security controls:
|
|
77
|
-
* 1. Command (check[0]) must be in the security allowlist
|
|
78
|
-
* 2. Shell interpreters are explicitly blocked (even if allowlisted)
|
|
79
|
-
* 3. Arguments are checked for null bytes and control characters
|
|
80
|
-
*
|
|
81
|
-
* Note: Shell metacharacters (|, &, $, etc.) in arguments are NOT blocked
|
|
82
|
-
* because policy rules use execFile (no shell), making these characters
|
|
83
|
-
* harmless literal values. Policy rules legitimately need regex
|
|
84
|
-
* metacharacters as arguments to grep/awk/sed.
|
|
85
|
-
*
|
|
86
|
-
* @param check The command array [command, ...args]
|
|
87
|
-
* @param label Human-readable label for error messages (e.g., "check", "remediation")
|
|
88
|
-
* @throws {Error} If validation fails
|
|
89
|
-
*/
|
|
90
|
-
export declare function validateRuleCheck(check: string[], label?: string): void;
|
|
91
|
-
/**
|
|
92
|
-
* SECURITY (CORE-009): ReDoS (Regular Expression Denial of Service) protection.
|
|
93
|
-
*
|
|
94
|
-
* Safely tests a regex pattern against input with multiple layers of defense
|
|
95
|
-
* against catastrophic backtracking:
|
|
96
|
-
*
|
|
97
|
-
* 1. **Length limit**: Patterns longer than 200 characters are rejected to reduce
|
|
98
|
-
* the attack surface for complex regex injection.
|
|
99
|
-
* 2. **Nested quantifier detection**: Patterns like `(a+)+`, `(a*)*`, `(a+)*`
|
|
100
|
-
* are rejected because they cause exponential backtracking on non-matching
|
|
101
|
-
* input. The check uses two heuristics:
|
|
102
|
-
* - Repeated quantifiers: `a++`, `a**`, `{n,m}{` (possessive-like syntax
|
|
103
|
-
* that JavaScript doesn't support, indicating malformed patterns)
|
|
104
|
-
* - Group-level nesting: `([...]+)+` or `([...]*)*` where a quantified
|
|
105
|
-
* group is itself quantified
|
|
106
|
-
* 3. **try-catch**: Invalid regex syntax is caught and reported clearly.
|
|
107
|
-
*
|
|
108
|
-
* These checks are applied to user-supplied `expectedOutput` regex patterns
|
|
109
|
-
* in policy rules before they are compiled or executed.
|
|
110
|
-
*
|
|
111
|
-
* @param pattern The regex pattern string
|
|
112
|
-
* @param input The string to test against
|
|
113
|
-
* @returns Whether the pattern matches the input
|
|
114
|
-
* @throws {Error} If the pattern is dangerous, invalid, or too long
|
|
115
|
-
*/
|
|
116
|
-
export declare function safeRegexTest(pattern: string, input: string): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Evaluates a single policy rule by executing its check command
|
|
119
|
-
* and comparing the output against the expected pattern.
|
|
120
|
-
*
|
|
121
|
-
* Before execution, the check command is validated against the
|
|
122
|
-
* security allowlist and shell interpreters are blocked.
|
|
123
|
-
*
|
|
124
|
-
* @param rule The policy rule to evaluate
|
|
125
|
-
* @returns The evaluation result
|
|
126
|
-
*/
|
|
127
|
-
export declare function evaluateRule(rule: PolicyRule): Promise<PolicyResult>;
|
|
128
|
-
/**
|
|
129
|
-
* Evaluates all rules in a policy set and returns a summary.
|
|
130
|
-
*
|
|
131
|
-
* @param policySet The policy set to evaluate
|
|
132
|
-
* @returns Evaluation summary with individual results
|
|
133
|
-
*/
|
|
134
|
-
export declare function evaluatePolicy(policySet: PolicySet): Promise<PolicyEvaluationSummary>;
|
|
135
|
-
/**
|
|
136
|
-
* Loads a policy set from a JSON file with strict schema validation.
|
|
137
|
-
*
|
|
138
|
-
* Validates:
|
|
139
|
-
* 1. JSON structure via Zod schema (field types, lengths, required fields)
|
|
140
|
-
* 2. All check commands against the security allowlist
|
|
141
|
-
* 3. All remediation commands against the security allowlist
|
|
142
|
-
*
|
|
143
|
-
* @param path Absolute or relative path to the policy JSON file
|
|
144
|
-
* @returns The loaded and validated policy set
|
|
145
|
-
* @throws If the file cannot be read, parsed, or fails validation
|
|
146
|
-
*/
|
|
147
|
-
export declare function loadPolicy(path: string): PolicySet;
|
|
148
|
-
/**
|
|
149
|
-
* Saves a policy set to a JSON file with secure permissions.
|
|
150
|
-
* Creates parent directories with owner-only permissions (0o700).
|
|
151
|
-
* Files are written with owner-only permissions (0o600).
|
|
152
|
-
*
|
|
153
|
-
* @param path Path to save the policy file
|
|
154
|
-
* @param policy The policy set to save
|
|
155
|
-
*/
|
|
156
|
-
export declare function savePolicy(path: string, policy: PolicySet): void;
|
|
157
|
-
/**
|
|
158
|
-
* Returns a list of built-in policy file names from the policy directory.
|
|
159
|
-
* Returns empty array if the directory doesn't exist or is empty.
|
|
160
|
-
*/
|
|
161
|
-
export declare function getBuiltinPolicies(): string[];
|
|
162
|
-
/**
|
|
163
|
-
* Built-in policy rule templates for common hardening checks.
|
|
164
|
-
* These can be used as a starting point for custom policies.
|
|
165
|
-
*
|
|
166
|
-
* SECURITY: All check commands use direct binary invocation (no shell).
|
|
167
|
-
* Shell interpreters (sh, bash, etc.) are never used in check or remediation arrays.
|
|
168
|
-
*/
|
|
169
|
-
export declare const BUILTIN_RULE_TEMPLATES: PolicyRule[];
|
|
170
|
-
//# sourceMappingURL=policy-engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy-engine.d.ts","sourceRoot":"","sources":["../../src/core/policy-engine.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,QAAQ,EAAE,cAAc,CAAC;IACzB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAA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;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAwBlD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CAQhE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAY7C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,UAAU,EAwT9C,CAAC"}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pre-flight Validation Engine â orchestrates the complete pre-flight
|
|
3
|
-
* validation pipeline for MCP tools.
|
|
4
|
-
*
|
|
5
|
-
* Before each tool invocation this module:
|
|
6
|
-
* 1. Resolves the tool's manifest from the {@link ToolRegistry}
|
|
7
|
-
* 2. Checks binary, Python, npm, library, and file dependencies
|
|
8
|
-
* 3. Attempts auto-installation of missing deps when enabled
|
|
9
|
-
* 4. Validates privilege requirements via {@link PrivilegeManager}
|
|
10
|
-
* 5. Returns a structured {@link PreflightResult} with pass/fail, actionable
|
|
11
|
-
* messages, and a human-readable summary
|
|
12
|
-
*
|
|
13
|
-
* Results are cached for 60 seconds to avoid redundant checks when multiple
|
|
14
|
-
* tools from the same category are invoked in sequence.
|
|
15
|
-
*
|
|
16
|
-
* @module preflight
|
|
17
|
-
*/
|
|
18
|
-
import { type ToolManifest } from "./tool-registry.js";
|
|
19
|
-
import { type PrivilegeIssue } from "./privilege-manager.js";
|
|
20
|
-
export interface PreflightResult {
|
|
21
|
-
toolName: string;
|
|
22
|
-
/** Overall pass/fail */
|
|
23
|
-
passed: boolean;
|
|
24
|
-
timestamp: number;
|
|
25
|
-
/** Total pre-flight time in ms */
|
|
26
|
-
duration: number;
|
|
27
|
-
dependencies: {
|
|
28
|
-
/** Everything that was checked */
|
|
29
|
-
checked: DependencyCheck[];
|
|
30
|
-
/** Still missing after install attempts */
|
|
31
|
-
missing: DependencyCheck[];
|
|
32
|
-
/** Successfully auto-installed */
|
|
33
|
-
installed: DependencyCheck[];
|
|
34
|
-
/** Non-fatal dependency issues */
|
|
35
|
-
warnings: string[];
|
|
36
|
-
};
|
|
37
|
-
privileges: {
|
|
38
|
-
satisfied: boolean;
|
|
39
|
-
issues: PrivilegeIssue[];
|
|
40
|
-
recommendations: string[];
|
|
41
|
-
};
|
|
42
|
-
safeguards?: {
|
|
43
|
-
/** Whether the operation is safe */
|
|
44
|
-
safe: boolean;
|
|
45
|
-
/** Blocking safety issues (prevent execution) */
|
|
46
|
-
blockers: string[];
|
|
47
|
-
/** Non-blocking safety warnings */
|
|
48
|
-
warnings: string[];
|
|
49
|
-
/** Applications impacted by the operation */
|
|
50
|
-
impactedApps: string[];
|
|
51
|
-
};
|
|
52
|
-
/** Human-readable summary */
|
|
53
|
-
summary: string;
|
|
54
|
-
/** Fatal blocking errors */
|
|
55
|
-
errors: string[];
|
|
56
|
-
/** Non-fatal warnings */
|
|
57
|
-
warnings: string[];
|
|
58
|
-
}
|
|
59
|
-
export interface DependencyCheck {
|
|
60
|
-
name: string;
|
|
61
|
-
type: "binary" | "python-module" | "npm-package" | "library" | "file";
|
|
62
|
-
/** true = required, false = optional */
|
|
63
|
-
required: boolean;
|
|
64
|
-
found: boolean;
|
|
65
|
-
autoInstalled?: boolean;
|
|
66
|
-
installMessage?: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Central orchestration engine for the pre-flight validation pipeline.
|
|
70
|
-
*
|
|
71
|
-
* Singleton â obtain via {@link PreflightEngine.instance}.
|
|
72
|
-
*
|
|
73
|
-
* The main entry point is {@link runPreflight}, which executes the full
|
|
74
|
-
* dependency â auto-install â privilege check pipeline and returns a
|
|
75
|
-
* structured {@link PreflightResult}.
|
|
76
|
-
*/
|
|
77
|
-
export declare class PreflightEngine {
|
|
78
|
-
private registry;
|
|
79
|
-
private privilegeManager;
|
|
80
|
-
private autoInstaller;
|
|
81
|
-
/**
|
|
82
|
-
* Dependency cache â keyed by tool name only, 60s TTL.
|
|
83
|
-
* Covers: binary existence, privilege checks, auto-install results.
|
|
84
|
-
* Cached regardless of params (dependency results don't depend on runtime params).
|
|
85
|
-
*/
|
|
86
|
-
private resultCache;
|
|
87
|
-
private static readonly CACHE_TTL;
|
|
88
|
-
private static _instance;
|
|
89
|
-
private constructor();
|
|
90
|
-
/** Get or create the singleton instance. */
|
|
91
|
-
static instance(): PreflightEngine;
|
|
92
|
-
/**
|
|
93
|
-
* Run the full pre-flight validation pipeline for a tool.
|
|
94
|
-
*
|
|
95
|
-
* 1. Check cache â return early for valid passing results
|
|
96
|
-
* 2. Resolve the tool's manifest from the registry
|
|
97
|
-
* 3. Check all dependency types (binary, Python, npm, library, file)
|
|
98
|
-
* 4. Auto-install missing required deps when enabled
|
|
99
|
-
* 5. Validate privilege requirements (sudo, capabilities)
|
|
100
|
-
* 6. Determine overall pass/fail and generate summary
|
|
101
|
-
* 7. Cache and return the result
|
|
102
|
-
*/
|
|
103
|
-
runPreflight(toolName: string, params?: Record<string, unknown>): Promise<PreflightResult>;
|
|
104
|
-
/**
|
|
105
|
-
* Check all dependency types for a tool manifest.
|
|
106
|
-
*
|
|
107
|
-
* Checks binaries, Python modules, npm packages, system libraries,
|
|
108
|
-
* and required files. If any required dependency is missing and
|
|
109
|
-
* auto-install is enabled, attempts installation via {@link AutoInstaller}.
|
|
110
|
-
*/
|
|
111
|
-
checkDependencies(manifest: ToolManifest): Promise<PreflightResult["dependencies"]>;
|
|
112
|
-
/**
|
|
113
|
-
* Check privilege requirements for a tool manifest.
|
|
114
|
-
* Delegates to {@link PrivilegeManager.checkForTool}.
|
|
115
|
-
*/
|
|
116
|
-
checkPrivileges(manifest: ToolManifest): Promise<PreflightResult["privileges"]>;
|
|
117
|
-
/**
|
|
118
|
-
* Generate a human-readable summary of the pre-flight result.
|
|
119
|
-
*
|
|
120
|
-
* @example Passing
|
|
121
|
-
* ```
|
|
122
|
-
* PASS: Pre-flight passed for 'firewall_iptables_list'
|
|
123
|
-
* Dependencies: 2/2 available (iptables, ip6tables)
|
|
124
|
-
* Privileges: sudo session active
|
|
125
|
-
* Ready to execute.
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @example Failing
|
|
129
|
-
* ```
|
|
130
|
-
* Pre-flight FAILED for 'compliance_oscap_scan'
|
|
131
|
-
* Missing dependencies:
|
|
132
|
-
* âĒ oscap (binary) â Install with: sudo apt-get install -y libopenscap8
|
|
133
|
-
* Privilege issues:
|
|
134
|
-
* âĒ Root access required for OpenSCAP scanning
|
|
135
|
-
* â Run 'sudo_elevate' tool first to provide credentials
|
|
136
|
-
* Cannot proceed until issues are resolved.
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
formatSummary(result: PreflightResult): string;
|
|
140
|
-
/**
|
|
141
|
-
* Generate a shorter status message for prepending to tool output.
|
|
142
|
-
*
|
|
143
|
-
* - Passed (no issues): `"[pre-flight OK] All checks passed (2 deps, sudo active)"`
|
|
144
|
-
* - Passed (warnings): `"[pre-flight OK] Passed with warnings: optional dep 'nmap' not found"`
|
|
145
|
-
* - Failed: returns the full error summary from {@link formatSummary}
|
|
146
|
-
*/
|
|
147
|
-
formatStatusMessage(result: PreflightResult): string;
|
|
148
|
-
/**
|
|
149
|
-
* Clear the result cache.
|
|
150
|
-
* Call after installs, privilege changes, or any event that invalidates
|
|
151
|
-
* previous pre-flight results.
|
|
152
|
-
*/
|
|
153
|
-
clearCache(): void;
|
|
154
|
-
/** Store a result in the cache with TTL. */
|
|
155
|
-
private cacheResult;
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=preflight.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../src/core/preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC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,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA6ID;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,aAAa,CAAgB;IAErC;;;;OAIG;IACH,OAAO,CAAC,WAAW,CAA2D;IAC9E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAU;IAE3C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAgC;IAExD,OAAO;IAOP,4CAA4C;IAC5C,MAAM,CAAC,QAAQ,IAAI,eAAe;IASlC;;;;;;;;;;OAUG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,eAAe,CAAC;IAmM3B;;;;;;OAMG;IACG,iBAAiB,CACrB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;IA0J3C;;;OAGG;IACG,eAAe,CACnB,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IAWzC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM;IAoG9C;;;;;;OAMG;IACH,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM;IAiCpD;;;;OAIG;IACH,UAAU,IAAI,IAAI;IAMlB,4CAA4C;IAC5C,OAAO,CAAC,WAAW;CAMpB"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PrivilegeManager â detects the current privilege level and checks whether
|
|
3
|
-
* a tool's privilege requirements are satisfied.
|
|
4
|
-
*
|
|
5
|
-
* This module is part of the pre-flight validation system. It queries:
|
|
6
|
-
* - UID / EUID via `process.getuid()` / `process.geteuid()`
|
|
7
|
-
* - Linux capabilities via `/proc/self/status` CapEff bitmask
|
|
8
|
-
* - Passwordless sudo via `sudo -n true`
|
|
9
|
-
* - Active sudo session via `SudoSession.getInstance().isElevated()`
|
|
10
|
-
* - User groups via `id -Gn`
|
|
11
|
-
*
|
|
12
|
-
* Child process spawning goes through spawn-safe.ts which enforces the
|
|
13
|
-
* command allowlist and shell: false without creating circular dependencies.
|
|
14
|
-
*
|
|
15
|
-
* @module privilege-manager
|
|
16
|
-
*/
|
|
17
|
-
import type { ToolManifest } from "./tool-registry.js";
|
|
18
|
-
export interface PrivilegeStatus {
|
|
19
|
-
/** Current real user ID */
|
|
20
|
-
uid: number;
|
|
21
|
-
/** Current effective user ID */
|
|
22
|
-
euid: number;
|
|
23
|
-
/** Whether running as root (euid === 0) */
|
|
24
|
-
isRoot: boolean;
|
|
25
|
-
/** Whether `sudo` binary is available on PATH */
|
|
26
|
-
sudoAvailable: boolean;
|
|
27
|
-
/** Whether passwordless sudo works (`sudo -n true`) */
|
|
28
|
-
passwordlessSudo: boolean;
|
|
29
|
-
/** Whether SudoSession has cached credentials */
|
|
30
|
-
sudoSessionActive: boolean;
|
|
31
|
-
/** Currently held Linux capabilities (from CapEff) */
|
|
32
|
-
capabilities: Set<string>;
|
|
33
|
-
/** User's group memberships */
|
|
34
|
-
groups: string[];
|
|
35
|
-
}
|
|
36
|
-
export interface PrivilegeCheckResult {
|
|
37
|
-
/** All privilege requirements met */
|
|
38
|
-
satisfied: boolean;
|
|
39
|
-
/** Problems found */
|
|
40
|
-
issues: PrivilegeIssue[];
|
|
41
|
-
/** How to fix any issues */
|
|
42
|
-
recommendations: string[];
|
|
43
|
-
}
|
|
44
|
-
export interface PrivilegeIssue {
|
|
45
|
-
type: "sudo-required" | "capability-missing" | "sudo-unavailable" | "session-expired";
|
|
46
|
-
/** Human-readable description of the issue */
|
|
47
|
-
description: string;
|
|
48
|
-
/** Which tool/operation needs this privilege */
|
|
49
|
-
operation: string;
|
|
50
|
-
/** How to resolve the issue */
|
|
51
|
-
resolution: string;
|
|
52
|
-
}
|
|
53
|
-
export declare class PrivilegeManager {
|
|
54
|
-
private cachedStatus;
|
|
55
|
-
private cacheExpiry;
|
|
56
|
-
private static readonly CACHE_TTL;
|
|
57
|
-
private static _instance;
|
|
58
|
-
private constructor();
|
|
59
|
-
/** Get or create the singleton instance. */
|
|
60
|
-
static instance(): PrivilegeManager;
|
|
61
|
-
/**
|
|
62
|
-
* Detect current privilege level.
|
|
63
|
-
* Results are cached for {@link CACHE_TTL} ms to avoid repeated
|
|
64
|
-
* subprocess spawns on rapid sequential tool calls.
|
|
65
|
-
*/
|
|
66
|
-
getStatus(): Promise<PrivilegeStatus>;
|
|
67
|
-
/**
|
|
68
|
-
* Check whether a specific tool's privilege requirements are met.
|
|
69
|
-
*
|
|
70
|
-
* Evaluates the tool's `sudo` level and `capabilities` list against
|
|
71
|
-
* the current {@link PrivilegeStatus} and returns actionable issues.
|
|
72
|
-
*/
|
|
73
|
-
checkForTool(manifest: ToolManifest): Promise<PrivilegeCheckResult>;
|
|
74
|
-
/**
|
|
75
|
-
* Check if a specific Linux capability is in the current effective set.
|
|
76
|
-
*/
|
|
77
|
-
hasCapability(cap: string): Promise<boolean>;
|
|
78
|
-
/**
|
|
79
|
-
* Parse the effective capability set from `/proc/self/status`.
|
|
80
|
-
*
|
|
81
|
-
* Reads the `CapEff` line which contains a hex-encoded bitmask,
|
|
82
|
-
* then maps set bits to capability names using the kernel-defined
|
|
83
|
-
* bit positions.
|
|
84
|
-
*/
|
|
85
|
-
getCurrentCapabilities(): Promise<Set<string>>;
|
|
86
|
-
/**
|
|
87
|
-
* Test whether passwordless sudo works by running `sudo -n true`.
|
|
88
|
-
* The `-n` (non-interactive) flag causes sudo to fail immediately
|
|
89
|
-
* rather than prompting if a password is required.
|
|
90
|
-
*/
|
|
91
|
-
testPasswordlessSudo(): Promise<boolean>;
|
|
92
|
-
/**
|
|
93
|
-
* Check whether the `sudo` binary exists on PATH.
|
|
94
|
-
*/
|
|
95
|
-
isSudoAvailable(): Promise<boolean>;
|
|
96
|
-
/**
|
|
97
|
-
* Invalidate the cached status.
|
|
98
|
-
* Should be called after events that change privilege state,
|
|
99
|
-
* e.g., after `sudo_elevate` or `sudo_drop`.
|
|
100
|
-
*/
|
|
101
|
-
clearCache(): void;
|
|
102
|
-
/**
|
|
103
|
-
* Get user group memberships via `id -Gn`.
|
|
104
|
-
* Returns an empty array on failure.
|
|
105
|
-
*/
|
|
106
|
-
private getGroups;
|
|
107
|
-
}
|
|
108
|
-
//# sourceMappingURL=privilege-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"privilege-manager.d.ts","sourceRoot":"","sources":["../../src/core/privilege-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAyEvD,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,EAAE,OAAO,CAAC;IAChB,iDAAiD;IACjD,aAAa,EAAE,OAAO,CAAC;IACvB,uDAAuD;IACvD,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iDAAiD;IACjD,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sDAAsD;IACtD,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,+BAA+B;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EACA,eAAe,GACf,oBAAoB,GACpB,kBAAk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