@cclabsnz/sf-audit 1.25.1 → 1.27.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/CHANGELOG.md +106 -1
- package/README.md +14 -2
- package/lib/chains/CapabilityRegistry.js +4 -8
- package/lib/chains/namedChains.js +2 -8
- package/lib/checks/impl/ConnectedAppInactivityCheck.js +10 -5
- package/lib/checks/impl/ConnectedAppScopeCheck.js +6 -8
- package/lib/checks/impl/CustomSettingsCheck.d.ts +14 -1
- package/lib/checks/impl/CustomSettingsCheck.js +120 -37
- package/lib/checks/impl/GuestRecordAccessPolicyCheck.d.ts +11 -20
- package/lib/checks/impl/GuestRecordAccessPolicyCheck.js +18 -111
- package/lib/checks/impl/GuestTrafficAnomalyCheck.js +1 -1
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.d.ts +2 -2
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.js +27 -38
- package/lib/checks/registry.js +1 -1
- package/lib/checks/selection.d.ts +13 -0
- package/lib/checks/selection.js +24 -0
- package/lib/commands/audit/explain.d.ts +16 -0
- package/lib/commands/audit/explain.js +79 -0
- package/lib/commands/audit/security.d.ts +4 -2
- package/lib/commands/audit/security.js +22 -2
- package/lib/findings/CheckMeta.js +3 -3
- package/lib/findings/status.d.ts +8 -0
- package/lib/findings/status.js +20 -0
- package/lib/findings/summary.d.ts +59 -0
- package/lib/findings/summary.js +48 -0
- package/lib/renderers/HtmlRenderer.js +3 -20
- package/lib/report/ActionPlan.d.ts +2 -0
- package/lib/report/ActionPlan.js +5 -0
- package/lib/report/explain.d.ts +63 -0
- package/lib/report/explain.js +102 -0
- package/package.json +1 -1
|
@@ -1,52 +1,22 @@
|
|
|
1
|
-
import { fieldsOf } from '../support/schema.js';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* status is unknown.
|
|
6
|
-
*/
|
|
7
|
-
function releaseUpdateEnabled(status) {
|
|
8
|
-
if (status === 'Invoked' || status === 'Revocable')
|
|
9
|
-
return true;
|
|
10
|
-
if (status === 'Invocable' || status === 'Revoked')
|
|
11
|
-
return false;
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Verifies the PREVENTIVE guardrail that stops the guest-ownership-defeats-OWD
|
|
16
|
-
* exfiltration vector: "Secure guest user record access".
|
|
2
|
+
* The PREVENTIVE guardrail that stops guest-owned records defeating a Private OWD: "Secure guest
|
|
3
|
+
* user record access". With it, guests reach records only through guest user sharing rules.
|
|
17
4
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* records they submit, which is what otherwise nullifies a Private OWD for
|
|
24
|
-
* guest-submitted records (an owner can always read its own records).
|
|
5
|
+
* Salesforce has enforced it in every org since Winter '21. From API 50.0,
|
|
6
|
+
* SharingSettings.enableSecureGuestAccess is always true and setting it has no effect, and the
|
|
7
|
+
* Release Update that once carried it is no longer served. So there is no state to read: this
|
|
8
|
+
* check states the platform guarantee for orgs with guest users. It once matched a Release Update
|
|
9
|
+
* by its wording ("guest" plus "record access"), which could only pick up a different guest update.
|
|
25
10
|
*
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* - update present & IsEnabled = false => HIGH: guardrail available, NOT activated.
|
|
30
|
-
* - update present & IsEnabled = true => pass: guardrail enforced.
|
|
31
|
-
* - update absent (older orgs where it was auto-activated long ago, or not
|
|
32
|
-
* surfaced) => LOW advisory: confirm the Sharing
|
|
33
|
-
* Settings checkboxes manually, since the API no longer exposes the toggle.
|
|
34
|
-
* Degrades to inconclusive if guest users or the Tooling API cannot be read.
|
|
11
|
+
* The residual risk is the symptom, not the policy: records a guest already owns, or shares a
|
|
12
|
+
* guest sharing rule grants. GuestObjectExposureCheck and GuestUserAccessCheck read those directly.
|
|
13
|
+
* Degrades to inconclusive if guest users cannot be read.
|
|
35
14
|
*/
|
|
36
15
|
export class GuestRecordAccessPolicyCheck {
|
|
37
16
|
id = 'guest-record-access-policy';
|
|
38
17
|
name = 'Secure Guest User Record Access';
|
|
39
18
|
category = 'Access Control';
|
|
40
|
-
description = '
|
|
41
|
-
// Matches the release update / sharing setting regardless of the exact label
|
|
42
|
-
// Salesforce uses across versions: the name/description mentions guests AND
|
|
43
|
-
// record access.
|
|
44
|
-
matchesSecureGuestAccess(u) {
|
|
45
|
-
const hay = `${u.Name} ${u.Description ?? ''}`.toLowerCase();
|
|
46
|
-
const guest = hay.includes('guest');
|
|
47
|
-
const record = hay.includes('record access') || hay.includes('record-level') || hay.includes("access to records") || hay.includes('securely access');
|
|
48
|
-
return guest && record;
|
|
49
|
-
}
|
|
19
|
+
description = 'Confirms the platform enforces "Secure guest user record access" for orgs with guest users, the guardrail that stops guest-owned records defeating a Private org-wide default';
|
|
50
20
|
async run(ctx) {
|
|
51
21
|
const findings = [];
|
|
52
22
|
const setupUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/SecuritySharing/page`;
|
|
@@ -66,82 +36,19 @@ export class GuestRecordAccessPolicyCheck {
|
|
|
66
36
|
passed: true,
|
|
67
37
|
title: 'No active guest users',
|
|
68
38
|
detail: 'There are no active guest users, so guest record-access enforcement has no attack surface to protect.',
|
|
69
|
-
remediation: 'If an Experience Cloud or Sites site is added later,
|
|
70
|
-
});
|
|
71
|
-
return { findings };
|
|
72
|
-
}
|
|
73
|
-
let updates;
|
|
74
|
-
try {
|
|
75
|
-
// Current orgs serve Release Updates as Tooling ReleaseUpdate (Status 'Invocable' = available
|
|
76
|
-
// but not enabled); CriticalUpdate is the older object. Read whichever this org serves.
|
|
77
|
-
if (await fieldsOf(ctx, 'ReleaseUpdate', 'tooling')) {
|
|
78
|
-
const rows = await ctx.tooling.query('SELECT Id, DeveloperName, Title, Description, Status FROM ReleaseUpdate');
|
|
79
|
-
updates = rows.map((r) => ({
|
|
80
|
-
Id: r.Id,
|
|
81
|
-
Name: r.Title ?? r.DeveloperName,
|
|
82
|
-
Description: r.Description,
|
|
83
|
-
IsEnabled: releaseUpdateEnabled(r.Status),
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
updates = await ctx.tooling.query('SELECT Id, Name, Description, IsEnabled FROM CriticalUpdate');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
findings.push(this.inconclusive('guest-record-access-policy-tooling-inaccessible', 'Release updates could not be queried', err));
|
|
92
|
-
return { findings };
|
|
93
|
-
}
|
|
94
|
-
const match = updates.find((u) => this.matchesSecureGuestAccess(u));
|
|
95
|
-
if (match && match.IsEnabled === false) {
|
|
96
|
-
findings.push({
|
|
97
|
-
id: 'guest-record-access-policy-not-enforced',
|
|
98
|
-
category: this.category,
|
|
99
|
-
riskLevel: 'HIGH',
|
|
100
|
-
title: `"Secure guest user record access" is available but NOT activated (${guests.length} active guest user(s))`,
|
|
101
|
-
detail: 'The "Secure guest user record access" Release Update is present but not enabled. Until it is activated, guest users can be granted record access through legacy sharing mechanisms and can own the records they submit via public forms. Because an owner can always read its own records, a Private org-wide default does not protect guest-owned records — this is the exact vector that turns a public submission form into an unauthenticated bulk-read surface.',
|
|
102
|
-
remediation: 'Activate "Secure guest user record access" in Setup → Release Updates, and enable "Assign new records created by guest users to the default owner" in Setup → Sharing Settings. Reparent existing guest-owned records to an internal default/integration owner. After enforcement, grant guest read access only through explicit, minimal guest user sharing rules.',
|
|
103
|
-
affectedItems: [{ label: match.Name, url: `${ctx.orgInfo.instanceUrl}/lightning/setup/ReleaseUpdates/home`, note: 'Release Update present, IsEnabled = false' }],
|
|
104
|
-
});
|
|
105
|
-
return { findings };
|
|
106
|
-
}
|
|
107
|
-
if (match && match.IsEnabled === true) {
|
|
108
|
-
findings.push({
|
|
109
|
-
id: 'guest-record-access-policy-enforced',
|
|
110
|
-
category: this.category,
|
|
111
|
-
riskLevel: 'LOW',
|
|
112
|
-
passed: true,
|
|
113
|
-
title: '"Secure guest user record access" is enforced',
|
|
114
|
-
detail: 'The "Secure guest user record access" Release Update is enabled, so guests cannot be granted record access except through explicit guest user sharing rules. Verify "Assign new records created by guest users to the default owner" is also enabled so guests do not own the records they submit.',
|
|
115
|
-
remediation: 'Confirm "Assign new records created by guest users to the default owner" is enabled in Setup → Sharing Settings, and periodically review guest user sharing rules for least privilege.',
|
|
116
|
-
affectedItems: [{ label: match.Name, url: setupUrl, note: 'Release Update enabled' }],
|
|
117
|
-
});
|
|
118
|
-
return { findings };
|
|
119
|
-
}
|
|
120
|
-
if (match) {
|
|
121
|
-
// Present, but its status says neither enabled nor available (e.g. a new status value):
|
|
122
|
-
// never read as enforced. MN-051.
|
|
123
|
-
findings.push({
|
|
124
|
-
id: 'guest-record-access-policy-verify-manually',
|
|
125
|
-
category: this.category,
|
|
126
|
-
riskLevel: 'LOW',
|
|
127
|
-
title: `Confirm guest record-access guardrails manually (${guests.length} active guest user(s))`,
|
|
128
|
-
detail: `The "Secure guest user record access" Release Update is present, but its status does not say whether it is enabled, so enforcement is not assumed.`,
|
|
129
|
-
remediation: 'In Setup → Release Updates and Setup → Sharing Settings, confirm "Secure guest user record access" is on and "Assign new records created by guest users to the default owner" is enabled.',
|
|
130
|
-
affectedItems: [{ label: match.Name, url: `${ctx.orgInfo.instanceUrl}/lightning/setup/ReleaseUpdates/home`, note: 'Status unknown' }],
|
|
39
|
+
remediation: 'If an Experience Cloud or Sites site is added later, review its guest user sharing rules and guest-owned records before going live.',
|
|
131
40
|
});
|
|
132
41
|
return { findings };
|
|
133
42
|
}
|
|
134
|
-
// No matching update surfaced — typical of orgs where it was auto-activated in
|
|
135
|
-
// an earlier release and no longer appears in CriticalUpdate. We got data, so
|
|
136
|
-
// this is advisory (LOW), not inconclusive: point the operator at the manual toggles.
|
|
137
43
|
findings.push({
|
|
138
|
-
id: 'guest-record-access-policy-
|
|
44
|
+
id: 'guest-record-access-policy-enforced',
|
|
139
45
|
category: this.category,
|
|
140
46
|
riskLevel: 'LOW',
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
47
|
+
passed: true,
|
|
48
|
+
title: `"Secure guest user record access" is enforced by the platform (${guests.length} active guest user(s))`,
|
|
49
|
+
detail: "Salesforce has enforced secure guest user record access in every org since Winter '21, and from API 50.0 the setting is always on and cannot be turned off. Guests get no access from the org-wide default, and new record access for guests comes only through guest user sharing rules. Records a guest owns, shares granted before Winter '21, and Apex or flows that run without sharing can still reach records.",
|
|
50
|
+
remediation: 'Nothing to switch on. Review the residual paths: guest-object-exposure and guest-user-access report guest-owned and guest-shared records, and guest-executable-apex reports Apex guests can run without sharing.',
|
|
51
|
+
affectedItems: [{ label: 'Sharing Settings', url: setupUrl, note: 'Enforced by the platform' }],
|
|
145
52
|
});
|
|
146
53
|
return { findings };
|
|
147
54
|
}
|
|
@@ -155,7 +155,7 @@ export class GuestTrafficAnomalyCheck {
|
|
|
155
155
|
riskLevel: 'HIGH',
|
|
156
156
|
title: `${reconIps.length} source IP(s) ran a GraphQL object-enumeration (totalCount) sweep as a guest`,
|
|
157
157
|
detail: 'These unauthenticated source IPs issued GraphQL queries that request only totalCount across many distinct objects — the signature of reconnaissance that maps the guest-readable data surface before bulk extraction. This is exactly the pre-attack recon pattern seen through aura://RecordUiController/ACTION$executeGraphQL on Experience Cloud sites.',
|
|
158
|
-
remediation: 'Treat these IPs as hostile and block them at the WAF/CDN. Then close the surface they were mapping:
|
|
158
|
+
remediation: 'Treat these IPs as hostile and block them at the WAF/CDN. Then close the surface they were mapping: remove guest sharing rules and guest object read permissions, and reassign guest-owned records. Enable Threat Detection storage and a Transaction Security Policy to catch this in real time.',
|
|
159
159
|
affectedItems: reconIps
|
|
160
160
|
.sort((a, b) => b[1].reconEntities.size - a[1].reconEntities.size)
|
|
161
161
|
.slice(0, 20)
|
|
@@ -2,9 +2,9 @@ import type { AuditContext } from '@cclabsnz/sf-core';
|
|
|
2
2
|
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
3
|
export declare class OauthDeviceAndAssetTokenFlowsCheck implements SecurityCheck {
|
|
4
4
|
readonly id = "oauth-device-and-asset-token-flows";
|
|
5
|
-
readonly name = "OAuth
|
|
5
|
+
readonly name = "OAuth Username-Password Flow";
|
|
6
6
|
readonly category = "Identity & Access";
|
|
7
|
-
readonly description = "Flags OAuth 2.0
|
|
7
|
+
readonly description = "Flags the OAuth 2.0 Username-Password Flow when OAuth and OpenID Connect Settings do not block it.";
|
|
8
8
|
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=OauthDeviceAndAssetTokenFlowsCheck.d.ts.map
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
/** Settings types outside jsforce's schema come back with string values. */
|
|
2
|
+
function asBoolean(v) {
|
|
3
|
+
if (v === true || v === 'true')
|
|
4
|
+
return true;
|
|
5
|
+
if (v === false || v === 'false')
|
|
6
|
+
return false;
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
1
9
|
export class OauthDeviceAndAssetTokenFlowsCheck {
|
|
2
10
|
id = 'oauth-device-and-asset-token-flows';
|
|
3
|
-
name = 'OAuth
|
|
11
|
+
name = 'OAuth Username-Password Flow';
|
|
4
12
|
category = 'Identity & Access';
|
|
5
|
-
description = 'Flags OAuth 2.0
|
|
13
|
+
description = 'Flags the OAuth 2.0 Username-Password Flow when OAuth and OpenID Connect Settings do not block it.';
|
|
6
14
|
async run(ctx) {
|
|
7
15
|
const findings = [];
|
|
8
16
|
const oauthUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/OauthOidcSettings/home`;
|
|
9
|
-
// Org settings are the only evidence read.
|
|
10
|
-
// a boolean: a failed read, an absent Metadata client or a missing
|
|
17
|
+
// Org settings are the only evidence read. The flow counts as blocked or not only when the
|
|
18
|
+
// read returned the field as a boolean: a failed read, an absent Metadata client or a missing
|
|
19
|
+
// field is not "blocked".
|
|
11
20
|
let settings = null;
|
|
12
21
|
if (ctx.metadata) {
|
|
13
22
|
try {
|
|
@@ -17,64 +26,44 @@ export class OauthDeviceAndAssetTokenFlowsCheck {
|
|
|
17
26
|
settings = null;
|
|
18
27
|
}
|
|
19
28
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
if (device === true) {
|
|
23
|
-
findings.push({
|
|
24
|
-
id: 'oauth-device-flow-enabled',
|
|
25
|
-
category: this.category,
|
|
26
|
-
riskLevel: 'HIGH',
|
|
27
|
-
title: 'OAuth 2.0 Device Flow is ENABLED in org settings',
|
|
28
|
-
detail: 'OAuth 2.0 Device Flow allows a user to authorize a token by entering an 8-character code on a legitimate verification URL. Attackers frequently use Device Code phishing to bypass standard browser-based conditional access and MFA controls, obtaining persistent refresh tokens.',
|
|
29
|
-
remediation: 'Disable OAuth 2.0 Device Flow in Setup → OAuth and OpenID Connect Settings unless strictly required for headless devices.',
|
|
30
|
-
affectedItems: [
|
|
31
|
-
{
|
|
32
|
-
label: 'OAuth and OpenID Connect Settings',
|
|
33
|
-
url: oauthUrl,
|
|
34
|
-
note: 'Disable "Allow OAuth Device Flow"',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (password === true) {
|
|
29
|
+
const blocked = asBoolean(settings?.blockOAuthUnPwFlow);
|
|
30
|
+
if (blocked === false) {
|
|
40
31
|
findings.push({
|
|
41
32
|
id: 'oauth-password-flow-enabled',
|
|
42
33
|
category: this.category,
|
|
43
34
|
riskLevel: 'HIGH',
|
|
44
|
-
title: 'OAuth 2.0 Username-Password Flow is
|
|
35
|
+
title: 'OAuth 2.0 Username-Password Flow is not blocked in org settings',
|
|
45
36
|
detail: 'The Resource Owner Password Credentials (ROPC / Username-Password) flow allows exchanging raw credentials directly for access tokens, completely bypassing interactive SSO redirects, browser-based MFA, and device trust policies.',
|
|
46
|
-
remediation: '
|
|
37
|
+
remediation: 'Turn on "Block OAuth Username-Password Flows" in Setup → OAuth and OpenID Connect Settings, and migrate integrations to OAuth 2.0 Client Credentials or JWT Bearer flow.',
|
|
47
38
|
affectedItems: [
|
|
48
39
|
{
|
|
49
40
|
label: 'OAuth and OpenID Connect Settings',
|
|
50
41
|
url: oauthUrl,
|
|
51
|
-
note: '
|
|
42
|
+
note: 'Block OAuth Username-Password Flows',
|
|
52
43
|
},
|
|
53
44
|
],
|
|
54
45
|
});
|
|
55
46
|
}
|
|
56
|
-
if (
|
|
47
|
+
else if (blocked === true) {
|
|
57
48
|
findings.push({
|
|
58
49
|
id: 'oauth-device-and-asset-flows-ok',
|
|
59
50
|
category: this.category,
|
|
60
51
|
riskLevel: 'LOW',
|
|
61
52
|
passed: true,
|
|
62
|
-
title: '
|
|
63
|
-
detail: '
|
|
64
|
-
remediation: 'Keep
|
|
53
|
+
title: 'OAuth Username-Password Flow is blocked org-wide',
|
|
54
|
+
detail: 'OAuth and OpenID Connect Settings block the Username-Password Flow, so no connected app can exchange a raw password for a token. Device Flow is switched on per connected app ("Enable for Device Flow"), and connected app metadata does not report it, so review it in each app that needs it.',
|
|
55
|
+
remediation: 'Keep the Username-Password Flow blocked, and enable Device Flow only on connected apps for headless devices.',
|
|
65
56
|
});
|
|
66
57
|
}
|
|
67
|
-
else
|
|
68
|
-
const unread = [device === undefined && 'Device Flow', password === undefined && 'Username-Password Flow']
|
|
69
|
-
.filter(Boolean)
|
|
70
|
-
.join(' and ');
|
|
58
|
+
else {
|
|
71
59
|
findings.push({
|
|
72
60
|
id: 'oauth-device-and-asset-flows-advisory',
|
|
73
61
|
category: this.category,
|
|
74
62
|
riskLevel: 'INFO',
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
inconclusive: true,
|
|
64
|
+
title: 'Verify the OAuth Username-Password Flow setting manually',
|
|
65
|
+
detail: 'This run could not read whether OAuth and OpenID Connect Settings block the Username-Password Flow, so whether it is allowed is unknown. The flow lets a token be issued for a raw password, bypassing MFA and conditional access.',
|
|
66
|
+
remediation: 'In Setup → OAuth and OpenID Connect Settings, confirm "Block OAuth Username-Password Flows" is on unless a documented integration needs the flow.',
|
|
78
67
|
affectedItems: [{ label: 'OAuth and OpenID Connect Settings', url: oauthUrl }],
|
|
79
68
|
});
|
|
80
69
|
}
|
package/lib/checks/registry.js
CHANGED
|
@@ -178,7 +178,7 @@ export const CHECKS = [
|
|
|
178
178
|
new PublicContentExposureCheck(), // externally available Documents + public static resources
|
|
179
179
|
new GuestObjectExposureCheck(), // auto-discovered guest bulk-read surface (UI API) + ownership-defeats-OWD
|
|
180
180
|
new GuestSiteOptionsCheck(), // guest file access + guest member visibility on Experience sites
|
|
181
|
-
new GuestRecordAccessPolicyCheck(), // "Secure guest user record access"
|
|
181
|
+
new GuestRecordAccessPolicyCheck(), // "Secure guest user record access": platform-enforced since API 50.0
|
|
182
182
|
new ThreatDetectionCheck(), // Guest User Anomaly / Threat Detection event storage enabled
|
|
183
183
|
new LoginAccessPolicyCheck(), // delegated admin + login-as impersonation paths
|
|
184
184
|
new DataExportAccessCheck(), // Weekly Export / API+ViewAll bulk-exfil capability
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SecurityCheck } from './SecurityCheck.js';
|
|
2
|
+
/**
|
|
3
|
+
* A --checks selection plus the checks that fill the cache it reads. CheckEngine refuses a check
|
|
4
|
+
* whose cache keys no earlier check populates, so `--checks apex-sharing` alone could not run.
|
|
5
|
+
* Each needed key is filled by the earliest registry check that populates it, transitively, and the
|
|
6
|
+
* result keeps registry order so providers run before their readers. `added` lists the providers
|
|
7
|
+
* the user did not ask for, so the command can say why they ran.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withCacheProviders(selected: readonly SecurityCheck[], registry: readonly SecurityCheck[]): {
|
|
10
|
+
checks: SecurityCheck[];
|
|
11
|
+
added: SecurityCheck[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A --checks selection plus the checks that fill the cache it reads. CheckEngine refuses a check
|
|
3
|
+
* whose cache keys no earlier check populates, so `--checks apex-sharing` alone could not run.
|
|
4
|
+
* Each needed key is filled by the earliest registry check that populates it, transitively, and the
|
|
5
|
+
* result keeps registry order so providers run before their readers. `added` lists the providers
|
|
6
|
+
* the user did not ask for, so the command can say why they ran.
|
|
7
|
+
*/
|
|
8
|
+
export function withCacheProviders(selected, registry) {
|
|
9
|
+
const chosen = new Set(selected);
|
|
10
|
+
const pending = [...selected];
|
|
11
|
+
while (pending.length > 0) {
|
|
12
|
+
const check = pending.pop();
|
|
13
|
+
for (const key of check.dependsOnCache ?? []) {
|
|
14
|
+
const provider = registry.find((c) => (c.populatesCache ?? []).includes(key));
|
|
15
|
+
if (provider && !chosen.has(provider)) {
|
|
16
|
+
chosen.add(provider);
|
|
17
|
+
pending.push(provider);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const checks = registry.filter((c) => chosen.has(c));
|
|
22
|
+
return { checks, added: checks.filter((c) => !selected.includes(c)) };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { type Explanation } from '../../report/explain.js';
|
|
3
|
+
export default class AuditExplainCommand extends SfCommand<Explanation> {
|
|
4
|
+
static summary: string;
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static args: {
|
|
8
|
+
id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<Explanation>;
|
|
14
|
+
private print;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { Args } from '@oclif/core';
|
|
3
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
4
|
+
import { explain, ExplainError, parseResult } from '../../report/explain.js';
|
|
5
|
+
export default class AuditExplainCommand extends SfCommand {
|
|
6
|
+
static summary = 'Explain a check, or one finding from an audit run';
|
|
7
|
+
static description = 'With a check id: what the check looks for, its domain, effort, impact and compliance mapping. With --file and a finding id: the finding from that run, what it affects, the attack chains it is part of and the fix-first action that closes it.';
|
|
8
|
+
static examples = [
|
|
9
|
+
'<%= config.bin %> <%= command.id %> apex-sharing',
|
|
10
|
+
'<%= config.bin %> <%= command.id %> guest-user-sharing-exposure --file ./audit.json',
|
|
11
|
+
];
|
|
12
|
+
static args = {
|
|
13
|
+
id: Args.string({ description: 'A check id (sf audit list) or a finding id from a report.', required: true }),
|
|
14
|
+
};
|
|
15
|
+
static flags = {
|
|
16
|
+
file: Flags.file({
|
|
17
|
+
summary: 'A report from sf audit security --json (full result, not --digest or --summary).',
|
|
18
|
+
exists: true,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
async run() {
|
|
22
|
+
const { args, flags } = await this.parse(AuditExplainCommand);
|
|
23
|
+
let result;
|
|
24
|
+
if (flags.file) {
|
|
25
|
+
try {
|
|
26
|
+
result = parseResult(readFileSync(flags.file, 'utf8'));
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
this.error(`Could not read an audit result from ${flags.file}: ${err instanceof Error ? err.message : String(err)}`, {
|
|
30
|
+
suggestions: ['Pass the output of sf audit security --json, without --digest or --summary.'],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let out;
|
|
35
|
+
try {
|
|
36
|
+
out = explain(args.id, result);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err instanceof ExplainError)
|
|
40
|
+
this.error(err.message, { suggestions: [err.suggestion] });
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
this.print(out);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
print(out) {
|
|
47
|
+
const c = out.check;
|
|
48
|
+
this.log(`${c.name} (${c.id})`);
|
|
49
|
+
if (c.domain)
|
|
50
|
+
this.log(`Domain: ${c.domain}`);
|
|
51
|
+
this.log(c.description);
|
|
52
|
+
if (c.impact)
|
|
53
|
+
this.log(`\nWhy it matters: ${c.impact}`);
|
|
54
|
+
if (c.effort)
|
|
55
|
+
this.log(`Typical effort: ${c.effort}`);
|
|
56
|
+
if (c.complianceTags.length > 0)
|
|
57
|
+
this.log(`Maps to: ${c.complianceTags.join(', ')}`);
|
|
58
|
+
const f = out.finding;
|
|
59
|
+
if (f) {
|
|
60
|
+
this.log(`\n${f.severity} ${f.status}: ${f.title}`);
|
|
61
|
+
this.log(f.detail);
|
|
62
|
+
this.log(`\nFix: ${f.remediation}`);
|
|
63
|
+
if (f.affectedCount > 0) {
|
|
64
|
+
const more = f.affectedCount > f.affectedSample.length ? ` and ${f.affectedCount - f.affectedSample.length} more` : '';
|
|
65
|
+
this.log(`Affects: ${f.affectedSample.join(', ')}${more}`);
|
|
66
|
+
}
|
|
67
|
+
for (const ch of f.chains)
|
|
68
|
+
this.log(`Part of ${ch.label} ${ch.title} (${ch.severity})${ch.breaksChain ? ': fixing this breaks it' : ''}`);
|
|
69
|
+
if (f.action)
|
|
70
|
+
this.log(`Fix-first plan: action ${f.action.rank} (${f.action.wave}): ${f.action.title}`);
|
|
71
|
+
}
|
|
72
|
+
if (out.findings) {
|
|
73
|
+
this.log(`\nIn this run:`);
|
|
74
|
+
for (const x of out.findings)
|
|
75
|
+
this.log(` ${x.id} ${x.status === 'open' ? x.severity : x.status} ${x.title}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
2
|
import type { AuditResult } from '../../findings/AuditResult.js';
|
|
3
3
|
import { type AuditDigest } from '../../findings/digest.js';
|
|
4
|
-
|
|
4
|
+
import { type AuditSummary } from '../../findings/summary.js';
|
|
5
|
+
export default class SecurityAuditCommand extends SfCommand<AuditResult | AuditDigest | AuditSummary> {
|
|
5
6
|
static summary: string;
|
|
6
7
|
static description: string;
|
|
7
8
|
static examples: string[];
|
|
@@ -12,6 +13,7 @@ export default class SecurityAuditCommand extends SfCommand<AuditResult | AuditD
|
|
|
12
13
|
waivers: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
14
|
'fail-on': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
15
|
digest: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
summary: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
17
|
'fail-on-inconclusive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
18
|
checks: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
19
|
'scoring-config': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -23,7 +25,7 @@ export default class SecurityAuditCommand extends SfCommand<AuditResult | AuditD
|
|
|
23
25
|
'no-history': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
24
26
|
'keep-history': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
25
27
|
};
|
|
26
|
-
run(): Promise<AuditResult | AuditDigest>;
|
|
28
|
+
run(): Promise<AuditResult | AuditDigest | AuditSummary>;
|
|
27
29
|
/** Resolve --checks to the checks to run, erroring on any unknown ID. */
|
|
28
30
|
private resolveChecks;
|
|
29
31
|
/** Resolve --format to a validated list, erroring on any unknown format. */
|
|
@@ -3,6 +3,7 @@ import * as path from 'node:path';
|
|
|
3
3
|
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
4
4
|
import { CheckEngine } from '../../checks/CheckEngine.js';
|
|
5
5
|
import { CHECKS } from '../../checks/registry.js';
|
|
6
|
+
import { withCacheProviders } from '../../checks/selection.js';
|
|
6
7
|
import { JsonRenderer } from '../../renderers/JsonRenderer.js';
|
|
7
8
|
import { HtmlRenderer } from '../../renderers/HtmlRenderer.js';
|
|
8
9
|
import { MarkdownRenderer } from '../../renderers/MarkdownRenderer.js';
|
|
@@ -16,6 +17,7 @@ import { HistoryStore } from '../../history/HistoryStore.js';
|
|
|
16
17
|
import { isCiEnvironment, shouldArchiveHistory } from '../../history/archivePolicy.js';
|
|
17
18
|
import { EXIT_FINDINGS, EXIT_INCONCLUSIVE, resolveExitCode, violationsFor } from '../../findings/exitCode.js';
|
|
18
19
|
import { buildDigest } from '../../findings/digest.js';
|
|
20
|
+
import { buildSummary } from '../../findings/summary.js';
|
|
19
21
|
import { WaiverLoader, DEFAULT_WAIVER_FILE } from '../../waivers/WaiverLoader.js';
|
|
20
22
|
import { coverageSummary, coverageAdvice } from '../../findings/coverage.js';
|
|
21
23
|
const RENDERERS = {
|
|
@@ -54,8 +56,15 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
54
56
|
options: ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'],
|
|
55
57
|
}),
|
|
56
58
|
digest: Flags.boolean({
|
|
57
|
-
summary: '
|
|
59
|
+
summary: 'With --json, return a compact, token-cheap result: no passing checks, no detail prose, capped affected lists.',
|
|
58
60
|
default: false,
|
|
61
|
+
exclusive: ['summary'],
|
|
62
|
+
}),
|
|
63
|
+
summary: Flags.boolean({
|
|
64
|
+
summary: 'With --json, return page one of the report: grade and reason, coverage, the fix-first plan and attack paths. Smaller than --digest.',
|
|
65
|
+
description: 'Each action lists the ids of the findings it closes; run sf audit explain <id> --file <report.json> for one of them.',
|
|
66
|
+
default: false,
|
|
67
|
+
exclusive: ['digest'],
|
|
59
68
|
}),
|
|
60
69
|
'fail-on-inconclusive': Flags.boolean({
|
|
61
70
|
summary: 'Exit with code 3 if any check could not gather evidence. Off by default.',
|
|
@@ -102,6 +111,9 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
102
111
|
};
|
|
103
112
|
async run() {
|
|
104
113
|
const { flags } = await this.parse(SecurityAuditCommand);
|
|
114
|
+
if ((flags.summary || flags.digest) && !this.jsonEnabled()) {
|
|
115
|
+
this.warn(`--${flags.summary ? 'summary' : 'digest'} shapes the --json output only; add --json to see it.`);
|
|
116
|
+
}
|
|
105
117
|
// Validate the selection and output formats up front, so a typo fails fast with
|
|
106
118
|
// a clear message instead of silently running a partial/empty audit or writing
|
|
107
119
|
// no report after the (potentially long) run completes.
|
|
@@ -162,6 +174,8 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
162
174
|
// Exit code is resolved from the full result: the digest drops passing checks,
|
|
163
175
|
// which the threshold logic must still be able to see and discount.
|
|
164
176
|
this.applyExitCode(result, flags['fail-on'], flags['fail-on-inconclusive']);
|
|
177
|
+
if (flags.summary)
|
|
178
|
+
return buildSummary(result);
|
|
165
179
|
return flags.digest ? buildDigest(result) : result;
|
|
166
180
|
}
|
|
167
181
|
/** Resolve --checks to the checks to run, erroring on any unknown ID. */
|
|
@@ -182,7 +196,13 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
182
196
|
suggestions: ["Run 'sf audit list' to see valid check IDs, or omit --checks to run all."],
|
|
183
197
|
});
|
|
184
198
|
}
|
|
185
|
-
|
|
199
|
+
// Checks that read data another check collects need that check to run first.
|
|
200
|
+
const { checks, added } = withCacheProviders(selected, CHECKS);
|
|
201
|
+
if (added.length > 0) {
|
|
202
|
+
// A warning, not a log line, so --json callers see it too (on stderr): these checks' findings count.
|
|
203
|
+
this.warn(`Also running ${added.map((c) => c.id).join(', ')}: ${added.length === 1 ? 'it collects' : 'they collect'} data the selected checks read, and ${added.length === 1 ? 'its' : 'their'} findings count toward the grade and --fail-on.`);
|
|
204
|
+
}
|
|
205
|
+
return checks;
|
|
186
206
|
}
|
|
187
207
|
/** Resolve --format to a validated list, erroring on any unknown format. */
|
|
188
208
|
resolveFormats(raw) {
|
|
@@ -16,7 +16,7 @@ export const CHECK_META = {
|
|
|
16
16
|
'csp-trusted-sites': { effort: 'quick', impact: 'Insecure HTTP CSP entries allow mixed-content loading and man-in-the-middle script injection.' },
|
|
17
17
|
'named-credentials': { effort: 'quick', impact: 'Unmanaged callout endpoints can send org data to unintended or attacker-controlled destinations.' },
|
|
18
18
|
'hardcoded-credentials': { effort: 'moderate', impact: 'Secrets embedded in Apex can be read by anyone with code access and reused to reach connected systems.' },
|
|
19
|
-
'custom-settings': { effort: 'quick', impact: '
|
|
19
|
+
'custom-settings': { effort: 'quick', impact: 'A secret kept in a custom setting or custom metadata field is readable by users who can query the type.' },
|
|
20
20
|
'health-check': { effort: 'moderate', impact: 'Unaddressed Health Check high-risk settings are documented, exploitable misconfigurations.' },
|
|
21
21
|
'audit-trail': { effort: 'quick', impact: 'Without reviewing the audit trail, malicious permission changes and Login-As abuse go undetected.' },
|
|
22
22
|
'code-security': { effort: 'project', impact: 'Low Apex test coverage and injection-prone code hide exploitable vulnerabilities behind untested paths.' },
|
|
@@ -72,7 +72,7 @@ export const CHECK_META = {
|
|
|
72
72
|
'guest-object-exposure': { effort: 'moderate', impact: 'Grades guest-readable objects by ACTUAL UI-API reachability: objects the UI API models whose records the guest owns are bulk-readable unauthenticated via GraphQL (CRITICAL, enabling mass PII exfiltration without login); records shared with guests whatever the OWD (guest sharing rules, legacy manual, Apex or group shares, or a read UserRecordAccess confirms) are HIGH, for the org to confirm they are meant to be public; a public external OWD without a confirmed guest read is MEDIUM, since secure guest record access means the OWD alone gives guests nothing; objects readable only in the sharing model but not UI-API-modelled (Calendar, AuthSession, etc.) are MEDIUM defense-in-depth.' },
|
|
73
73
|
'guest-site-options': { effort: 'quick', impact: 'Guest file access and member visibility let unauthenticated visitors download public files and enumerate site members.' },
|
|
74
74
|
'threat-detection': { effort: 'moderate', impact: 'Without Guest User Anomaly storage, malicious guest bulk-reads are never flagged and cannot be reconstructed after the fact.' },
|
|
75
|
-
'guest-record-access-policy': { effort: 'quick', impact: '
|
|
75
|
+
'guest-record-access-policy': { effort: 'quick', impact: 'The platform enforces this; records a guest owns or that older shares grant stay readable without a login.' },
|
|
76
76
|
'guest-traffic-anomaly': { effort: 'moderate', impact: 'Guest requests from anonymizer/hosting IPs, single-IP bursts, and GraphQL totalCount sweeps are the live signatures of scraping and pre-exfiltration recon — unmonitored, they only surface after data is gone.' },
|
|
77
77
|
'login-access-policy': { effort: 'moderate', impact: 'Delegated admins and "log in as any user" let accounts impersonate others and self-escalate, bypassing normal credentials and admin-focused monitoring.' },
|
|
78
78
|
'data-export-access': { effort: 'quick', impact: 'Weekly Data Export or API access with View/Modify All is a one-step, org-wide exfiltration capability in the wrong hands.' },
|
|
@@ -99,7 +99,7 @@ export const CHECK_META = {
|
|
|
99
99
|
'data-cloud-data-space-isolation': { effort: 'moderate', impact: 'Default Data Space over-sharing flattens Salesforce OWD record security, exposing sensitive customer data across integrations and partner users.' },
|
|
100
100
|
'platform-event-subscriber-context': { effort: 'moderate', impact: 'Platform events published by low-trust or guest users trigger subscriber Apex running as Automated Process or Admin, creating a direct privilege escalation bridge.' },
|
|
101
101
|
'flow-http-callout-credential-bypass': { effort: 'quick', impact: 'Declarative Flow HTTP callouts storing API keys or bearer tokens in formulas bypass Named Credentials and leak secrets in outbound integrations.' },
|
|
102
|
-
'oauth-device-and-asset-token-flows': { effort: 'quick', impact: '
|
|
102
|
+
'oauth-device-and-asset-token-flows': { effort: 'quick', impact: 'An unblocked Username-Password Flow lets anyone holding a password obtain a token without SSO or MFA.' },
|
|
103
103
|
'delegated-authentication-exposure': { effort: 'moderate', impact: 'Delegated Authentication over insecure endpoints or assigned to admins allows attackers who compromise the gateway to authenticate as any admin user.' },
|
|
104
104
|
'delegated-administration-groups': { effort: 'moderate', impact: 'Delegated Admin groups grant shadow-admin capabilities (user management, login-as, permission set assignment) completely invisible to standard permission set queries.' },
|
|
105
105
|
'auth-provider-registration-handler': { effort: 'moderate', impact: 'Auth Provider registration handlers running as Admin that match users solely on unverified email addresses allow pre-authentication account takeover.' },
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditResult } from './AuditResult.js';
|
|
2
|
+
import type { Finding } from './Finding.js';
|
|
3
|
+
/** What a finding counts as on the report's page one; the HTML report, --summary and explain share it. */
|
|
4
|
+
export type FindingStatus = 'open' | 'info' | 'waived' | 'inconclusive' | 'passed';
|
|
5
|
+
export declare function findingStatus(f: Finding): FindingStatus;
|
|
6
|
+
/** Open findings per severity: what the score and the executive report count (RULE-079). */
|
|
7
|
+
export declare function openCounts(result: AuditResult): Record<'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW', number>;
|
|
8
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function findingStatus(f) {
|
|
2
|
+
if (f.passed)
|
|
3
|
+
return 'passed';
|
|
4
|
+
if (f.inconclusive || f.notAssessed)
|
|
5
|
+
return 'inconclusive';
|
|
6
|
+
if (f.waived)
|
|
7
|
+
return 'waived';
|
|
8
|
+
return f.riskLevel === 'INFO' ? 'info' : 'open';
|
|
9
|
+
}
|
|
10
|
+
/** Open findings per severity: what the score and the executive report count (RULE-079). */
|
|
11
|
+
export function openCounts(result) {
|
|
12
|
+
const open = result.findings.filter((f) => findingStatus(f) === 'open');
|
|
13
|
+
return {
|
|
14
|
+
CRITICAL: open.filter((f) => f.riskLevel === 'CRITICAL').length,
|
|
15
|
+
HIGH: open.filter((f) => f.riskLevel === 'HIGH').length,
|
|
16
|
+
MEDIUM: open.filter((f) => f.riskLevel === 'MEDIUM').length,
|
|
17
|
+
LOW: open.filter((f) => f.riskLevel === 'LOW').length,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=status.js.map
|