@cclabsnz/sf-audit 0.2.3 → 1.0.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 CHANGED
@@ -34,6 +34,8 @@ This runs all 22 security checks against the target org and writes a report to t
34
34
  | `--format` / `-f` | `html` | Output format(s), comma-separated: `html`, `md`, `json` |
35
35
  | `--output` / `-o` | `.` | Directory to write the report file |
36
36
  | `--fail-on` | — | Exit with code 1 if any finding is at or above this severity: `CRITICAL`, `HIGH`, `MEDIUM`, `LOW` |
37
+ | `--checks` | *(all)* | Comma-separated check IDs to run instead of all 22 (e.g. `hardcoded-credentials,apex-sharing`) |
38
+ | `--scoring-config` | — | Path to a custom scoring config JSON file to override weights and grade thresholds |
37
39
 
38
40
  ### Examples
39
41
 
@@ -49,6 +51,12 @@ sf audit security --target-org myOrg --output ./reports
49
51
 
50
52
  # Fail CI pipeline on HIGH or CRITICAL findings
51
53
  sf audit security --target-org myOrg --fail-on HIGH
54
+
55
+ # Run only specific checks
56
+ sf audit security --target-org myOrg --checks hardcoded-credentials,apex-sharing,guest-user-access
57
+
58
+ # Use a custom scoring config (e.g. stricter weights for your org)
59
+ sf audit security --target-org myOrg --scoring-config ./my-scoring.json
52
60
  ```
53
61
 
54
62
  The report file is written as `sf-audit-<orgId>-<timestamp>.<ext>` in the output directory (e.g. `sf-audit-00D000000000001-1711234567890.html`).
@@ -107,8 +115,8 @@ The audit runs 22 checks across 6 categories:
107
115
 
108
116
  Each finding is assigned a risk level with a corresponding weight:
109
117
 
110
- | Risk Level | Weight |
111
- |------------|--------|
118
+ | Risk Level | Default Weight |
119
+ |------------|---------------|
112
120
  | CRITICAL | 10 |
113
121
  | HIGH | 7 |
114
122
  | MEDIUM | 4 |
@@ -117,8 +125,6 @@ Each finding is assigned a risk level with a corresponding weight:
117
125
 
118
126
  The health score is calculated as `100 - (total weight / max possible weight) * 100`, capped at 0.
119
127
 
120
- Weights are configurable in [`config/scoring.json`](config/scoring.json) — no recompile needed.
121
-
122
128
  The audit produces a **Health Score** (0–100) and a **Grade** (A–F):
123
129
 
124
130
  | Grade | Criteria |
@@ -129,6 +135,53 @@ The audit produces a **Health Score** (0–100) and a **Grade** (A–F):
129
135
  | D | Score ≥ 40, no CRITICAL findings |
130
136
  | F | Score < 40 or any CRITICAL finding |
131
137
 
138
+ ### Custom Scoring Config
139
+
140
+ All weights and grade thresholds are configurable — no recompile needed. This is useful when your org has a different risk appetite (e.g. you want to penalise hardcoded credentials more heavily, or set stricter grade thresholds).
141
+
142
+ **Step 1** — Copy the sample config as your starting point:
143
+
144
+ ```bash
145
+ cp config/scoring.sample.json my-scoring.json
146
+ ```
147
+
148
+ **Step 2** — Edit the values. All three sections (`riskScores`, `checkWeights`, `gradeThresholds`) are optional — omit any section to keep the defaults.
149
+
150
+ ```json
151
+ {
152
+ "riskScores": {
153
+ "CRITICAL": 10,
154
+ "HIGH": 7,
155
+ "MEDIUM": 4,
156
+ "LOW": 1,
157
+ "INFO": 0
158
+ },
159
+ "checkWeights": {
160
+ "hardcoded-credentials": 10,
161
+ "guest-user-access": 10,
162
+ "users-and-admins": 10,
163
+ "apex-sharing": 7
164
+ },
165
+ "gradeThresholds": {
166
+ "A": { "minScore": 90, "maxHigh": 0 },
167
+ "B": { "minScore": 75, "maxHigh": 1 },
168
+ "C": { "minScore": 60, "maxHigh": 3 },
169
+ "D": { "minScore": 40, "maxCritical": 0 },
170
+ "F": {}
171
+ }
172
+ }
173
+ ```
174
+
175
+ The full list of valid `checkWeights` keys (one per check) is in [`config/scoring.sample.json`](config/scoring.sample.json).
176
+
177
+ **Step 3** — Pass it when running the audit:
178
+
179
+ ```bash
180
+ sf audit security --target-org myOrg --scoring-config ./my-scoring.json
181
+ ```
182
+
183
+ Your config is deep-merged with the defaults, so you only need to include the values you want to change.
184
+
132
185
  ## Requirements
133
186
 
134
187
  - Node.js 18+
@@ -54,6 +54,7 @@ export class ApiLimitsCheck {
54
54
  id: 'api-limits-healthy',
55
55
  category: this.category,
56
56
  riskLevel: 'LOW',
57
+ passed: true,
57
58
  title: 'All monitored API limits are within acceptable thresholds',
58
59
  detail: 'All monitored API and resource limits are below 50% utilization.',
59
60
  remediation: 'Continue monitoring limits as org activity grows.',
@@ -32,6 +32,7 @@ export class ConnectedAppsCheck {
32
32
  id: 'restricted-connected-apps',
33
33
  category: this.category,
34
34
  riskLevel: 'LOW',
35
+ passed: true,
35
36
  title: 'All connected apps restrict user access appropriately',
36
37
  detail: `All ${count} connected app(s) are configured to require admin pre-authorization.`,
37
38
  remediation: 'Continue monitoring as new connected apps are added.',
@@ -48,6 +48,7 @@ export class CustomSettingsCheck {
48
48
  id: 'custom-settings-clean',
49
49
  category: this.category,
50
50
  riskLevel: 'LOW',
51
+ passed: true,
51
52
  title: 'No obviously credential-related custom objects detected',
52
53
  detail: 'No custom objects with credential-related naming patterns were found.',
53
54
  remediation: 'Continue to avoid storing secrets in custom objects or custom settings. Use Named Credentials for external authentication.',
@@ -33,6 +33,7 @@ export class FieldLevelSecurityCheck {
33
33
  id: 'field-level-security-ok',
34
34
  category: this.category,
35
35
  riskLevel: 'LOW',
36
+ passed: true,
36
37
  title: 'Sensitive custom fields appear appropriately restricted',
37
38
  detail: 'No sensitive custom fields with excessive permission set access were found.',
38
39
  remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
@@ -65,6 +66,7 @@ export class FieldLevelSecurityCheck {
65
66
  id: 'field-level-security-ok',
66
67
  category: this.category,
67
68
  riskLevel: 'LOW',
69
+ passed: true,
68
70
  title: 'Sensitive custom fields appear appropriately restricted',
69
71
  detail: 'No sensitive custom fields with excessive permission set access were found.',
70
72
  remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
@@ -89,6 +91,7 @@ export class FieldLevelSecurityCheck {
89
91
  id: 'field-level-security-ok',
90
92
  category: this.category,
91
93
  riskLevel: 'LOW',
94
+ passed: true,
92
95
  title: 'Sensitive custom fields appear appropriately restricted',
93
96
  detail: 'No sensitive custom fields with excessive permission set access were found.',
94
97
  remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
@@ -138,6 +141,7 @@ export class FieldLevelSecurityCheck {
138
141
  id: 'field-level-security-ok',
139
142
  category: this.category,
140
143
  riskLevel: 'LOW',
144
+ passed: true,
141
145
  title: 'Sensitive custom fields appear appropriately restricted',
142
146
  detail: 'No sensitive custom fields with excessive permission set access were found.',
143
147
  remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
@@ -49,6 +49,7 @@ export class FlowsWithoutSharingCheck {
49
49
  id: 'flows-without-sharing-none',
50
50
  category: this.category,
51
51
  riskLevel: 'LOW',
52
+ passed: true,
52
53
  title: 'No active flows running without sharing context identified',
53
54
  detail: `All ${total} active flows either enforce user sharing context or are not autolaunched/screen flow types.`,
54
55
  remediation: 'Continue to review flow settings when new flows are activated.',
@@ -16,6 +16,7 @@ export class GuestUserAccessCheck {
16
16
  id: 'guest-user-none',
17
17
  category: this.category,
18
18
  riskLevel: 'LOW',
19
+ passed: true,
19
20
  title: 'No active guest users found',
20
21
  detail: 'There are no active guest users in this org, so guest user security misconfiguration is not a concern.',
21
22
  remediation: 'If an Experience Cloud site is added in the future, ensure guest user permissions are properly restricted.',
@@ -135,6 +135,7 @@ export class HardcodedCredentialsCheck {
135
135
  id: 'no-hardcoded-credentials',
136
136
  category: this.category,
137
137
  riskLevel: 'LOW',
138
+ passed: true,
138
139
  title: 'No hardcoded credentials or unprotected endpoints detected in Apex classes',
139
140
  detail: `Scanned ${total} custom Apex classes. No obvious hardcoded credential patterns or unprotected callout endpoints were found.`,
140
141
  remediation: 'Continue using Named Credentials for all external callouts and periodically re-scan as new code is added.',
@@ -10,6 +10,7 @@ export class InactiveUsersCheck {
10
10
  SELECT Id, Username, Name, Profile.Name, LastLoginDate, UserType
11
11
  FROM User
12
12
  WHERE IsActive = true
13
+ AND Id NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)
13
14
  AND (LastLoginDate < LAST_N_DAYS:90 OR LastLoginDate = null)
14
15
  AND UserType = 'Standard'
15
16
  ORDER BY LastLoginDate ASC
@@ -83,6 +83,7 @@ export class IpRestrictionsCheck {
83
83
  id: 'ip-restrictions-ok',
84
84
  category: this.category,
85
85
  riskLevel: 'LOW',
86
+ passed: true,
86
87
  title: 'Login IP restrictions appear appropriately configured',
87
88
  detail: 'All checked admin profiles have login IP ranges configured and no connected apps bypass IP enforcement.',
88
89
  remediation: 'Periodically review IP restriction configuration as new admins and connected apps are added.',
@@ -89,6 +89,7 @@ export class PasswordSessionPolicyCheck {
89
89
  id: 'password-session-policy-compliant',
90
90
  category: this.category,
91
91
  riskLevel: 'LOW',
92
+ passed: true,
92
93
  title: 'Password and session policies appear compliant with security recommendations',
93
94
  detail: 'No password, session, or MFA-related deviations were detected in the Security Health Check results.',
94
95
  remediation: 'Continue monitoring password policies and MFA enforcement as Salesforce releases new security recommendations.',
@@ -15,6 +15,7 @@ export class PublicGroupSharingCheck {
15
15
  id: 'public-group-sharing-none',
16
16
  category: this.category,
17
17
  riskLevel: 'LOW',
18
+ passed: true,
18
19
  title: 'No records shared to All Internal Users groups via sharing rules',
19
20
  detail: 'No sharing rules were found targeting the "All Internal Users" group on key objects.',
20
21
  remediation: 'Continue to avoid broad sharing rules. Periodically review sharing configuration as the org grows.',
@@ -57,6 +58,7 @@ export class PublicGroupSharingCheck {
57
58
  id: 'public-group-sharing-none',
58
59
  category: this.category,
59
60
  riskLevel: 'LOW',
61
+ passed: true,
60
62
  title: 'No records shared to All Internal Users groups via sharing rules',
61
63
  detail: 'No sharing rules were found targeting the "All Internal Users" group on key objects.',
62
64
  remediation: 'Continue to avoid broad sharing rules. Periodically review sharing configuration as the org grows.',
@@ -37,6 +37,7 @@ export class RemoteSitesCheck {
37
37
  id: 'remote-sites-inventory',
38
38
  category: this.category,
39
39
  riskLevel: insecureSites.length === 0 ? 'LOW' : 'INFO',
40
+ passed: insecureSites.length === 0 ? true : undefined,
40
41
  title: `${count} active remote site setting(s) registered (${insecureSites.length} insecure, ${secureSites.length} secure)`,
41
42
  detail: 'Remote Site Settings control which external URLs Apex code can call. Entries should be reviewed periodically to remove unused entries.',
42
43
  remediation: 'Audit each remote site setting to confirm it is still actively used. Remove unused entries to reduce the attack surface.',
@@ -52,6 +53,7 @@ export class RemoteSitesCheck {
52
53
  id: 'no-remote-sites',
53
54
  category: this.category,
54
55
  riskLevel: 'LOW',
56
+ passed: true,
55
57
  title: 'No active remote site settings found',
56
58
  detail: 'No active Remote Site Settings are registered in this org.',
57
59
  remediation: 'This is expected if the org does not make outbound callouts. Monitor as integrations are added.',
@@ -50,6 +50,7 @@ export class SharingModelCheck {
50
50
  id: 'sharing-model-secure',
51
51
  category: this.category,
52
52
  riskLevel: 'LOW',
53
+ passed: true,
53
54
  title: 'No objects have Public Read/Write org-wide defaults',
54
55
  detail: 'All checked standard objects have appropriately restrictive org-wide default sharing settings.',
55
56
  remediation: 'Continue monitoring OWD settings as new objects and customizations are introduced.',
@@ -11,11 +11,11 @@ export class UsersAndAdminsCheck {
11
11
  url: `${baseUrl}/${r.Assignee.Id}`,
12
12
  note: `via: ${r.PermissionSet.IsOwnedByProfile ? 'Profile' : r.PermissionSet.Name}`,
13
13
  });
14
- // Total active users
15
- const activeUsersResult = await ctx.soql.query('SELECT COUNT() FROM User WHERE IsActive = true');
14
+ // Total active, non-frozen users
15
+ const activeUsersResult = await ctx.soql.query('SELECT COUNT() FROM User WHERE IsActive = true AND Id NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)');
16
16
  const totalActiveUsers = activeUsersResult.totalSize;
17
17
  // Modify All Data
18
- const modifyAllResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Name, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsModifyAllData = true AND Assignee.IsActive = true');
18
+ const modifyAllResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Name, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsModifyAllData = true AND Assignee.IsActive = true AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)');
19
19
  const modifyAllUsers = modifyAllResult.records;
20
20
  const modifyAllCount = modifyAllUsers.length;
21
21
  const modifyRisk = modifyAllCount > 5 ? 'CRITICAL' : modifyAllCount > 3 ? 'HIGH' : 'LOW';
@@ -29,7 +29,7 @@ export class UsersAndAdminsCheck {
29
29
  affectedItems: modifyAllUsers.map(userItem),
30
30
  });
31
31
  // View All Data
32
- const viewAllResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Name, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsViewAllData = true AND Assignee.IsActive = true');
32
+ const viewAllResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Name, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsViewAllData = true AND Assignee.IsActive = true AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)');
33
33
  const viewAllUsers = viewAllResult.records;
34
34
  const viewAllCount = viewAllUsers.length;
35
35
  const viewRisk = viewAllCount > 10 ? 'HIGH' : viewAllCount > 5 ? 'MEDIUM' : 'LOW';
@@ -43,7 +43,7 @@ export class UsersAndAdminsCheck {
43
43
  affectedItems: viewAllUsers.map(userItem),
44
44
  });
45
45
  // Customize Application
46
- const customizeAppResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsCustomizeApplication = true AND Assignee.IsActive = true');
46
+ const customizeAppResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsCustomizeApplication = true AND Assignee.IsActive = true AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)');
47
47
  const customizeAppUsers = customizeAppResult.records;
48
48
  const customizeAppCount = customizeAppUsers.length;
49
49
  if (customizeAppCount > 5) {
@@ -58,7 +58,7 @@ export class UsersAndAdminsCheck {
58
58
  });
59
59
  }
60
60
  // Author Apex
61
- const authorApexResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsAuthorApex = true AND Assignee.IsActive = true');
61
+ const authorApexResult = await ctx.soql.query('SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.IsOwnedByProfile FROM PermissionSetAssignment WHERE PermissionSet.PermissionsAuthorApex = true AND Assignee.IsActive = true AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)');
62
62
  const authorApexUsers = authorApexResult.records;
63
63
  const authorApexCount = authorApexUsers.length;
64
64
  if (authorApexCount > 3) {
@@ -22,5 +22,7 @@ export interface Finding {
22
22
  detail: string;
23
23
  remediation: string;
24
24
  affectedItems?: AffectedItem[];
25
+ /** True when the finding represents a passing check (everything is correctly configured). */
26
+ passed?: boolean;
25
27
  }
26
28
  //# sourceMappingURL=Finding.d.ts.map
@@ -12,6 +12,8 @@ const RISK_BG = {
12
12
  LOW: 'rgba(37,99,235,0.12)',
13
13
  INFO: 'rgba(100,116,139,0.12)',
14
14
  };
15
+ const PASS_COLOR = '#22c55e';
16
+ const PASS_BG = 'rgba(34,197,94,0.10)';
15
17
  function esc(str) {
16
18
  return str
17
19
  .replace(/&/g, '&amp;')
@@ -37,10 +39,15 @@ export class HtmlRenderer {
37
39
  ].join('\n ');
38
40
  const findingsHtml = result.findings.length === 0
39
41
  ? '<p style="color:#64748b;text-align:center;padding:2rem 0">No findings.</p>'
40
- : result.findings.map((f) => `
41
- <details class="finding-card" data-risk="${esc(f.riskLevel)}" style="--card-accent:${RISK_COLORS[f.riskLevel]};--card-bg:${RISK_BG[f.riskLevel] ?? 'rgba(100,116,139,0.12)'}">
42
+ : result.findings.map((f) => {
43
+ const cardAccent = f.passed ? PASS_COLOR : (RISK_COLORS[f.riskLevel] ?? '#64748b');
44
+ const cardBg = f.passed ? PASS_BG : (RISK_BG[f.riskLevel] ?? 'rgba(100,116,139,0.12)');
45
+ const badgeStyle = f.passed ? PASS_COLOR : (RISK_COLORS[f.riskLevel] ?? '#64748b');
46
+ const badgeLabel = f.passed ? '✓ PASS' : esc(f.riskLevel);
47
+ return `
48
+ <details class="finding-card" data-risk="${esc(f.riskLevel)}" style="--card-accent:${cardAccent};--card-bg:${cardBg}">
42
49
  <summary class="finding-summary">
43
- <span class="risk-badge" style="background:${RISK_COLORS[f.riskLevel]}">${esc(f.riskLevel)}</span>
50
+ <span class="risk-badge" style="background:${badgeStyle}">${badgeLabel}</span>
44
51
  <span class="finding-title">${esc(f.title)}</span>
45
52
  <span class="finding-category">${esc(f.category)}</span>
46
53
  <span class="chevron">›</span>
@@ -52,22 +59,23 @@ export class HtmlRenderer {
52
59
  <p>${esc(f.remediation)}</p>
53
60
  </div>
54
61
  ${f.affectedItems?.length ? (() => {
55
- const hasUrls = f.affectedItems.some((i) => i.url);
56
- const hasNotes = f.affectedItems.some((i) => i.note);
57
- const headers = ['Item', ...(hasUrls ? ['Setup Link'] : []), ...(hasNotes ? ['Notes'] : [])];
58
- const thead = `<tr>${headers.map((h) => `<th>${esc(h)}</th>`).join('')}</tr>`;
59
- const tbody = f.affectedItems.map((item) => {
60
- const cells = [
61
- `<td>${esc(item.label)}</td>`,
62
- ...(hasUrls ? [`<td>${item.url ? `<a href="${esc(item.url)}" target="_blank" rel="noopener">Open ↗</a>` : '—'}</td>`] : []),
63
- ...(hasNotes ? [`<td>${esc(item.note ?? '')}</td>`] : []),
64
- ];
65
- return `<tr>${cells.join('')}</tr>`;
66
- }).join('');
67
- return `<div class="affected-items"><strong>Affected items (${f.affectedItems.length})</strong><table class="affected-table"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`;
68
- })() : ''}
62
+ const hasUrls = f.affectedItems.some((i) => i.url);
63
+ const hasNotes = f.affectedItems.some((i) => i.note);
64
+ const headers = ['Item', ...(hasUrls ? ['Setup Link'] : []), ...(hasNotes ? ['Notes'] : [])];
65
+ const thead = `<tr>${headers.map((h) => `<th>${esc(h)}</th>`).join('')}</tr>`;
66
+ const tbody = f.affectedItems.map((item) => {
67
+ const cells = [
68
+ `<td>${esc(item.label)}</td>`,
69
+ ...(hasUrls ? [`<td>${item.url ? `<a href="${esc(item.url)}" target="_blank" rel="noopener">Open ↗</a>` : '—'}</td>`] : []),
70
+ ...(hasNotes ? [`<td>${esc(item.note ?? '')}</td>`] : []),
71
+ ];
72
+ return `<tr>${cells.join('')}</tr>`;
73
+ }).join('');
74
+ return `<div class="affected-items"><strong>Affected items (${f.affectedItems.length})</strong><table class="affected-table"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`;
75
+ })() : ''}
69
76
  </div>
70
- </details>`).join('\n');
77
+ </details>`;
78
+ }).join('\n');
71
79
  return `<!DOCTYPE html>
72
80
  <html lang="en">
73
81
  <head>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cclabsnz/sf-audit",
3
- "version": "0.2.3",
4
- "description": "CloudCounsel Salesforce Security Audit — native sf plugin",
3
+ "version": "1.0.0",
4
+ "description": "Salesforce Security Audit — native sf plugin",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {