@cclabsnz/sf-audit 1.0.1 → 1.1.0
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 +75 -0
- package/lib/api/ToolingClientImpl.js +5 -2
- package/lib/chains/AttackChain.d.ts +20 -0
- package/lib/chains/AttackChain.js +2 -0
- package/lib/chains/Capability.d.ts +7 -0
- package/lib/chains/Capability.js +11 -0
- package/lib/chains/CapabilityRegistry.d.ts +18 -0
- package/lib/chains/CapabilityRegistry.js +53 -0
- package/lib/chains/ChainEngine.d.ts +13 -0
- package/lib/chains/ChainEngine.js +137 -0
- package/lib/chains/namedChains.d.ts +14 -0
- package/lib/chains/namedChains.js +99 -0
- package/lib/checks/CheckEngine.js +33 -5
- package/lib/checks/impl/AnonymousApexAuditCheck.d.ts +10 -0
- package/lib/checks/impl/AnonymousApexAuditCheck.js +106 -0
- package/lib/checks/impl/ApexCrudFLSCheck.d.ts +11 -0
- package/lib/checks/impl/ApexCrudFLSCheck.js +98 -0
- package/lib/checks/impl/ApexLoggingCheck.d.ts +11 -0
- package/lib/checks/impl/ApexLoggingCheck.js +124 -0
- package/lib/checks/impl/ApexRestEndpointCheck.d.ts +11 -0
- package/lib/checks/impl/ApexRestEndpointCheck.js +94 -0
- package/lib/checks/impl/ApexSharingCheck.js +29 -0
- package/lib/checks/impl/ApiClientPermissionCheck.d.ts +10 -0
- package/lib/checks/impl/ApiClientPermissionCheck.js +59 -0
- package/lib/checks/impl/AuditTrailCheck.js +29 -0
- package/lib/checks/impl/CertificateExpiryCheck.d.ts +10 -0
- package/lib/checks/impl/CertificateExpiryCheck.js +123 -0
- package/lib/checks/impl/CodeSecurityCheck.d.ts +2 -1
- package/lib/checks/impl/CodeSecurityCheck.js +46 -6
- package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +11 -0
- package/lib/checks/impl/ConnectedAppInactivityCheck.js +86 -0
- package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +10 -0
- package/lib/checks/impl/ConnectedAppScopeCheck.js +125 -0
- package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -0
- package/lib/checks/impl/ConnectedAppsCheck.js +37 -2
- package/lib/checks/impl/ContentLinksCheck.d.ts +10 -0
- package/lib/checks/impl/ContentLinksCheck.js +115 -0
- package/lib/checks/impl/CorsAllowlistCheck.d.ts +10 -0
- package/lib/checks/impl/CorsAllowlistCheck.js +80 -0
- package/lib/checks/impl/CspTrustedSitesCheck.d.ts +10 -0
- package/lib/checks/impl/CspTrustedSitesCheck.js +55 -0
- package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +10 -0
- package/lib/checks/impl/CustomLabelsCredentialCheck.js +97 -0
- package/lib/checks/impl/DataClassificationCheck.d.ts +10 -0
- package/lib/checks/impl/DataClassificationCheck.js +112 -0
- package/lib/checks/impl/DebugLogAccessCheck.d.ts +10 -0
- package/lib/checks/impl/DebugLogAccessCheck.js +81 -0
- package/lib/checks/impl/DeploymentIdentityCheck.d.ts +11 -0
- package/lib/checks/impl/DeploymentIdentityCheck.js +144 -0
- package/lib/checks/impl/EnhancedDomainsCheck.d.ts +10 -0
- package/lib/checks/impl/EnhancedDomainsCheck.js +84 -0
- package/lib/checks/impl/EscalationPermsCheck.d.ts +10 -0
- package/lib/checks/impl/EscalationPermsCheck.js +77 -0
- package/lib/checks/impl/EventMonitoringCheck.d.ts +11 -0
- package/lib/checks/impl/EventMonitoringCheck.js +84 -0
- package/lib/checks/impl/ExperienceCloudSiteCheck.d.ts +10 -0
- package/lib/checks/impl/ExperienceCloudSiteCheck.js +91 -0
- package/lib/checks/impl/FailedLoginCheck.d.ts +10 -0
- package/lib/checks/impl/FailedLoginCheck.js +122 -0
- package/lib/checks/impl/FieldHistoryTrackingCheck.d.ts +10 -0
- package/lib/checks/impl/FieldHistoryTrackingCheck.js +70 -0
- package/lib/checks/impl/FieldLevelSecurityCheck.js +28 -18
- package/lib/checks/impl/GuestExecutableApexCheck.d.ts +11 -0
- package/lib/checks/impl/GuestExecutableApexCheck.js +93 -0
- package/lib/checks/impl/GuestUserAccessCheck.js +74 -66
- package/lib/checks/impl/HardcodedCredentialsCheck.js +2 -2
- package/lib/checks/impl/HighAssuranceSessionCheck.d.ts +10 -0
- package/lib/checks/impl/HighAssuranceSessionCheck.js +103 -0
- package/lib/checks/impl/InactiveUsersCheck.js +38 -19
- package/lib/checks/impl/InstalledPackagesCheck.d.ts +10 -0
- package/lib/checks/impl/InstalledPackagesCheck.js +94 -0
- package/lib/checks/impl/IntegrationUsersCheck.d.ts +10 -0
- package/lib/checks/impl/IntegrationUsersCheck.js +108 -0
- package/lib/checks/impl/InternalUserMfaCheck.d.ts +10 -0
- package/lib/checks/impl/InternalUserMfaCheck.js +81 -0
- package/lib/checks/impl/IpRestrictionsCheck.js +86 -23
- package/lib/checks/impl/LegacyApiVersionCheck.d.ts +10 -0
- package/lib/checks/impl/LegacyApiVersionCheck.js +91 -0
- package/lib/checks/impl/MfaEnforcementCheck.d.ts +10 -0
- package/lib/checks/impl/MfaEnforcementCheck.js +76 -0
- package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +11 -0
- package/lib/checks/impl/MfaMethodStrengthCheck.js +116 -0
- package/lib/checks/impl/MfaRegistrationCheck.d.ts +11 -0
- package/lib/checks/impl/MfaRegistrationCheck.js +95 -0
- package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +10 -0
- package/lib/checks/impl/MyDomainLoginPolicyCheck.js +105 -0
- package/lib/checks/impl/NamedCredentialsCheck.js +37 -2
- package/lib/checks/impl/PermissionsCheck.js +67 -14
- package/lib/checks/impl/PublicGroupSharingCheck.js +20 -9
- package/lib/checks/impl/ReleaseUpdatesCheck.d.ts +10 -0
- package/lib/checks/impl/ReleaseUpdatesCheck.js +106 -0
- package/lib/checks/impl/ReportFolderAccessCheck.d.ts +10 -0
- package/lib/checks/impl/ReportFolderAccessCheck.js +54 -0
- package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -0
- package/lib/checks/impl/ScheduledApexCheck.js +3 -0
- package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
- package/lib/checks/impl/SharingModelCheck.js +103 -32
- package/lib/checks/impl/SiemIntegrationCheck.d.ts +11 -0
- package/lib/checks/impl/SiemIntegrationCheck.js +102 -0
- package/lib/checks/impl/SsoEnforcementCheck.d.ts +10 -0
- package/lib/checks/impl/SsoEnforcementCheck.js +90 -0
- package/lib/checks/impl/StandardProfilesCheck.d.ts +10 -0
- package/lib/checks/impl/StandardProfilesCheck.js +68 -0
- package/lib/checks/impl/TransactionSecurityPolicyCheck.d.ts +10 -0
- package/lib/checks/impl/TransactionSecurityPolicyCheck.js +62 -0
- package/lib/checks/impl/TrustedIPRangesCheck.d.ts +10 -0
- package/lib/checks/impl/TrustedIPRangesCheck.js +106 -0
- package/lib/checks/impl/UsersAndAdminsCheck.js +50 -20
- package/lib/checks/impl/VisualforceXssCheck.d.ts +11 -0
- package/lib/checks/impl/VisualforceXssCheck.js +150 -0
- package/lib/checks/registry.js +97 -12
- package/lib/commands/audit/diff.d.ts +17 -0
- package/lib/commands/audit/diff.js +76 -0
- package/lib/commands/audit/history.d.ts +15 -0
- package/lib/commands/audit/history.js +59 -0
- package/lib/commands/audit/security.js +6 -6
- package/lib/context/AuditCache.d.ts +20 -0
- package/lib/context/AuditContext.d.ts +0 -2
- package/lib/findings/AuditResult.d.ts +3 -0
- package/lib/findings/ComplianceMapping.d.ts +3 -0
- package/lib/findings/ComplianceMapping.js +75 -0
- package/lib/findings/Finding.d.ts +20 -0
- package/lib/findings/loadScoringConfig.js +9 -2
- package/lib/findings/scoring.d.ts +2 -1
- package/lib/findings/scoring.js +20 -7
- package/lib/history/AuditDiff.d.ts +26 -0
- package/lib/history/AuditDiff.js +2 -0
- package/lib/history/DiffEngine.d.ts +4 -0
- package/lib/history/DiffEngine.js +61 -0
- package/lib/history/HistoryStore.d.ts +11 -0
- package/lib/history/HistoryStore.js +56 -0
- package/lib/history/metricMeta.d.ts +9 -0
- package/lib/history/metricMeta.js +28 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +2 -1
- package/lib/lib/wire.d.ts +1 -2
- package/lib/lib/wire.js +1 -2
- package/lib/renderers/DiffHtmlRenderer.d.ts +8 -0
- package/lib/renderers/DiffHtmlRenderer.js +164 -0
- package/lib/renderers/DiffJsonRenderer.d.ts +8 -0
- package/lib/renderers/DiffJsonRenderer.js +8 -0
- package/lib/renderers/DiffRenderer.d.ts +7 -0
- package/lib/renderers/DiffRenderer.js +2 -0
- package/lib/renderers/HistoryRenderer.d.ts +6 -0
- package/lib/renderers/HistoryRenderer.js +140 -0
- package/lib/renderers/HtmlRenderer.d.ts +1 -0
- package/lib/renderers/HtmlRenderer.js +354 -54
- package/lib/renderers/MarkdownRenderer.js +34 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -182,6 +182,81 @@ sf audit security --target-org myOrg --scoring-config ./my-scoring.json
|
|
|
182
182
|
|
|
183
183
|
Your config is deep-merged with the defaults, so you only need to include the values you want to change.
|
|
184
184
|
|
|
185
|
+
## History & Diff
|
|
186
|
+
|
|
187
|
+
Every `sf audit security` run automatically archives a JSON copy of the report to:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
~/.sf/audit-history/{orgId}/sf-audit-{orgId}-{timestamp}.json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
No configuration needed — archiving happens silently after each run.
|
|
194
|
+
|
|
195
|
+
### View Audit History
|
|
196
|
+
|
|
197
|
+
Show how your org's security posture has changed across multiple runs:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
sf audit history --target-org myOrg
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Prints a terminal table with score trends and writes an HTML timeline to the current directory.
|
|
204
|
+
|
|
205
|
+
**Flags:**
|
|
206
|
+
|
|
207
|
+
| Flag | Description | Default |
|
|
208
|
+
|------|-------------|---------|
|
|
209
|
+
| `--target-org` | Org alias or username | required |
|
|
210
|
+
| `--reports-dir` | Custom directory containing archived reports | `~/.sf/audit-history/{orgId}` |
|
|
211
|
+
| `--output` | Directory to write the HTML timeline | `.` (cwd) |
|
|
212
|
+
| `--limit` | Maximum number of most-recent runs to show | all |
|
|
213
|
+
|
|
214
|
+
**Example output:**
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
Audit History: My Org (00D000000000001)
|
|
218
|
+
────────────────────────────────────────────────────────────────────────────────
|
|
219
|
+
# Date Score Grade CRIT HIGH MED LOW Δ Score
|
|
220
|
+
────────────────────────────────────────────────────────────────────────────────
|
|
221
|
+
1 2026-03-23 15:10 64 D 1 5 8 3 —
|
|
222
|
+
2 2026-04-09 11:22 81 B 0 2 5 3 +17
|
|
223
|
+
────────────────────────────────────────────────────────────────────────────────
|
|
224
|
+
Trend: ▲ +17 over 2 audits Best: 81 (2026-04-09 11:22) Worst: 64 (2026-03-23 15:10)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Diff Two Reports
|
|
228
|
+
|
|
229
|
+
Compare any two audit JSON files to see exactly what changed:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
sf audit diff baseline.json current.json
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Writes an HTML and JSON diff report to the current directory.
|
|
236
|
+
|
|
237
|
+
**Flags:**
|
|
238
|
+
|
|
239
|
+
| Flag | Description | Default |
|
|
240
|
+
|------|-------------|---------|
|
|
241
|
+
| `--output` | Directory to write diff reports | `.` (cwd) |
|
|
242
|
+
| `--format` | Comma-separated formats: `html`, `json` | `html,json` |
|
|
243
|
+
|
|
244
|
+
**Example output:**
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
Diff report written: ./sf-audit-diff-00D000000000001-...-vs-....html
|
|
248
|
+
Diff report written: ./sf-audit-diff-00D000000000001-...-vs-....json
|
|
249
|
+
|
|
250
|
+
─────────────────────────────
|
|
251
|
+
Diff Summary
|
|
252
|
+
─────────────────────────────
|
|
253
|
+
Score delta +17
|
|
254
|
+
Grade D → B
|
|
255
|
+
New 0
|
|
256
|
+
Resolved 1
|
|
257
|
+
─────────────────────────────
|
|
258
|
+
```
|
|
259
|
+
|
|
185
260
|
## Requirements
|
|
186
261
|
|
|
187
262
|
- Node.js 18+
|
|
@@ -10,8 +10,11 @@ export class ToolingClientImpl {
|
|
|
10
10
|
let records = (result.records ?? []);
|
|
11
11
|
let nextUrl = result.nextRecordsUrl;
|
|
12
12
|
// Using conn.request() directly avoids the complex Query<> overload typings
|
|
13
|
-
// on tooling.queryMore — the nextRecordsUrl is a plain string handled cleanly here
|
|
14
|
-
|
|
13
|
+
// on tooling.queryMore — the nextRecordsUrl is a plain string handled cleanly here.
|
|
14
|
+
// Circuit breaker: 200 pages × 2000 rows = 400 000 records max before we abort.
|
|
15
|
+
let page = 0;
|
|
16
|
+
while (nextUrl && page < 200) {
|
|
17
|
+
page++;
|
|
15
18
|
const next = await this.conn.request(nextUrl);
|
|
16
19
|
records = records.concat(next.records ?? []);
|
|
17
20
|
nextUrl = next.nextRecordsUrl;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RiskLevel } from '../findings/RiskLevel.js';
|
|
2
|
+
import type { Capability } from './Capability.js';
|
|
3
|
+
export interface AttackChainStep {
|
|
4
|
+
findingId: string;
|
|
5
|
+
checkId?: string;
|
|
6
|
+
/** The capability this step contributes to the chain. */
|
|
7
|
+
capability: Capability;
|
|
8
|
+
title?: string;
|
|
9
|
+
severity?: RiskLevel;
|
|
10
|
+
}
|
|
11
|
+
export interface AttackChain {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
severity: RiskLevel;
|
|
15
|
+
confidence: 'named' | 'potential';
|
|
16
|
+
narrative: string;
|
|
17
|
+
remediation: string;
|
|
18
|
+
steps: AttackChainStep[];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=AttackChain.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Capability = 'unauth-foothold' | 'low-trust-authenticated' | 'data-read' | 'data-read-bulk' | 'data-write' | 'code-exec' | 'credential-theft' | 'priv-esc' | 'org-takeover' | 'external-egress';
|
|
2
|
+
export declare const ALL_CAPABILITIES: readonly Capability[];
|
|
3
|
+
/** Capabilities that represent an attacker entry point. */
|
|
4
|
+
export declare const SOURCE_CAPS: readonly Capability[];
|
|
5
|
+
/** Capabilities that represent a high-impact outcome (a chain "sink"). */
|
|
6
|
+
export declare const HIGH_IMPACT_SINKS: readonly Capability[];
|
|
7
|
+
//# sourceMappingURL=Capability.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ALL_CAPABILITIES = [
|
|
2
|
+
'unauth-foothold', 'low-trust-authenticated', 'data-read', 'data-read-bulk',
|
|
3
|
+
'data-write', 'code-exec', 'credential-theft', 'priv-esc', 'org-takeover', 'external-egress',
|
|
4
|
+
];
|
|
5
|
+
/** Capabilities that represent an attacker entry point. */
|
|
6
|
+
export const SOURCE_CAPS = ['unauth-foothold', 'low-trust-authenticated'];
|
|
7
|
+
/** Capabilities that represent a high-impact outcome (a chain "sink"). */
|
|
8
|
+
export const HIGH_IMPACT_SINKS = [
|
|
9
|
+
'org-takeover', 'data-write', 'data-read-bulk', 'credential-theft',
|
|
10
|
+
];
|
|
11
|
+
//# sourceMappingURL=Capability.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Capability } from './Capability.js';
|
|
2
|
+
import type { Finding } from '../findings/Finding.js';
|
|
3
|
+
export interface CapabilityEntry {
|
|
4
|
+
grants?: Capability[];
|
|
5
|
+
requires?: Capability[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The full attack model lives here: finding id → attacker capabilities it grants.
|
|
9
|
+
* Keep this the single source of truth so the ~75 checks stay untouched.
|
|
10
|
+
* Every key MUST correspond to a finding id some check can emit (see registry-integrity test).
|
|
11
|
+
*/
|
|
12
|
+
export declare const CAPABILITY_REGISTRY: Record<string, CapabilityEntry>;
|
|
13
|
+
/** Resolve the effective capabilities for a finding (inline overrides registry; passed/inconclusive yield nothing). */
|
|
14
|
+
export declare function capabilitiesFor(finding: Finding): {
|
|
15
|
+
grants: Capability[];
|
|
16
|
+
requires: Capability[];
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=CapabilityRegistry.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The full attack model lives here: finding id → attacker capabilities it grants.
|
|
3
|
+
* Keep this the single source of truth so the ~75 checks stay untouched.
|
|
4
|
+
* Every key MUST correspond to a finding id some check can emit (see registry-integrity test).
|
|
5
|
+
*/
|
|
6
|
+
export const CAPABILITY_REGISTRY = {
|
|
7
|
+
// Guest / unauthenticated foothold
|
|
8
|
+
'guest-user-write-access': { grants: ['unauth-foothold', 'data-write', 'data-read'] },
|
|
9
|
+
'guest-user-read-access': { grants: ['unauth-foothold', 'data-read'] },
|
|
10
|
+
'guest-user-sharing-exposure': { grants: ['unauth-foothold', 'data-read'] },
|
|
11
|
+
'guest-user-baseline': { grants: ['unauth-foothold'] },
|
|
12
|
+
// External / portal sharing
|
|
13
|
+
'sharing-model-external-write': { grants: ['low-trust-authenticated', 'data-write', 'data-read-bulk'] },
|
|
14
|
+
'sharing-model-external-read': { grants: ['low-trust-authenticated', 'data-read-bulk'] },
|
|
15
|
+
// Apex / code execution surfaces
|
|
16
|
+
'portal-exposed-apex-without-sharing': { grants: ['code-exec', 'data-read', 'data-write'] },
|
|
17
|
+
'soql-injection-risk': { grants: ['code-exec', 'data-read-bulk'] },
|
|
18
|
+
// Sensitive data presence
|
|
19
|
+
'field-level-security-high': { grants: ['data-read'] },
|
|
20
|
+
'field-level-security-medium': { grants: ['data-read'] },
|
|
21
|
+
// Credential / secret exposure
|
|
22
|
+
'hardcoded-credentials-found': { grants: ['credential-theft'] },
|
|
23
|
+
'custom-labels-credential-value-match': { grants: ['credential-theft'] },
|
|
24
|
+
'custom-labels-credential-name-match': { grants: ['credential-theft'] },
|
|
25
|
+
'debug-log-active-traces': { grants: ['credential-theft'] },
|
|
26
|
+
// Egress
|
|
27
|
+
'named-credentials-inventory': { grants: ['external-egress'] },
|
|
28
|
+
'named-credentials-http-endpoint': { grants: ['external-egress'] },
|
|
29
|
+
'remote-sites-inventory': { grants: ['external-egress'] },
|
|
30
|
+
// Privileged users
|
|
31
|
+
'users-modify-all-data': { grants: ['data-read-bulk', 'data-write'] },
|
|
32
|
+
'users-view-all-data': { grants: ['data-read-bulk'] },
|
|
33
|
+
'users-super-admin-combo': { grants: ['org-takeover'] },
|
|
34
|
+
'users-author-apex': { grants: ['code-exec', 'priv-esc'] },
|
|
35
|
+
// New checks (Tasks 8–10)
|
|
36
|
+
'guest-executable-apex-unprotected': { grants: ['code-exec', 'data-read-bulk', 'data-write'] },
|
|
37
|
+
'guest-executable-apex-exposed': { grants: ['code-exec'] },
|
|
38
|
+
'cors-wildcard-origin': { grants: ['credential-theft'] },
|
|
39
|
+
'cors-broad-origin': { grants: ['credential-theft'] },
|
|
40
|
+
'escalation-perms-found': { grants: ['priv-esc'] },
|
|
41
|
+
};
|
|
42
|
+
/** Resolve the effective capabilities for a finding (inline overrides registry; passed/inconclusive yield nothing). */
|
|
43
|
+
export function capabilitiesFor(finding) {
|
|
44
|
+
if (finding.passed || finding.inconclusive)
|
|
45
|
+
return { grants: [], requires: [] };
|
|
46
|
+
const inline = finding.capabilities;
|
|
47
|
+
if (inline && (inline.grants || inline.requires)) {
|
|
48
|
+
return { grants: inline.grants ?? [], requires: inline.requires ?? [] };
|
|
49
|
+
}
|
|
50
|
+
const entry = CAPABILITY_REGISTRY[finding.id];
|
|
51
|
+
return { grants: entry?.grants ?? [], requires: entry?.requires ?? [] };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=CapabilityRegistry.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Finding } from '../findings/Finding.js';
|
|
2
|
+
import type { AttackChain } from './AttackChain.js';
|
|
3
|
+
export declare class ChainEngine {
|
|
4
|
+
correlate(findings: Finding[]): AttackChain[];
|
|
5
|
+
private rank;
|
|
6
|
+
private stepFor;
|
|
7
|
+
private runNamedPass;
|
|
8
|
+
/** Record which (source, sink) capability pairs are already explained by a named chain. */
|
|
9
|
+
private coveredSourceSinkPairs;
|
|
10
|
+
private runEmergentPass;
|
|
11
|
+
private label;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ChainEngine.d.ts.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { SOURCE_CAPS, HIGH_IMPACT_SINKS } from './Capability.js';
|
|
2
|
+
import { capabilitiesFor } from './CapabilityRegistry.js';
|
|
3
|
+
import { NAMED_CHAINS } from './namedChains.js';
|
|
4
|
+
const SEVERITY_ORDER = {
|
|
5
|
+
CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4,
|
|
6
|
+
};
|
|
7
|
+
/** Potential-chain severity by terminal sink (capped at HIGH — named chains own CRITICAL). */
|
|
8
|
+
const SINK_SEVERITY = {
|
|
9
|
+
'org-takeover': 'HIGH',
|
|
10
|
+
'data-write': 'HIGH',
|
|
11
|
+
'data-read-bulk': 'HIGH',
|
|
12
|
+
'credential-theft': 'MEDIUM',
|
|
13
|
+
};
|
|
14
|
+
const MAX_STEPS = 4;
|
|
15
|
+
export class ChainEngine {
|
|
16
|
+
correlate(findings) {
|
|
17
|
+
const active = findings.filter((f) => !f.passed && !f.inconclusive);
|
|
18
|
+
// Build present capability set + per-finding grants.
|
|
19
|
+
const present = new Set();
|
|
20
|
+
const grantsByFinding = new Map();
|
|
21
|
+
for (const f of active) {
|
|
22
|
+
const grants = capabilitiesFor(f).grants;
|
|
23
|
+
grantsByFinding.set(f, grants);
|
|
24
|
+
for (const c of grants)
|
|
25
|
+
present.add(c);
|
|
26
|
+
}
|
|
27
|
+
const namedChains = this.runNamedPass(present, active, grantsByFinding);
|
|
28
|
+
const covered = this.coveredSourceSinkPairs(namedChains, grantsByFinding);
|
|
29
|
+
const potentialChains = this.runEmergentPass(present, active, grantsByFinding, covered);
|
|
30
|
+
return [...namedChains, ...potentialChains].sort((a, b) => this.rank(a) - this.rank(b));
|
|
31
|
+
}
|
|
32
|
+
rank(c) {
|
|
33
|
+
// named before potential, then by severity
|
|
34
|
+
return (c.confidence === 'named' ? 0 : 100) + SEVERITY_ORDER[c.severity];
|
|
35
|
+
}
|
|
36
|
+
stepFor(f, grants) {
|
|
37
|
+
return {
|
|
38
|
+
findingId: f.id,
|
|
39
|
+
checkId: f.checkId,
|
|
40
|
+
capability: grants[0] ?? 'data-read',
|
|
41
|
+
title: f.title,
|
|
42
|
+
severity: f.riskLevel,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
runNamedPass(present, active, grantsByFinding) {
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const def of NAMED_CHAINS) {
|
|
48
|
+
const members = def.match(present, active);
|
|
49
|
+
if (!members || members.length === 0)
|
|
50
|
+
continue;
|
|
51
|
+
out.push({
|
|
52
|
+
id: def.id,
|
|
53
|
+
title: def.title,
|
|
54
|
+
severity: def.severity,
|
|
55
|
+
confidence: 'named',
|
|
56
|
+
narrative: def.narrative,
|
|
57
|
+
remediation: def.remediation,
|
|
58
|
+
steps: members.map((f) => this.stepFor(f, grantsByFinding.get(f) ?? [])),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** Record which (source, sink) capability pairs are already explained by a named chain. */
|
|
64
|
+
coveredSourceSinkPairs(named, grantsByFinding) {
|
|
65
|
+
const covered = new Set();
|
|
66
|
+
for (const chain of named) {
|
|
67
|
+
const caps = new Set();
|
|
68
|
+
for (const s of chain.steps)
|
|
69
|
+
caps.add(s.capability);
|
|
70
|
+
for (const src of SOURCE_CAPS) {
|
|
71
|
+
for (const sink of HIGH_IMPACT_SINKS) {
|
|
72
|
+
if (caps.has(src) && caps.has(sink))
|
|
73
|
+
covered.add(`${src}->${sink}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Also use the raw grants of member findings (capability per step is only the first grant).
|
|
78
|
+
for (const chain of named) {
|
|
79
|
+
const memberCaps = new Set();
|
|
80
|
+
for (const s of chain.steps) {
|
|
81
|
+
const f = [...grantsByFinding.keys()].find((k) => k.id === s.findingId);
|
|
82
|
+
if (f)
|
|
83
|
+
for (const c of grantsByFinding.get(f) ?? [])
|
|
84
|
+
memberCaps.add(c);
|
|
85
|
+
}
|
|
86
|
+
for (const src of SOURCE_CAPS) {
|
|
87
|
+
for (const sink of HIGH_IMPACT_SINKS) {
|
|
88
|
+
if (memberCaps.has(src) && memberCaps.has(sink))
|
|
89
|
+
covered.add(`${src}->${sink}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return covered;
|
|
94
|
+
}
|
|
95
|
+
runEmergentPass(present, active, grantsByFinding, covered) {
|
|
96
|
+
const out = [];
|
|
97
|
+
const seen = new Set();
|
|
98
|
+
for (const src of SOURCE_CAPS) {
|
|
99
|
+
if (!present.has(src))
|
|
100
|
+
continue;
|
|
101
|
+
for (const sink of HIGH_IMPACT_SINKS) {
|
|
102
|
+
if (!present.has(sink))
|
|
103
|
+
continue;
|
|
104
|
+
const key = `${src}->${sink}`;
|
|
105
|
+
if (covered.has(key) || seen.has(key))
|
|
106
|
+
continue;
|
|
107
|
+
seen.add(key);
|
|
108
|
+
// Gather the findings that grant the source and the sink (+ any code-exec bridge).
|
|
109
|
+
const members = [];
|
|
110
|
+
for (const f of active) {
|
|
111
|
+
const g = grantsByFinding.get(f) ?? [];
|
|
112
|
+
if (g.includes(src) || g.includes(sink) || g.includes('code-exec'))
|
|
113
|
+
members.push(f);
|
|
114
|
+
if (members.length >= MAX_STEPS)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (members.length === 0)
|
|
118
|
+
continue;
|
|
119
|
+
out.push({
|
|
120
|
+
id: `potential-${src}-${sink}`,
|
|
121
|
+
title: `Potential attack path: ${this.label(src)} → ${this.label(sink)}`,
|
|
122
|
+
severity: SINK_SEVERITY[sink] ?? 'MEDIUM',
|
|
123
|
+
confidence: 'potential',
|
|
124
|
+
narrative: `The org presents a ${this.label(src)} entry point and findings that grant ` +
|
|
125
|
+
`${this.label(sink)}. Review whether these can be combined into an exploit path.`,
|
|
126
|
+
remediation: 'Treat the contributing findings as a single risk: remediating any one of them breaks the path.',
|
|
127
|
+
steps: members.map((f) => this.stepFor(f, grantsByFinding.get(f) ?? [])),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
label(c) {
|
|
134
|
+
return c.replace(/-/g, ' ');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=ChainEngine.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RiskLevel } from '../findings/RiskLevel.js';
|
|
2
|
+
import type { Finding } from '../findings/Finding.js';
|
|
3
|
+
import type { Capability } from './Capability.js';
|
|
4
|
+
export interface NamedChainDef {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
severity: RiskLevel;
|
|
8
|
+
narrative: string;
|
|
9
|
+
remediation: string;
|
|
10
|
+
/** Returns the member findings (chain steps) if present in this org, else null. */
|
|
11
|
+
match(present: Set<Capability>, active: Finding[]): Finding[] | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const NAMED_CHAINS: NamedChainDef[];
|
|
14
|
+
//# sourceMappingURL=namedChains.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const has = (s, ...caps) => caps.every((c) => s.has(c));
|
|
2
|
+
const hasAny = (s, ...caps) => caps.some((c) => s.has(c));
|
|
3
|
+
const byIds = (active, ids) => active.filter((f) => ids.includes(f.id));
|
|
4
|
+
export const NAMED_CHAINS = [
|
|
5
|
+
{
|
|
6
|
+
id: 'unauth-bulk-exfil',
|
|
7
|
+
title: 'Unauthenticated bulk exfiltration',
|
|
8
|
+
severity: 'CRITICAL',
|
|
9
|
+
narrative: 'An unauthenticated guest foothold combines with guest-reachable code execution or public ' +
|
|
10
|
+
'external sharing to read business data in bulk without any login.',
|
|
11
|
+
remediation: 'Remove guest object/sharing access, ensure no guest-invokable Apex runs without sharing, ' +
|
|
12
|
+
'and set external OWD to Private. Grant portal access only via sharing sets.',
|
|
13
|
+
match(present, active) {
|
|
14
|
+
if (!has(present, 'unauth-foothold'))
|
|
15
|
+
return null;
|
|
16
|
+
if (!hasAny(present, 'code-exec', 'data-read-bulk', 'data-write'))
|
|
17
|
+
return null;
|
|
18
|
+
const steps = byIds(active, [
|
|
19
|
+
'guest-user-read-access', 'guest-user-write-access', 'guest-user-sharing-exposure', 'guest-user-baseline',
|
|
20
|
+
'guest-executable-apex-unprotected', 'guest-executable-apex-exposed',
|
|
21
|
+
'portal-exposed-apex-without-sharing', 'sharing-model-external-read', 'sharing-model-external-write',
|
|
22
|
+
'field-level-security-high', 'field-level-security-medium',
|
|
23
|
+
]);
|
|
24
|
+
return steps.length >= 2 ? steps : null;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'standard-to-takeover',
|
|
29
|
+
title: 'Standard user → org takeover',
|
|
30
|
+
severity: 'CRITICAL',
|
|
31
|
+
narrative: 'A low-trust authenticated user combines with a privilege-escalation permission ' +
|
|
32
|
+
'(assign permission sets, manage users, author apex, modify metadata) to reach full org control.',
|
|
33
|
+
remediation: 'Remove escalation permissions from non-admin profiles/permission sets and review who holds them.',
|
|
34
|
+
match(present, active) {
|
|
35
|
+
if (!hasAny(present, 'low-trust-authenticated', 'unauth-foothold'))
|
|
36
|
+
return null;
|
|
37
|
+
if (!hasAny(present, 'priv-esc', 'org-takeover'))
|
|
38
|
+
return null;
|
|
39
|
+
const steps = byIds(active, [
|
|
40
|
+
'sharing-model-external-read', 'sharing-model-external-write', 'guest-user-baseline',
|
|
41
|
+
'escalation-perms-found', 'users-author-apex', 'users-super-admin-combo',
|
|
42
|
+
]);
|
|
43
|
+
return steps.length >= 2 ? steps : null;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'cred-theft-pivot',
|
|
48
|
+
title: 'Credential theft → external pivot',
|
|
49
|
+
severity: 'CRITICAL',
|
|
50
|
+
narrative: 'Exposed secrets (hardcoded credentials, credentials in custom labels, debug logs, or broad CORS) ' +
|
|
51
|
+
'combine with an external egress path (named credential or remote site) to exfiltrate data to attacker infrastructure.',
|
|
52
|
+
remediation: 'Rotate and remove exposed secrets, tighten CORS origins, and review external callout endpoints.',
|
|
53
|
+
match(present, active) {
|
|
54
|
+
if (!has(present, 'credential-theft', 'external-egress'))
|
|
55
|
+
return null;
|
|
56
|
+
const steps = byIds(active, [
|
|
57
|
+
'hardcoded-credentials-found', 'custom-labels-credential-value-match', 'custom-labels-credential-name-match',
|
|
58
|
+
'debug-log-active-traces', 'cors-wildcard-origin', 'cors-broad-origin',
|
|
59
|
+
'named-credentials-inventory', 'named-credentials-http-endpoint', 'remote-sites-inventory',
|
|
60
|
+
]);
|
|
61
|
+
return steps.length >= 2 ? steps : null;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'soql-injection-read',
|
|
66
|
+
title: 'SOQL injection → mass read',
|
|
67
|
+
severity: 'HIGH',
|
|
68
|
+
narrative: 'Injectable dynamic SOQL combines with bulk data readability to let an attacker extract large datasets.',
|
|
69
|
+
remediation: 'Use bind variables in all dynamic SOQL and enforce CRUD/FLS; restrict bulk read access.',
|
|
70
|
+
match(present, active) {
|
|
71
|
+
if (!has(present, 'code-exec'))
|
|
72
|
+
return null;
|
|
73
|
+
const inj = byIds(active, ['soql-injection-risk']);
|
|
74
|
+
if (inj.length === 0)
|
|
75
|
+
return null;
|
|
76
|
+
const sink = byIds(active, [
|
|
77
|
+
'sharing-model-external-read', 'sharing-model-external-write',
|
|
78
|
+
'field-level-security-high', 'field-level-security-medium', 'users-view-all-data',
|
|
79
|
+
]);
|
|
80
|
+
return sink.length > 0 ? [...inj, ...sink] : null;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'mfa-bypass-admin',
|
|
85
|
+
title: 'MFA bypass → privileged compromise',
|
|
86
|
+
severity: 'HIGH',
|
|
87
|
+
narrative: 'Weak MFA enforcement or trusted-IP MFA bypass combines with the presence of highly-privileged ' +
|
|
88
|
+
'accounts, so a credential-stuffing or phishing attacker can take over an admin without a second factor.',
|
|
89
|
+
remediation: 'Enforce MFA for all internal users, remove trusted-IP MFA bypass ranges, and minimise privileged accounts.',
|
|
90
|
+
match(_present, active) {
|
|
91
|
+
const weakness = byIds(active, [
|
|
92
|
+
'trusted-ip-broad-ranges', 'internal-user-mfa-gaps', 'mfa-portal-users-without-enforcement',
|
|
93
|
+
]);
|
|
94
|
+
const targets = byIds(active, ['users-modify-all-data', 'users-view-all-data', 'users-super-admin-combo']);
|
|
95
|
+
return weakness.length > 0 && targets.length > 0 ? [...weakness, ...targets] : null;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
//# sourceMappingURL=namedChains.js.map
|
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import { buildAuditResult } from '../findings/scoring.js';
|
|
2
|
+
import { getComplianceTags } from '../findings/ComplianceMapping.js';
|
|
3
|
+
import { ChainEngine } from '../chains/ChainEngine.js';
|
|
4
|
+
const PERMISSION_ERROR_CODES = new Set([
|
|
5
|
+
'INSUFFICIENT_ACCESS_RIGHTS',
|
|
6
|
+
'INVALID_CROSS_REFERENCE_KEY',
|
|
7
|
+
'ENTITY_IS_INACCESSIBLE',
|
|
8
|
+
'INVALID_FIELD',
|
|
9
|
+
'INVALID_TYPE',
|
|
10
|
+
]);
|
|
11
|
+
function isPermissionError(err) {
|
|
12
|
+
if (!(err instanceof Error))
|
|
13
|
+
return false;
|
|
14
|
+
const code = err.errorCode ?? '';
|
|
15
|
+
const msg = err.message ?? '';
|
|
16
|
+
return (PERMISSION_ERROR_CODES.has(code) ||
|
|
17
|
+
msg.includes('INSUFFICIENT_ACCESS') ||
|
|
18
|
+
msg.includes('insufficient access') ||
|
|
19
|
+
msg.includes('INVALID_FIELD') ||
|
|
20
|
+
msg.includes('entity type cannot be queried'));
|
|
21
|
+
}
|
|
2
22
|
function buildErrorFinding(check, err) {
|
|
3
23
|
const msg = err instanceof Error ? err.message : String(err);
|
|
24
|
+
const inconclusive = isPermissionError(err);
|
|
4
25
|
return {
|
|
5
26
|
id: `${check.id}-error`,
|
|
6
27
|
checkId: check.id,
|
|
7
28
|
category: check.category,
|
|
8
29
|
riskLevel: 'INFO',
|
|
9
|
-
title: `${check.name}: check failed`,
|
|
10
|
-
detail:
|
|
11
|
-
|
|
30
|
+
title: `${check.name}: ${inconclusive ? 'insufficient permissions' : 'check failed'}`,
|
|
31
|
+
detail: inconclusive
|
|
32
|
+
? `This check could not gather evidence because the running user lacks the required permissions: ${msg}`
|
|
33
|
+
: `This check encountered an error and could not complete: ${msg}`,
|
|
34
|
+
remediation: inconclusive
|
|
35
|
+
? 'Grant the audit user the permissions listed in the tool documentation, then re-run the audit.'
|
|
36
|
+
: 'Review the error message and verify the running user has the required permissions.',
|
|
37
|
+
inconclusive: inconclusive || undefined,
|
|
12
38
|
};
|
|
13
39
|
}
|
|
14
40
|
export class CheckEngine {
|
|
@@ -30,7 +56,8 @@ export class CheckEngine {
|
|
|
30
56
|
onProgress?.(i + 1, total, check.name);
|
|
31
57
|
try {
|
|
32
58
|
const result = await check.run(this.ctx);
|
|
33
|
-
|
|
59
|
+
const tags = getComplianceTags(check.id);
|
|
60
|
+
findings.push(...result.findings.map((f) => ({ ...f, checkId: check.id, complianceTags: tags })));
|
|
34
61
|
if (result.metrics) {
|
|
35
62
|
metrics = { ...metrics, ...result.metrics };
|
|
36
63
|
}
|
|
@@ -39,7 +66,8 @@ export class CheckEngine {
|
|
|
39
66
|
findings.push(buildErrorFinding(check, err));
|
|
40
67
|
}
|
|
41
68
|
}
|
|
42
|
-
|
|
69
|
+
const attackChains = new ChainEngine().correlate(findings);
|
|
70
|
+
return buildAuditResult(this.ctx, findings, metrics, this.scoringConfig, attackChains);
|
|
43
71
|
}
|
|
44
72
|
validateCacheOrdering() {
|
|
45
73
|
const populated = new Set();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class AnonymousApexAuditCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "anonymous-apex-audit";
|
|
5
|
+
readonly name = "Anonymous Apex Execution Audit";
|
|
6
|
+
readonly category = "Code Security";
|
|
7
|
+
readonly description = "Detects anonymous Apex execution in the last 90 days via SetupAuditTrail";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=AnonymousApexAuditCheck.d.ts.map
|