@cclabsnz/sf-audit 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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+
@@ -24,7 +24,7 @@ export class ApexSharingCheck {
24
24
  async run(ctx) {
25
25
  const findings = [];
26
26
  const baseUrl = ctx.orgInfo.instanceUrl;
27
- const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/page`;
27
+ const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/home`;
28
28
  let apexBodies = ctx.cache.apexBodies;
29
29
  if (!apexBodies) {
30
30
  // Fall back to querying if cache not populated
@@ -6,7 +6,7 @@ export class AuditTrailCheck {
6
6
  async run(ctx) {
7
7
  const findings = [];
8
8
  const baseUrl = ctx.orgInfo.instanceUrl;
9
- const auditTrailUrl = `${baseUrl}/lightning/setup/AuditTrail/page`;
9
+ const auditTrailUrl = `${baseUrl}/lightning/setup/AuditTrail/home`;
10
10
  // Query audit trail for the last 7 days
11
11
  const auditRecords = await ctx.soql.queryAll(`SELECT CreatedDate, CreatedBy.Username, Action, Display, Section
12
12
  FROM SetupAuditTrail
@@ -129,7 +129,7 @@ export class GuestUserAccessCheck {
129
129
  title: `${count} object sharing rule(s) expose records to guest users`,
130
130
  affectedItems: sharingExposures.map((e) => ({
131
131
  label: e.shareTable,
132
- url: `${baseUrl}/lightning/setup/SecuritySharingRules/page`,
132
+ url: `${baseUrl}/lightning/setup/SecuritySharing/page`,
133
133
  note: `${e.count} sharing rule(s) — review and remove guest-targeting rules`,
134
134
  })),
135
135
  detail: 'Sharing rules targeting guest users can expose internal records to unauthenticated visitors.',
@@ -30,7 +30,7 @@ export class HardcodedCredentialsCheck {
30
30
  async run(ctx) {
31
31
  const findings = [];
32
32
  const baseUrl = ctx.orgInfo.instanceUrl;
33
- const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/page`;
33
+ const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/home`;
34
34
  const records = await ctx.tooling.query('SELECT Id, Name, Body, LengthWithoutComments, NamespacePrefix FROM ApexClass WHERE NamespacePrefix = null');
35
35
  // Cache apex bodies for downstream checks — exclude test classes and filter null bodies
36
36
  const nonTestRecords = records.filter((r) => !IS_TEST_CLASS.test(r.Body ?? ''));
@@ -7,7 +7,7 @@ export class HealthCheckCheck {
7
7
  async run(ctx) {
8
8
  const findings = [];
9
9
  const baseUrl = ctx.orgInfo.instanceUrl;
10
- const healthCheckUrl = `${baseUrl}/lightning/setup/HealthCheck/page`;
10
+ const healthCheckUrl = `${baseUrl}/lightning/setup/HealthCheck/home`;
11
11
  // Health Cloud detection
12
12
  const pkgRows = await ctx.soql.queryAll("SELECT NamespacePrefix FROM PackageLicense WHERE NamespacePrefix = 'HealthCloudGA'");
13
13
  ctx.cache.healthCloudInstalled = pkgRows.length > 0;
@@ -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
@@ -7,7 +7,7 @@ export class NamedCredentialsCheck {
7
7
  async run(ctx) {
8
8
  const findings = [];
9
9
  const baseUrl = ctx.orgInfo.instanceUrl;
10
- const setupUrl = `${baseUrl}/lightning/setup/NamedCredential/page`;
10
+ const setupUrl = `${baseUrl}/lightning/setup/NamedCredential/home`;
11
11
  // Query named credentials using Tooling API
12
12
  const records = await ctx.tooling.query('SELECT Id, MasterLabel, DeveloperName, Endpoint FROM NamedCredential');
13
13
  const count = records.length;
@@ -8,7 +8,7 @@ export class PublicGroupSharingCheck {
8
8
  async run(ctx) {
9
9
  const findings = [];
10
10
  const baseUrl = ctx.orgInfo.instanceUrl;
11
- const sharingRulesUrl = `${baseUrl}/lightning/setup/SecuritySharingRules/page`;
11
+ const sharingRulesUrl = `${baseUrl}/lightning/setup/SecuritySharing/page`;
12
12
  const groups = await ctx.soql.queryAll("SELECT Id, Name, Type FROM Group WHERE Type = 'AllInternal'");
13
13
  if (groups.length === 0) {
14
14
  findings.push({
@@ -7,7 +7,7 @@ export class RemoteSitesCheck {
7
7
  async run(ctx) {
8
8
  const findings = [];
9
9
  const baseUrl = ctx.orgInfo.instanceUrl;
10
- const setupUrl = `${baseUrl}/lightning/setup/SecurityWhitelistPage/page`;
10
+ const setupUrl = `${baseUrl}/lightning/setup/SecurityRemoteProxy/home`;
11
11
  // Query active remote site settings using Tooling API
12
12
  const records = await ctx.tooling.query('SELECT Id, SiteName, EndpointUrl, IsActive, DisableProtocolSecurity FROM RemoteProxy WHERE IsActive = true');
13
13
  const count = records.length;
@@ -6,8 +6,8 @@ export class ScheduledApexCheck {
6
6
  async run(ctx) {
7
7
  const findings = [];
8
8
  const baseUrl = ctx.orgInfo.instanceUrl;
9
- const apexJobsUrl = `${baseUrl}/lightning/setup/ScheduledJobs/page`;
10
- const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/page`;
9
+ const apexJobsUrl = `${baseUrl}/lightning/setup/ScheduledJobs/home`;
10
+ const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/home`;
11
11
  // Query all active scheduled/batch Apex jobs
12
12
  const jobs = await ctx.soql.queryAll(`
13
13
  SELECT Id, ApexClass.Name, JobType, Status, CreatedById
@@ -7,7 +7,7 @@ export class SharingModelCheck {
7
7
  async run(ctx) {
8
8
  const findings = [];
9
9
  const baseUrl = ctx.orgInfo.instanceUrl;
10
- const owdUrl = `${baseUrl}/lightning/setup/OrgWideDefaultSettings/page`;
10
+ const owdUrl = `${baseUrl}/lightning/setup/SecuritySharing/page`;
11
11
  const publicReadWriteObjects = [];
12
12
  for (const objectName of OBJECTS_TO_CHECK) {
13
13
  try {
@@ -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 Assignee.Id 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 Assignee.Id 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 Assignee.Id 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 Assignee.Id 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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cclabsnz/sf-audit",
3
- "version": "0.2.2",
4
- "description": "CloudCounsel Salesforce Security Audit — native sf plugin",
3
+ "version": "0.2.4",
4
+ "description": "Salesforce Security Audit — native sf plugin",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {