@cclabsnz/sf-audit 1.1.0 → 1.2.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.
Files changed (52) hide show
  1. package/README.md +153 -31
  2. package/lib/checks/CheckEngine.js +1 -1
  3. package/lib/commands/audit/security.d.ts +5 -0
  4. package/lib/commands/audit/security.js +32 -3
  5. package/lib/compliance/catalogs/hiso10029.d.ts +3 -0
  6. package/lib/compliance/catalogs/hiso10029.js +35 -0
  7. package/lib/compliance/catalogs/index.d.ts +4 -0
  8. package/lib/compliance/catalogs/index.js +21 -0
  9. package/lib/compliance/catalogs/iso27001.d.ts +3 -0
  10. package/lib/compliance/catalogs/iso27001.js +39 -0
  11. package/lib/compliance/catalogs/nzism.d.ts +3 -0
  12. package/lib/compliance/catalogs/nzism.js +31 -0
  13. package/lib/compliance/catalogs/owasp.d.ts +3 -0
  14. package/lib/compliance/catalogs/owasp.js +37 -0
  15. package/lib/compliance/catalogs/privacyAct.d.ts +3 -0
  16. package/lib/compliance/catalogs/privacyAct.js +17 -0
  17. package/lib/compliance/catalogs/sbs.d.ts +3 -0
  18. package/lib/compliance/catalogs/sbs.js +61 -0
  19. package/lib/compliance/catalogs/soc2.d.ts +3 -0
  20. package/lib/compliance/catalogs/soc2.js +42 -0
  21. package/lib/compliance/mapping.d.ts +2 -0
  22. package/lib/compliance/mapping.js +111 -0
  23. package/lib/compliance/resolve.d.ts +12 -0
  24. package/lib/compliance/resolve.js +49 -0
  25. package/lib/compliance/types.d.ts +13 -0
  26. package/lib/compliance/types.js +2 -0
  27. package/lib/findings/CheckMeta.d.ts +9 -0
  28. package/lib/findings/CheckMeta.js +67 -0
  29. package/lib/renderers/AuditRenderer.d.ts +2 -0
  30. package/lib/renderers/ClientReportRenderer.d.ts +29 -0
  31. package/lib/renderers/ClientReportRenderer.js +205 -0
  32. package/lib/renderers/HtmlRenderer.js +1 -7
  33. package/lib/renderers/html-utils.d.ts +2 -0
  34. package/lib/renderers/html-utils.js +8 -0
  35. package/lib/report/ComplianceMatrix.d.ts +19 -0
  36. package/lib/report/ComplianceMatrix.js +47 -0
  37. package/lib/report/ExecutivePriorities.d.ts +8 -0
  38. package/lib/report/ExecutivePriorities.js +22 -0
  39. package/lib/report/RemediationRoadmap.d.ts +9 -0
  40. package/lib/report/RemediationRoadmap.js +18 -0
  41. package/lib/report/branding.d.ts +18 -0
  42. package/lib/report/branding.js +19 -0
  43. package/lib/report/fonts.d.ts +2 -0
  44. package/lib/report/fonts.js +22 -0
  45. package/package.json +2 -1
  46. package/src/assets/fonts/dm-sans-italic-latin.woff2 +0 -0
  47. package/src/assets/fonts/dm-sans-normal-latin.woff2 +0 -0
  48. package/src/assets/fonts/dm-serif-display-italic-latin.woff2 +0 -0
  49. package/src/assets/fonts/dm-serif-display-normal-latin.woff2 +0 -0
  50. package/config/queries/soql.json +0 -24
  51. package/config/queries/tooling.json +0 -28
  52. package/config/scoring.json +0 -17
package/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # @cclabsnz/sf-audit
2
2
 
3
- A Salesforce CLI (`sf`) plugin that runs a comprehensive security audit against any Salesforce org and produces an HTML, Markdown, or JSON report.
3
+ A Salesforce CLI (`sf`) plugin that runs a comprehensive, **read-only** security audit against any Salesforce org, risk-scores it with an A–F grade, and turns the result into a report your security team — or your client's — can act on.
4
+
5
+ - **61 read-only checks** across identity, access, data, code, integrations, and monitoring
6
+ - **Attack-chain correlation** — links individual findings into named, multi-step attack scenarios
7
+ - **Compliance mapping** — every finding mapped to **source-verified** controls across 7 frameworks (OWASP, SOC 2, ISO/IEC 27001:2022, Security Benchmark for Salesforce, NZ Privacy Act, HISO 10029, NZISM)
8
+ - **Outputs:** a technical `html` / `md` / `json` report, or a branded, client-ready **executive report** (print-to-PDF) with priorities, remediation roadmap, and a compliance coverage matrix
9
+ - **History & diff** — archives each run and shows security-posture drift over time
10
+ - Strictly read-only (SOQL/Tooling/REST GETs); see [PERMISSIONS.md](PERMISSIONS.md) for the least-privilege access it needs
4
11
 
5
12
  ## Installation
6
13
 
@@ -24,18 +31,22 @@ sf plugins link .
24
31
  sf audit security --target-org <orgAlias>
25
32
  ```
26
33
 
27
- This runs all 22 security checks against the target org and writes a report to the current directory.
34
+ This runs all 61 security checks against the target org and writes a report to the current directory.
28
35
 
29
36
  ### Options
30
37
 
31
38
  | Flag | Default | Description |
32
39
  |------|---------|-------------|
33
40
  | `--target-org` | *(required)* | Org alias or username to audit |
34
- | `--format` / `-f` | `html` | Output format(s), comma-separated: `html`, `md`, `json` |
41
+ | `--format` / `-f` | `html` | Output format(s), comma-separated: `html`, `md`, `json`, `executive` |
35
42
  | `--output` / `-o` | `.` | Directory to write the report file |
36
43
  | `--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`) |
44
+ | `--checks` | *(all)* | Comma-separated check IDs to run instead of all 61 (e.g. `hardcoded-credentials,apex-sharing`) |
38
45
  | `--scoring-config` | — | Path to a custom scoring config JSON file to override weights and grade thresholds |
46
+ | `--prepared-for` | — | Client name for the executive report cover line |
47
+ | `--branding` | — | Path to a `report-branding.json` to override CloudCounsel defaults (executive format) |
48
+ | `--top` | `5` | Number of executive priorities to highlight (executive format) |
49
+ | `--frameworks` | `universal` | Compliance matrix scope (executive format): `universal` (OWASP/SOC 2/ISO 27001), `nz` (ISO/HISO/Privacy Act/NZISM), `all`, or a comma list (e.g. `owasp,iso,nzism`) |
39
50
 
40
51
  ### Examples
41
52
 
@@ -59,57 +70,168 @@ sf audit security --target-org myOrg --checks hardcoded-credentials,apex-sharing
59
70
  sf audit security --target-org myOrg --scoring-config ./my-scoring.json
60
71
  ```
61
72
 
73
+ ### Executive report
74
+
75
+ `--format executive` produces a CloudCounsel-branded, print-to-PDF HTML report for clients —
76
+ grade and executive summary, top priorities with abuse/impact narratives, attack scenarios, a
77
+ risk×effort remediation roadmap, and a **compliance coverage matrix** mapping findings to framework
78
+ controls. It is fully self-contained (fonts embedded); open it and **Save as PDF**.
79
+
80
+ ```bash
81
+ # Branded executive report for a client (universal compliance matrix)
82
+ sf audit security --target-org myOrg --format executive --prepared-for "Acme Health" --top 5
83
+
84
+ # NZ health/government engagement — NZ framework matrix
85
+ sf audit security --target-org myOrg --format executive --frameworks nz
86
+
87
+ # White-label / co-brand via overrides
88
+ sf audit security --target-org myOrg --format executive --branding ./report-branding.json
89
+ ```
90
+
91
+ Compliance controls are mapped from authoritative, version-pinned sources (OWASP Top 10:2021,
92
+ AICPA TSC, ISO/IEC 27001:2022, the Security Benchmark for Salesforce, NZ Privacy Act, HISO 10029,
93
+ NZISM). Only source-verified controls render; "No findings detected" is **not** an attestation of
94
+ compliance (see the report's Scope & Liability section).
95
+
62
96
  The report file is written as `sf-audit-<orgId>-<timestamp>.<ext>` in the output directory (e.g. `sf-audit-00D000000000001-1711234567890.html`).
63
97
 
64
98
  ## What It Checks
65
99
 
66
- The audit runs 22 checks across 6 categories:
100
+ The audit runs **61 read-only checks**. Every finding is risk-rated (CRITICAL → INFO) and mapped to controls across the compliance frameworks (see [Compliance frameworks](#compliance-frameworks)). The checks are grouped into nine domains below.
67
101
 
68
- ### Org Health
102
+ ### Org Health & Configuration
69
103
  | Check | What it looks for |
70
104
  |-------|------------------|
71
- | Health Check | Salesforce Health Check score and individual risk items |
72
- | Password & Session Policy | Weak password requirements, session timeout, MFA gaps |
105
+ | Security Health Check | Salesforce Health Check score and individual high-risk settings |
106
+ | Enhanced Domains | Enhanced Domains enabled — prevents cross-org cookie leakage and enforces URL isolation |
107
+ | Pending Release Updates | Salesforce release updates pending activation, especially those past auto-activation |
108
+ | Legacy API Versions | Apex compiled on old API versions and SOAP-based remote site integrations |
109
+ | API & Resource Limits | API request consumption against daily and concurrent limits |
73
110
 
74
- ### Identity & Access
111
+ ### Identity & Authentication
112
+ | Check | What it looks for |
113
+ |-------|------------------|
114
+ | SSO Enforcement | Username-password logins indicating SSO is not org-wide enforced |
115
+ | My Domain Login Policy | My Domain configured and login from login.salesforce.com blocked (stops SSO bypass) |
116
+ | Internal User MFA | MFA enforcement for active internal standard users |
117
+ | MFA for External Users | MFA enforced for external/portal users with data access |
118
+ | MFA Method Registration | Active standard users with no registered MFA method |
119
+ | MFA Method Strength | Registered MFA methods classified by strength (phishing-resistant / TOTP / weak) |
120
+ | High Assurance Sessions | Admin-capable connected apps requiring short timeouts or high-assurance MFA sessions |
121
+ | Trusted IP Ranges | Trusted IP ranges that bypass MFA, including overly broad ranges |
122
+ | Login IP Restrictions | Admin profiles missing IP ranges; connected apps with relaxed IP policy |
123
+ | Password & Session Policy | Password complexity, session timeout, and MFA gaps (from Health Check) |
124
+ | Certificate Expiry | Installed certificates nearing expiry (30 / 90 / 180-day thresholds) |
125
+
126
+ ### Users, Permissions & Privilege
75
127
  | Check | What it looks for |
76
128
  |-------|------------------|
77
- | Users & Admins | Users with system-wide permissions (ModifyAllData, ViewAllData, AuthorApex) |
78
- | Permissions | Unassigned permission sets, excessive profile count |
79
- | IP Restrictions | Admins without IP range restrictions, connected apps with relaxed IP policies |
80
- | Login Sessions | Failed login trends, logins from diverse IPs, recent login activity |
129
+ | Users & Admins | Users with system-wide permissions (ModifyAllData, ViewAllData, AuthorApex, CustomizeApplication) |
130
+ | Permissions | Unassigned permission sets and high profile counts that widen the attack surface |
131
+ | Standard Profile Usage | Active users assigned to out-of-the-box standard profiles |
132
+ | Use Any API Client | Users with the permission that bypasses API Access Control |
133
+ | Privilege Escalation Permissions | Users holding lateral-movement / persistence permission clusters |
134
+ | Integration / Service Accounts | Non-human identity inventory and excess privilege |
81
135
  | Inactive Users | Active licensed users with no login in 90+ days |
82
136
 
83
- ### Data Security
137
+ ### Data Access & Sharing
84
138
  | Check | What it looks for |
85
139
  |-------|------------------|
86
- | Sharing Model | Object-level OWD settings for Account, Contact, Opportunity, Case, Lead |
87
- | Field Level Security | Sensitive fields (SSN, credit card, tax ID) exposed to broad permission sets |
88
- | Guest User Access | Object permissions and sharing rules granted to unauthenticated guest users |
140
+ | OWD Sharing Model | Org-wide defaults for Account, Contact, Opportunity, Case, Lead (internal + external) |
141
+ | Field-Level Security | Sensitive fields (SSN, credit card, tax ID) exposed to broad permission sets |
89
142
  | Public Group Sharing | Sharing rules that grant access to All Internal Users |
143
+ | Report Folder Public Access | Report folders any authenticated user can view |
144
+ | Field History Tracking | History tracking enabled on sensitive standard objects |
145
+ | Data Classification & Encryption | Field data classification usage and Shield Platform Encryption |
146
+ | Flows Without Sharing | Active flows running in system context without sharing enforcement |
147
+ | Content Distribution Links | Public file links missing expiry or passwords, and stale records |
90
148
 
91
- ### Integration Security
149
+ ### Guest & External-Facing Access
92
150
  | Check | What it looks for |
93
151
  |-------|------------------|
94
- | Connected Apps | Apps not restricted to admin-approved users |
95
- | Remote Sites | Raw remote site registrations without Named Credential coverage |
96
- | Named Credentials | Named credential inventory |
97
- | Hardcoded Credentials | Bearer tokens, Basic auth, API keys, and raw callout URLs in Apex code |
152
+ | Guest User Access | Object permissions and sharing rules granted to unauthenticated guests |
153
+ | Guest-Executable Apex | Apex that guest profiles can run, flagging `without sharing` classes |
154
+ | Experience Cloud Sites | Live sites with self-registration enabled and guest user presence |
155
+ | CORS Allowlist | Wildcard or overly broad CORS allowlist origins |
156
+ | CSP Trusted Sites | Content Security Policy trusted sites with insecure HTTP (mixed-content) endpoints |
98
157
 
99
- ### Code & Automation
158
+ ### Apex & Code Security
100
159
  | Check | What it looks for |
101
160
  |-------|------------------|
102
- | Apex Sharing | Apex classes using `without sharing` or missing sharing declaration |
103
- | Flows Without Sharing | Active flows running in system context without sharing enforcement |
104
- | Scheduled Apex | Active scheduled and batch Apex jobs |
105
- | Code Security | Org-wide Apex test coverage percentage |
161
+ | Apex Sharing Declarations | Classes classified by sharing declaration (with / without / inherited / omitted) |
162
+ | Apex CRUD/FLS Enforcement | DML or SOQL performed without CRUD/FLS permission checks |
163
+ | Apex REST Endpoints | `@RestResource` classes running `without sharing` |
164
+ | Visualforce XSS | `escape="false"` and unencoded merge fields in Visualforce markup |
165
+ | Hardcoded Credentials | Bearer tokens, Basic auth, API keys, and raw callout URLs in Apex |
166
+ | Code Security & Coverage | Org-wide Apex test coverage, class/trigger counts, and SOQL injection patterns |
167
+ | Scheduled & Batch Apex | Active scheduled and batch Apex jobs |
168
+ | Anonymous Apex Audit | Anonymous Apex executed in the last 90 days (via SetupAuditTrail) |
169
+ | Apex Logging Framework | Persistent logging usage and sensitive data exposed in Apex logs |
170
+
171
+ ### Integrations, Connected Apps & Deployments
172
+ | Check | What it looks for |
173
+ |-------|------------------|
174
+ | Connected Apps | Apps not restricted to admin-approved users |
175
+ | Connected App OAuth Scopes | Full OAuth-scope grants and infinite refresh-token policies |
176
+ | Inactive Connected Apps | Apps with no OAuth logins in the past 90 days |
177
+ | Named Credentials | Named credential inventory; credentials not referenced in Apex |
178
+ | Remote Site Settings | Remote sites with protocol security disabled |
179
+ | Installed Packages | Managed/unmanaged package inventory; unmanaged or beta packages in production |
180
+ | Deployment Identity | Designated deployment identity and uncontrolled deployment activity |
181
+
182
+ ### Secrets & Credential Storage
183
+ | Check | What it looks for |
184
+ |-------|------------------|
185
+ | Custom Settings & Credentials | Custom settings with credential-like names that may store secrets |
186
+ | Custom Labels Credential Exposure | API keys and tokens in globally-readable Custom Labels |
106
187
 
107
- ### Platform
188
+ ### Monitoring & Threat Detection
108
189
  | Check | What it looks for |
109
190
  |-------|------------------|
110
- | API Limits | API request consumption vs. daily/concurrent limits |
111
191
  | Audit Trail | Permission changes and Login-As events in the setup audit trail |
112
- | Custom Settings | Custom settings with credential-like names that may store secrets |
192
+ | Login Session | Failed login trends, Login-As events, and access from diverse IPs |
193
+ | Failed Login Detection | Brute-force and credential-stuffing patterns (last 7 days) |
194
+ | Transaction Security Policies | Automated threat detection and response policies configured |
195
+ | Active Debug Log Traces | Active TraceFlag records capturing logs, including high-detail traces |
196
+ | Event Monitoring | Event Monitoring enabled with logs covering 30+ days |
197
+ | SIEM Integration Signals | Evidence of SIEM or external monitoring integration |
198
+
199
+ ## Compliance frameworks
200
+
201
+ Findings are mapped to controls across seven security and privacy frameworks. The mapping is built on a **sourced control catalog** — each control carries its framework, **pinned version**, official title, and a citation — so a finding's compliance reference ties to an exact, defensible requirement rather than a bare tag.
202
+
203
+ | Framework | Version | Notes |
204
+ |-----------|---------|-------|
205
+ | OWASP Top 10 | 2021 | Web application risk categories |
206
+ | SOC 2 | AICPA TSC 2017 | Common Criteria (CC6–CC9) |
207
+ | ISO/IEC 27001 | 2022 | Annex A controls |
208
+ | Security Benchmark for Salesforce (SBS) | current | Salesforce-native benchmark — [docs.securitybenchmark.org](https://docs.securitybenchmark.org) |
209
+ | NZ Privacy Act | 2020 | Information Privacy Principles (IPP 5/9/12) |
210
+ | HISO 10029 | 2022 | NZ Health Information Security Framework |
211
+ | NZISM | v3.8 | NZ Information Security Manual |
212
+
213
+ **Provenance gate.** Each catalogued control is marked `verified` only after its title/reference is confirmed against the authoritative source. **Controls that are not verified do not render** in the compliance matrix — nothing ships as "compliant-to-clause" on unconfirmed data. The current verification status is tracked in [`docs/compliance/verification-worksheet.md`](docs/compliance/verification-worksheet.md).
214
+
215
+ **Framework packs.** The executive report's compliance matrix is scoped with `--frameworks`:
216
+
217
+ - `universal` *(default)* — OWASP, SOC 2, ISO 27001
218
+ - `nz` — ISO 27001, HISO 10029, NZ Privacy Act, NZISM (for NZ health/government engagements)
219
+ - `all` — every framework
220
+ - a comma list of aliases, e.g. `owasp,iso,nzism`
221
+
222
+ > **Not an attestation.** A control rendering "No findings detected" means this audit's checks surfaced no issues mapped to it — it is **not** a statement of compliance or certification. See [Scope & Liability](#scope--liability).
223
+
224
+ ## Scope & Liability
225
+
226
+ **What this tool is.** A read-only, point-in-time configuration review. Every check uses standard Salesforce SOQL, Tooling, and REST **GET** queries only — the tool performs no DML, no metadata deployments, and never modifies the target org or its data. It runs under the permissions of the authenticated `sf` user; checks that the user cannot access are reported as *inconclusive* rather than passing silently.
227
+
228
+ **What this tool is not.** It is **not** a penetration test, a dynamic/runtime security test, or a source-code audit of managed-package internals. It does not exploit vulnerabilities, attempt privilege escalation, or guarantee detection of every misconfiguration. The Health Score and A–F grade are **prioritisation aids**, not certifications, and do not represent compliance with, or accreditation under, any standard (OWASP, SOC 2, ISO 27001, HIPAA, GDPR, or otherwise). Compliance-framework tags indicate *relevance* to a control area only.
229
+
230
+ **Point-in-time.** Results reflect org configuration **at the moment the audit ran**. Configuration drift, new customisations, and platform changes can invalidate findings at any time. Re-run regularly (see [History & Diff](#history--diff)).
231
+
232
+ **Authorisation.** Run this tool only against orgs you own or are **explicitly authorised in writing** to assess. You are responsible for obtaining the necessary permissions and for handling generated reports — which may contain sensitive security configuration — in accordance with your organisation's data-handling and confidentiality obligations.
233
+
234
+ **No warranty.** This software is provided "as is", without warranty of any kind, express or implied. To the maximum extent permitted by law, the authors and CloudCounsel Limited accept no liability for any loss, damage, or claim arising from use of this tool or reliance on its output. Findings are informational and should be validated by a qualified Salesforce security practitioner before any remediation action is taken.
113
235
 
114
236
  ## Scoring
115
237
 
@@ -261,7 +383,7 @@ Diff report written: ./sf-audit-diff-00D000000000001-...-vs-....json
261
383
 
262
384
  - Node.js 18+
263
385
  - Salesforce CLI (`sf`) v2+
264
- - The authenticated org user needs at least: Read access to setup objects (User, PermissionSet, ApexClass, Flow, etc.) and access to the Tooling API.
386
+ - A least-privilege, **read-only** org user. The audit performs no writes and does **not** require `View All Data`. See **[PERMISSIONS.md](PERMISSIONS.md)** for the exact minimum permission set, what each is for, what the tool does *not* need, and a ready-to-deploy `SF Audit (Read-Only)` permission set ([`docs/permissionset/`](docs/permissionset/SF_Audit_ReadOnly.permissionset-meta.xml)).
265
387
 
266
388
  ## Development
267
389
 
@@ -1,5 +1,5 @@
1
1
  import { buildAuditResult } from '../findings/scoring.js';
2
- import { getComplianceTags } from '../findings/ComplianceMapping.js';
2
+ import { getComplianceTags } from '../compliance/resolve.js';
3
3
  import { ChainEngine } from '../chains/ChainEngine.js';
4
4
  const PERMISSION_ERROR_CODES = new Set([
5
5
  'INSUFFICIENT_ACCESS_RIGHTS',
@@ -11,8 +11,13 @@ export default class SecurityAuditCommand extends SfCommand<AuditResult> {
11
11
  'fail-on': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
12
  checks: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
13
  'scoring-config': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'prepared-for': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ branding: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ top: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
17
+ frameworks: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
14
18
  };
15
19
  run(): Promise<AuditResult>;
20
+ private rendererFor;
16
21
  private printSummary;
17
22
  private handleFailOn;
18
23
  }
@@ -6,6 +6,9 @@ import { CHECKS } from '../../checks/registry.js';
6
6
  import { JsonRenderer } from '../../renderers/JsonRenderer.js';
7
7
  import { HtmlRenderer } from '../../renderers/HtmlRenderer.js';
8
8
  import { MarkdownRenderer } from '../../renderers/MarkdownRenderer.js';
9
+ import { ClientReportRenderer } from '../../renderers/ClientReportRenderer.js';
10
+ import { resolveBranding } from '../../report/branding.js';
11
+ import { resolveFrameworks } from '../../compliance/resolve.js';
9
12
  import { buildAuditContext, resolveOrgInfo } from '../../lib/wire.js';
10
13
  import { loadScoringConfig } from '../../findings/loadScoringConfig.js';
11
14
  import { HistoryStore } from '../../history/HistoryStore.js';
@@ -46,6 +49,21 @@ export default class SecurityAuditCommand extends SfCommand {
46
49
  summary: 'Path to a custom scoring config JSON file. Merges with defaults.',
47
50
  helpValue: './hnz-scoring.json',
48
51
  }),
52
+ 'prepared-for': Flags.string({
53
+ summary: 'Client name for the executive report cover line.',
54
+ }),
55
+ branding: Flags.string({
56
+ summary: 'Path to a report-branding.json to override CloudCounsel defaults (executive format).',
57
+ helpValue: './report-branding.json',
58
+ }),
59
+ top: Flags.integer({
60
+ summary: 'Number of executive priorities to highlight (executive format).',
61
+ default: 5,
62
+ }),
63
+ frameworks: Flags.string({
64
+ summary: 'Compliance frameworks for the executive matrix: universal | nz | all | a comma list (executive format).',
65
+ default: 'universal',
66
+ }),
49
67
  };
50
68
  async run() {
51
69
  const { flags } = await this.parse(SecurityAuditCommand);
@@ -74,13 +92,14 @@ export default class SecurityAuditCommand extends SfCommand {
74
92
  const formats = flags.format.split(',').map((f) => f.trim());
75
93
  fs.mkdirSync(flags.output, { recursive: true });
76
94
  for (const format of formats) {
77
- const renderer = RENDERERS[format];
95
+ const renderer = this.rendererFor(format, flags);
78
96
  if (!renderer) {
79
- this.warn(`Unknown format '${format}' — skipping. Valid formats: html, md, json`);
97
+ this.warn(`Unknown format '${format}' — skipping. Valid formats: html, md, json, executive`);
80
98
  continue;
81
99
  }
82
100
  const output = renderer.render(result);
83
- const filename = `sf-audit-${orgInfo.id}-${Date.now()}${renderer.fileExtension}`;
101
+ const prefix = renderer.filenamePrefix ?? 'sf-audit';
102
+ const filename = `${prefix}-${orgInfo.id}-${Date.now()}${renderer.fileExtension}`;
84
103
  const outputPath = path.join(flags.output, filename);
85
104
  fs.writeFileSync(outputPath, output, 'utf-8');
86
105
  this.log(`\nReport written: ${outputPath}`);
@@ -95,6 +114,16 @@ export default class SecurityAuditCommand extends SfCommand {
95
114
  }
96
115
  return result;
97
116
  }
117
+ rendererFor(format, flags) {
118
+ if (format === 'executive') {
119
+ let overrides;
120
+ if (flags.branding)
121
+ overrides = JSON.parse(fs.readFileSync(flags.branding, 'utf-8'));
122
+ const branding = resolveBranding(overrides, flags['prepared-for']);
123
+ return new ClientReportRenderer({ branding, topN: flags.top, frameworks: resolveFrameworks(flags.frameworks) });
124
+ }
125
+ return RENDERERS[format];
126
+ }
98
127
  printSummary(result) {
99
128
  const levels = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
100
129
  const counts = Object.fromEntries(levels.map((l) => [l, result.findings.filter((f) => f.riskLevel === l).length]));
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const HISO10029_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=hiso10029.d.ts.map
@@ -0,0 +1,35 @@
1
+ // HISO 10029:2022 — Health Information Security Framework (HISF), Health NZ / Te Whatu Ora.
2
+ // Basis VERIFIED 2026-06: HISF is explicitly built on AS/NZS ISO/IEC 27002 (confirmed via the
3
+ // framework and Te Whatu Ora cyber standards). These are DOMAIN-LEVEL controls mapped to the
4
+ // ISO 27002 control areas HISF adopts. `verified` = the framework basis and domain coverage are
5
+ // confirmed; exact HISF 2022 clause references are a later granularity pass needing the MoH document.
6
+ const V = 'HISO 10029:2022 (HISF)';
7
+ const URL = 'https://www.tewhatuora.govt.nz/health-services-and-programmes/cyber-hub/cyber-standards';
8
+ const ref = (domain) => `HISO 10029:2022 (HISF, AS/NZS ISO/IEC 27002-aligned), ${domain}`;
9
+ export const HISO10029_CONTROLS = [
10
+ { id: 'HISO-AC', framework: 'HISO10029', version: V, title: 'Access control',
11
+ requirement: 'Access to health information and supporting systems is restricted to authorised users on a need-to-know, least-privilege basis.',
12
+ sourceRef: ref('Access Control'), url: URL, verified: true },
13
+ { id: 'HISO-AUTH', framework: 'HISO10029', version: V, title: 'Identity and authentication',
14
+ requirement: 'Users are uniquely identified and strongly authenticated (including multi-factor) before accessing health information.',
15
+ sourceRef: ref('Authentication'), url: URL, verified: true },
16
+ { id: 'HISO-CRYPTO', framework: 'HISO10029', version: V, title: 'Cryptography and key management',
17
+ requirement: 'Health information is protected using appropriate cryptographic controls in transit and at rest, with managed keys and credentials.',
18
+ sourceRef: ref('Cryptography'), url: URL, verified: true },
19
+ { id: 'HISO-LOG', framework: 'HISO10029', version: V, title: 'Logging, monitoring and audit',
20
+ requirement: 'Security-relevant events affecting health information are logged, retained, and monitored to support detection and investigation.',
21
+ sourceRef: ref('Logging and Monitoring'), url: URL, verified: true },
22
+ { id: 'HISO-DATA', framework: 'HISO10029', version: V, title: 'Information classification and handling',
23
+ requirement: 'Health information is classified and handled according to its sensitivity, including identification of personal and sensitive data.',
24
+ sourceRef: ref('Information Classification'), url: URL, verified: true },
25
+ { id: 'HISO-DEV', framework: 'HISO10029', version: V, title: 'Secure development and change',
26
+ requirement: 'Application code and changes follow secure development practices that prevent introduction of vulnerabilities affecting health information.',
27
+ sourceRef: ref('Secure Development'), url: URL, verified: true },
28
+ { id: 'HISO-COMM', framework: 'HISO10029', version: V, title: 'Communications and integration security',
29
+ requirement: 'Integrations and external communications carrying health information use secure, controlled, and authorised channels.',
30
+ sourceRef: ref('Communications Security'), url: URL, verified: true },
31
+ { id: 'HISO-GOV', framework: 'HISO10029', version: V, title: 'Security configuration and governance',
32
+ requirement: 'Systems holding health information are securely configured, kept current, and governed against a defined security baseline.',
33
+ sourceRef: ref('Security Governance'), url: URL, verified: true },
34
+ ];
35
+ //# sourceMappingURL=hiso10029.js.map
@@ -0,0 +1,4 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const ALL_CONTROLS: ControlDef[];
3
+ export declare function getControl(id: string): ControlDef | undefined;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { OWASP_CONTROLS } from './owasp.js';
2
+ import { SOC2_CONTROLS } from './soc2.js';
3
+ import { ISO27001_CONTROLS } from './iso27001.js';
4
+ import { SBS_CONTROLS } from './sbs.js';
5
+ import { PRIVACY_ACT_CONTROLS } from './privacyAct.js';
6
+ import { HISO10029_CONTROLS } from './hiso10029.js';
7
+ import { NZISM_CONTROLS } from './nzism.js';
8
+ export const ALL_CONTROLS = [
9
+ ...OWASP_CONTROLS,
10
+ ...SOC2_CONTROLS,
11
+ ...ISO27001_CONTROLS,
12
+ ...SBS_CONTROLS,
13
+ ...PRIVACY_ACT_CONTROLS,
14
+ ...HISO10029_CONTROLS,
15
+ ...NZISM_CONTROLS,
16
+ ];
17
+ const BY_ID = new Map(ALL_CONTROLS.map((c) => [c.id, c]));
18
+ export function getControl(id) {
19
+ return BY_ID.get(id);
20
+ }
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const ISO27001_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=iso27001.d.ts.map
@@ -0,0 +1,39 @@
1
+ // ISO/IEC 27001:2022 Annex A. Control numbers + titles VERIFIED 2026-06 against an authoritative
2
+ // Annex A reference (isms.online). Remapped from the withdrawn 2013 Annex A numbering to the 2022
3
+ // structure (Organisational 5.x, People 6.x, Physical 7.x, Technological 8.x). `requirement` is a
4
+ // faithful paraphrase; verbatim control text is in the purchased standard.
5
+ const V = 'ISO/IEC 27001:2022';
6
+ const ref = (n) => `ISO/IEC 27001:2022, Annex A ${n}`;
7
+ export const ISO27001_CONTROLS = [
8
+ { id: 'ISO-A.5.12', framework: 'ISO27001', version: V, title: 'Classification of information',
9
+ requirement: 'Information is classified according to its confidentiality, integrity, and availability needs and legal requirements.',
10
+ sourceRef: ref('A.5.12'), verified: true },
11
+ { id: 'ISO-A.5.14', framework: 'ISO27001', version: V, title: 'Information transfer',
12
+ requirement: 'Information transfer is protected by rules, procedures, and agreements across all communication channels.',
13
+ sourceRef: ref('A.5.14'), verified: true },
14
+ { id: 'ISO-A.5.18', framework: 'ISO27001', version: V, title: 'Access rights',
15
+ requirement: 'Access rights to information and assets are provisioned, reviewed, modified, and removed per the access control policy.',
16
+ sourceRef: ref('A.5.18'), verified: true },
17
+ { id: 'ISO-A.8.3', framework: 'ISO27001', version: V, title: 'Information access restriction',
18
+ requirement: 'Access to information and application functions is restricted in line with the access control policy.',
19
+ sourceRef: ref('A.8.3'), verified: true },
20
+ { id: 'ISO-A.8.8', framework: 'ISO27001', version: V, title: 'Management of technical vulnerabilities',
21
+ requirement: 'Technical vulnerabilities are identified, evaluated, and remediated in a timely manner.',
22
+ sourceRef: ref('A.8.8'), verified: true },
23
+ { id: 'ISO-A.8.15', framework: 'ISO27001', version: V, title: 'Logging',
24
+ requirement: 'Logs recording activities, exceptions, faults, and security events are produced, stored, protected, and reviewed.',
25
+ sourceRef: ref('A.8.15'), verified: true },
26
+ { id: 'ISO-A.8.24', framework: 'ISO27001', version: V, title: 'Use of cryptography',
27
+ requirement: 'Rules for the effective use of cryptography, including key management, protect information confidentiality and integrity.',
28
+ sourceRef: ref('A.8.24'), verified: true },
29
+ { id: 'ISO-A.8.25', framework: 'ISO27001', version: V, title: 'Secure development life cycle',
30
+ requirement: 'Rules for the secure development of software and systems are established and applied.',
31
+ sourceRef: ref('A.8.25'), verified: true },
32
+ { id: 'ISO-A.8.26', framework: 'ISO27001', version: V, title: 'Application security requirements',
33
+ requirement: 'Information security requirements are identified, specified, and approved when developing or acquiring applications.',
34
+ sourceRef: ref('A.8.26'), verified: true },
35
+ { id: 'ISO-A.8.32', framework: 'ISO27001', version: V, title: 'Change management',
36
+ requirement: 'Changes to information processing facilities and systems are subject to change management procedures.',
37
+ sourceRef: ref('A.8.32'), verified: true },
38
+ ];
39
+ //# sourceMappingURL=iso27001.js.map
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const NZISM_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=nzism.d.ts.map
@@ -0,0 +1,31 @@
1
+ // New Zealand Information Security Manual (NZISM), GCSB/NCSC.
2
+ // Chapter references VERIFIED 2026-06 against the official manual (https://nzism.gcsb.govt.nz/ism-document),
3
+ // current version v3.8 (July 2025). These are CHAPTER/SECTION-level mappings; refining to individual
4
+ // NZISM control numbers (e.g. 16.1.35) is a future granularity pass. `verified` = the chapter reference
5
+ // is confirmed to exist with this title in the current NZISM.
6
+ const V = 'NZISM v3.8';
7
+ const URL = 'https://nzism.gcsb.govt.nz/ism-document';
8
+ export const NZISM_CONTROLS = [
9
+ { id: 'NZISM-AC', framework: 'NZISM', version: V, title: 'Access control and privilege management',
10
+ requirement: 'Access to systems and information is granted on a least-privilege, need-to-know basis; privileged access is controlled and reviewed.',
11
+ sourceRef: 'NZISM v3.8, Ch.16 Authentication and Access Controls (16.2 System Access, 16.3 Privileged User Access)', url: URL, verified: true },
12
+ { id: 'NZISM-AUTH', framework: 'NZISM', version: V, title: 'Identification, authentication and MFA',
13
+ requirement: 'Users and systems are uniquely identified and strongly authenticated, including multi-factor authentication.',
14
+ sourceRef: 'NZISM v3.8, Ch.16 Authentication and Access Controls (16.1 Identification, Authentication and Authorisation, 16.7 Multi-Factor Authentication)', url: URL, verified: true },
15
+ { id: 'NZISM-LOG', framework: 'NZISM', version: V, title: 'Event monitoring, logging and auditing',
16
+ requirement: 'Security-relevant events are logged with sufficient detail and retention, and reviewed to detect and investigate incidents.',
17
+ sourceRef: 'NZISM v3.8, §16.6 Event Monitoring, Logging and Auditing', url: URL, verified: true },
18
+ { id: 'NZISM-CRYPTO', framework: 'NZISM', version: V, title: 'Cryptography and key management',
19
+ requirement: 'Approved cryptographic algorithms, protocols, and key management protect information in transit and at rest.',
20
+ sourceRef: 'NZISM v3.8, Ch.17 Cryptography', url: URL, verified: true },
21
+ { id: 'NZISM-SW', framework: 'NZISM', version: V, title: 'Software and application security',
22
+ requirement: 'Applications are developed and configured securely, mitigating common code-level vulnerabilities and unsafe execution.',
23
+ sourceRef: 'NZISM v3.8, Ch.14 Software Security', url: URL, verified: true },
24
+ { id: 'NZISM-NET', framework: 'NZISM', version: V, title: 'Network security and gateways',
25
+ requirement: 'Network connections, gateways, and external integrations are restricted to authorised, secured endpoints.',
26
+ sourceRef: 'NZISM v3.8, Ch.18 Network Security / Ch.19 Gateway Security', url: URL, verified: true },
27
+ { id: 'NZISM-CONFIG', framework: 'NZISM', version: V, title: 'System hardening and configuration',
28
+ requirement: 'Systems are hardened to a secure baseline, kept current with security updates, and unnecessary functionality is disabled.',
29
+ sourceRef: 'NZISM v3.8, Ch.12 Product Security (configuration and patching)', url: URL, verified: true },
30
+ ];
31
+ //# sourceMappingURL=nzism.js.map
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const OWASP_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=owasp.d.ts.map
@@ -0,0 +1,37 @@
1
+ // Verified 2026-06 against the official source: https://owasp.org/Top10/2021/
2
+ // (OWASP Top 10:2025 now exists; this catalog pins the 2021 edition as a stable citation.)
3
+ const V = 'OWASP Top 10:2021';
4
+ export const OWASP_CONTROLS = [
5
+ { id: 'OWASP-A01', framework: 'OWASP', version: V, title: 'Broken Access Control',
6
+ requirement: 'Access control enforces policy so users cannot act outside their intended permissions; deny by default, enforce record/field ownership.',
7
+ sourceRef: 'OWASP Top 10:2021 A01', verified: true },
8
+ { id: 'OWASP-A02', framework: 'OWASP', version: V, title: 'Cryptographic Failures',
9
+ requirement: 'Sensitive data (credentials, secrets, PII) is protected in transit and at rest; secrets are not hardcoded or exposed.',
10
+ sourceRef: 'OWASP Top 10:2021 A02', verified: true },
11
+ { id: 'OWASP-A03', framework: 'OWASP', version: V, title: 'Injection',
12
+ requirement: 'Untrusted input is validated/escaped so it cannot alter queries, markup, or commands (SOQL injection, XSS).',
13
+ sourceRef: 'OWASP Top 10:2021 A03', verified: true },
14
+ { id: 'OWASP-A05', framework: 'OWASP', version: V, title: 'Security Misconfiguration',
15
+ requirement: 'Platform and application security settings are hardened and reviewed; unnecessary features and exposure are removed.',
16
+ sourceRef: 'OWASP Top 10:2021 A05', verified: true },
17
+ { id: 'OWASP-A06', framework: 'OWASP', version: V, title: 'Vulnerable and Outdated Components',
18
+ requirement: 'Installed packages and platform components are inventoried and kept current; outdated/unsupported components are flagged.',
19
+ sourceRef: 'OWASP Top 10:2021 A06', verified: true },
20
+ { id: 'OWASP-A07', framework: 'OWASP', version: V, title: 'Identification and Authentication Failures',
21
+ requirement: 'Authentication is strong (MFA, session controls, IP/login policy) and resistant to credential stuffing and session abuse.',
22
+ sourceRef: 'OWASP Top 10:2021 A07', verified: true },
23
+ { id: 'OWASP-A08', framework: 'OWASP', version: V, title: 'Software and Data Integrity Failures',
24
+ requirement: 'Software, packages, and deployments originate from trusted sources with integrity controls; unmanaged/unverified components and uncontrolled deployment activity are flagged.',
25
+ sourceRef: 'OWASP Top 10:2021 A08', verified: true },
26
+ { id: 'OWASP-A09', framework: 'OWASP', version: V, title: 'Security Logging and Monitoring Failures',
27
+ requirement: 'Security-relevant events are logged, retained, and monitored so incidents can be detected and investigated.',
28
+ sourceRef: 'OWASP Top 10:2021 A09', verified: true },
29
+ { id: 'OWASP-A10', framework: 'OWASP', version: V, title: 'Server-Side Request Forgery (SSRF)',
30
+ requirement: 'Server-side requests (Apex callouts, remote sites, integrations) are restricted to trusted, explicitly allowlisted endpoints to prevent forged requests to internal or unintended targets.',
31
+ sourceRef: 'OWASP Top 10:2021 A10', verified: true },
32
+ ];
33
+ // Note: OWASP-A04 (Insecure Design) is intentionally NOT catalogued. It concerns
34
+ // design-level flaws, not org configuration, so no read-only config check maps to it.
35
+ // The executive report's scope section declares A04 as out of assessment scope rather
36
+ // than forcing a weak mapping.
37
+ //# sourceMappingURL=owasp.js.map
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const PRIVACY_ACT_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=privacyAct.d.ts.map
@@ -0,0 +1,17 @@
1
+ // New Zealand Privacy Act 2020 — Information Privacy Principles (IPPs).
2
+ // IPP titles verified 2026-06 against the Office of the Privacy Commissioner
3
+ // (https://privacy.org.nz/privacy-act-2020/privacy-principles/). Requirement text is a close
4
+ // paraphrase of the statute; the legislation site (legislation.govt.nz) is the primary source.
5
+ const V = 'NZ Privacy Act 2020 (IPPs)';
6
+ export const PRIVACY_ACT_CONTROLS = [
7
+ { id: 'PRIVACY-IPP5', framework: 'PRIVACY_ACT', version: V, title: 'IPP 5 — Storage and security of personal information',
8
+ requirement: 'An agency holding personal information must ensure it is protected by such security safeguards as are reasonable to prevent loss, misuse, and unauthorised access, use, modification, or disclosure.',
9
+ sourceRef: 'Privacy Act 2020, IPP 5', url: 'https://www.legislation.govt.nz/act/public/2020/0031/latest/LMS23342.html', verified: true },
10
+ { id: 'PRIVACY-IPP9', framework: 'PRIVACY_ACT', version: V, title: 'IPP 9 — Retention of personal information',
11
+ requirement: 'An agency must not keep personal information for longer than is required for the purposes for which it may lawfully be used.',
12
+ sourceRef: 'Privacy Act 2020, IPP 9', verified: true },
13
+ { id: 'PRIVACY-IPP12', framework: 'PRIVACY_ACT', version: V, title: 'IPP 12 — Disclosure of personal information outside New Zealand',
14
+ requirement: 'An agency may disclose personal information to a foreign person or entity only where comparable safeguards (or specified exceptions) apply.',
15
+ sourceRef: 'Privacy Act 2020, IPP 12', verified: true },
16
+ ];
17
+ //# sourceMappingURL=privacyAct.js.map
@@ -0,0 +1,3 @@
1
+ import type { ControlDef } from '../types.js';
2
+ export declare const SBS_CONTROLS: ControlDef[];
3
+ //# sourceMappingURL=sbs.d.ts.map