@cclabsnz/sf-audit 1.3.0 → 1.4.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 +101 -5
- package/lib/api/MetadataClient.d.ts +4 -0
- package/lib/api/MetadataClient.js +2 -0
- package/lib/api/MetadataClientImpl.d.ts +8 -0
- package/lib/api/MetadataClientImpl.js +22 -0
- package/lib/api/RestClient.d.ts +1 -0
- package/lib/api/RestClientImpl.d.ts +1 -0
- package/lib/api/RestClientImpl.js +6 -0
- package/lib/chains/CapabilityRegistry.js +19 -0
- package/lib/chains/namedChains.js +22 -0
- package/lib/checks/eventLogAccess.d.ts +14 -0
- package/lib/checks/eventLogAccess.js +33 -0
- package/lib/checks/impl/AuthProvidersCheck.d.ts +17 -0
- package/lib/checks/impl/AuthProvidersCheck.js +88 -0
- package/lib/checks/impl/ClassicSitesCheck.d.ts +17 -0
- package/lib/checks/impl/ClassicSitesCheck.js +65 -0
- package/lib/checks/impl/DataExportAccessCheck.d.ts +19 -0
- package/lib/checks/impl/DataExportAccessCheck.js +79 -0
- package/lib/checks/impl/EncryptionCoverageCheck.d.ts +19 -0
- package/lib/checks/impl/EncryptionCoverageCheck.js +108 -0
- package/lib/checks/impl/EventMonitoringCheck.js +8 -5
- package/lib/checks/impl/ExperienceCspCheck.d.ts +18 -0
- package/lib/checks/impl/ExperienceCspCheck.js +57 -0
- package/lib/checks/impl/ExternalCredentialsCheck.d.ts +17 -0
- package/lib/checks/impl/ExternalCredentialsCheck.js +74 -0
- package/lib/checks/impl/GuestApiAccessCheck.d.ts +19 -0
- package/lib/checks/impl/GuestApiAccessCheck.js +113 -0
- package/lib/checks/impl/GuestObjectExposureCheck.d.ts +44 -0
- package/lib/checks/impl/GuestObjectExposureCheck.js +241 -0
- package/lib/checks/impl/GuestRecordAccessPolicyCheck.d.ts +34 -0
- package/lib/checks/impl/GuestRecordAccessPolicyCheck.js +120 -0
- package/lib/checks/impl/GuestSiteOptionsCheck.d.ts +18 -0
- package/lib/checks/impl/GuestSiteOptionsCheck.js +92 -0
- package/lib/checks/impl/GuestTrafficAnomalyCheck.d.ts +23 -0
- package/lib/checks/impl/GuestTrafficAnomalyCheck.js +343 -0
- package/lib/checks/impl/LoginAccessPolicyCheck.d.ts +26 -0
- package/lib/checks/impl/LoginAccessPolicyCheck.js +117 -0
- package/lib/checks/impl/LoginAnomalyCheck.d.ts +17 -0
- package/lib/checks/impl/LoginAnomalyCheck.js +98 -0
- package/lib/checks/impl/SandboxDataMaskingCheck.d.ts +17 -0
- package/lib/checks/impl/SandboxDataMaskingCheck.js +85 -0
- package/lib/checks/impl/SessionHardeningCheck.d.ts +21 -0
- package/lib/checks/impl/SessionHardeningCheck.js +134 -0
- package/lib/checks/impl/ThreatDetectionCheck.d.ts +17 -0
- package/lib/checks/impl/ThreatDetectionCheck.js +91 -0
- package/lib/checks/registry.js +33 -0
- package/lib/commands/audit/diff.js +9 -5
- package/lib/commands/audit/events/pull.d.ts +17 -0
- package/lib/commands/audit/events/pull.js +88 -0
- package/lib/commands/audit/security.d.ts +4 -0
- package/lib/commands/audit/security.js +40 -16
- package/lib/compliance/mapping.js +27 -7
- package/lib/context/AuditCache.d.ts +3 -0
- package/lib/context/AuditContext.d.ts +2 -0
- package/lib/events/EventBaselineStore.d.ts +16 -0
- package/lib/events/EventBaselineStore.js +55 -0
- package/lib/events/eventLogQuery.d.ts +21 -0
- package/lib/events/eventLogQuery.js +34 -0
- package/lib/events/pullEventLogs.d.ts +51 -0
- package/lib/events/pullEventLogs.js +79 -0
- package/lib/findings/CheckMeta.js +16 -0
- package/lib/lib/wire.d.ts +2 -0
- package/lib/lib/wire.js +3 -0
- package/package.json +13 -2
|
@@ -71,6 +71,22 @@ const BASE_CHECK_CONTROL_MAP = {
|
|
|
71
71
|
'public-content-exposure': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.14'],
|
|
72
72
|
'privileged-access': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.5.18', 'SBS-ACS-004'],
|
|
73
73
|
'separation-of-duties': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.5.18', 'SBS-ACS-004'],
|
|
74
|
+
'guest-object-exposure': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.18', 'SBS-CPORTAL-002'],
|
|
75
|
+
'guest-site-options': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.14', 'SBS-CPORTAL-003'],
|
|
76
|
+
'guest-record-access-policy': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.18', 'SBS-CPORTAL-002'],
|
|
77
|
+
'guest-traffic-anomaly': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.8.15', 'SBS-MON-003'],
|
|
78
|
+
'threat-detection': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.8.15', 'SBS-MON-001'],
|
|
79
|
+
'login-access-policy': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.5.18', 'SBS-ACS-004'],
|
|
80
|
+
'data-export-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.8.3'],
|
|
81
|
+
'classic-sites': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.8.3', 'SBS-CPORTAL-003'],
|
|
82
|
+
'auth-providers': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.8.3', 'SBS-AUTH-001'],
|
|
83
|
+
'guest-api-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.18', 'SBS-CPORTAL-002'],
|
|
84
|
+
'external-credentials': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.8.3', 'SBS-INT-003'],
|
|
85
|
+
'login-anomaly': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.8.15', 'SBS-MON-003'],
|
|
86
|
+
'session-hardening': ['OWASP-A05', 'SOC2-CC6.1', 'ISO-A.8.26'],
|
|
87
|
+
'encryption-coverage': ['OWASP-A02', 'SOC2-CC6.1', 'ISO-A.8.24'],
|
|
88
|
+
'experience-csp': ['OWASP-A05', 'SOC2-CC6.6', 'ISO-A.8.26'],
|
|
89
|
+
'sandbox-data-masking': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.5.12'],
|
|
74
90
|
};
|
|
75
91
|
// NZ pack crosswalk — each check belongs to one domain; the domain's NZ control ids are
|
|
76
92
|
// layered onto its base entry. HISO/NZISM are domain/chapter-level drafts; Privacy Act IPPs
|
|
@@ -81,25 +97,29 @@ const NZ_CROSSWALK = [
|
|
|
81
97
|
'field-level-security', 'standard-profiles', 'api-client-permission', 'integration-users',
|
|
82
98
|
'escalation-perms', 'report-folder-access', 'apex-crud-fls', 'apex-rest-endpoint',
|
|
83
99
|
'guest-executable-apex', 'experience-cloud-site', 'content-links', 'apex-sharing', 'flows-without-sharing',
|
|
84
|
-
'public-content-exposure', 'privileged-access', 'separation-of-duties'
|
|
100
|
+
'public-content-exposure', 'privileged-access', 'separation-of-duties',
|
|
101
|
+
'guest-object-exposure', 'guest-site-options', 'guest-record-access-policy',
|
|
102
|
+
'login-access-policy', 'data-export-access', 'classic-sites', 'guest-api-access'] },
|
|
85
103
|
{ controls: ['HISO-AUTH', 'NZISM-AUTH', 'PRIVACY-IPP5'],
|
|
86
104
|
checks: ['login-session', 'ip-restrictions', 'password-session-policy', 'sso-enforcement', 'mfa-enforcement',
|
|
87
105
|
'trusted-ip-ranges', 'my-domain-login-policy', 'high-assurance-session', 'internal-user-mfa',
|
|
88
|
-
'mfa-registration', 'mfa-method-strength', 'failed-login-detection', 'enhanced-domains'
|
|
106
|
+
'mfa-registration', 'mfa-method-strength', 'failed-login-detection', 'enhanced-domains',
|
|
107
|
+
'auth-providers'] },
|
|
89
108
|
{ controls: ['HISO-CRYPTO', 'NZISM-CRYPTO', 'PRIVACY-IPP5'],
|
|
90
|
-
checks: ['named-credentials', 'hardcoded-credentials', 'custom-settings', 'certificate-expiry', 'custom-labels-credential'] },
|
|
109
|
+
checks: ['named-credentials', 'hardcoded-credentials', 'custom-settings', 'certificate-expiry', 'custom-labels-credential', 'external-credentials', 'encryption-coverage'] },
|
|
91
110
|
{ controls: ['HISO-LOG', 'NZISM-LOG'],
|
|
92
111
|
checks: ['audit-trail', 'apex-logging', 'event-monitoring', 'siem-integration', 'anonymous-apex-audit',
|
|
93
|
-
'debug-log-access', 'transaction-security-policy'
|
|
112
|
+
'debug-log-access', 'transaction-security-policy', 'threat-detection', 'guest-traffic-anomaly',
|
|
113
|
+
'login-anomaly'] },
|
|
94
114
|
{ controls: ['HISO-DEV', 'NZISM-SW'],
|
|
95
115
|
checks: ['code-security', 'visualforce-xss', 'scheduled-apex'] },
|
|
96
116
|
{ controls: ['HISO-COMM', 'NZISM-NET', 'PRIVACY-IPP12'],
|
|
97
117
|
checks: ['remote-sites', 'csp-trusted-sites', 'connected-apps', 'connected-app-scope', 'connected-app-inactivity', 'cors-allowlist',
|
|
98
|
-
'email-security', 'outbound-messages'] },
|
|
118
|
+
'email-security', 'outbound-messages', 'experience-csp'] },
|
|
99
119
|
{ controls: ['HISO-DATA', 'PRIVACY-IPP5'],
|
|
100
|
-
checks: ['data-classification', 'field-history-tracking'] },
|
|
120
|
+
checks: ['data-classification', 'field-history-tracking', 'sandbox-data-masking'] },
|
|
101
121
|
{ controls: ['HISO-GOV', 'NZISM-CONFIG'],
|
|
102
|
-
checks: ['health-check', 'api-limits', 'release-updates', 'legacy-api-version', 'installed-packages', 'deployment-identity'] },
|
|
122
|
+
checks: ['health-check', 'api-limits', 'release-updates', 'legacy-api-version', 'installed-packages', 'deployment-identity', 'session-hardening'] },
|
|
103
123
|
{ controls: ['PRIVACY-IPP9'],
|
|
104
124
|
checks: ['inactive-users'] },
|
|
105
125
|
];
|
|
@@ -12,10 +12,13 @@ export interface VfPageBody {
|
|
|
12
12
|
name: string;
|
|
13
13
|
markup: string;
|
|
14
14
|
}
|
|
15
|
+
export type EventLogAccess = 'no-permission' | 'not-enabled' | 'unknown';
|
|
15
16
|
export interface EventLogSummary {
|
|
16
17
|
earliestDate: string | null;
|
|
17
18
|
totalFiles: number;
|
|
18
19
|
eventTypes: string[];
|
|
20
|
+
accessible?: boolean;
|
|
21
|
+
accessError?: EventLogAccess;
|
|
19
22
|
}
|
|
20
23
|
export interface MfaRegistration {
|
|
21
24
|
userId: string;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { SoqlClient } from '../api/SoqlClient.js';
|
|
2
2
|
import type { ToolingClient } from '../api/ToolingClient.js';
|
|
3
3
|
import type { RestClient } from '../api/RestClient.js';
|
|
4
|
+
import type { MetadataClient } from '../api/MetadataClient.js';
|
|
4
5
|
import type { OrgInfo } from './OrgInfo.js';
|
|
5
6
|
import type { AuditCache } from './AuditCache.js';
|
|
6
7
|
export interface AuditContext {
|
|
7
8
|
readonly soql: SoqlClient;
|
|
8
9
|
readonly tooling: ToolingClient;
|
|
9
10
|
readonly rest: RestClient;
|
|
11
|
+
readonly metadata?: MetadataClient;
|
|
10
12
|
readonly orgInfo: OrgInfo;
|
|
11
13
|
cache: AuditCache;
|
|
12
14
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class EventBaselineStore {
|
|
2
|
+
private readonly root;
|
|
3
|
+
constructor(root?: string);
|
|
4
|
+
static defaultRoot(): string;
|
|
5
|
+
/** The per-org base directory logs for this org are stored under. */
|
|
6
|
+
orgDir(orgId: string): string;
|
|
7
|
+
/** Absolute path a given log file is (or would be) stored at. */
|
|
8
|
+
pathFor(orgId: string, eventType: string, logDate: string, id: string): string;
|
|
9
|
+
/** True when this EventLogFile is already on disk — the dedup / idempotency check. */
|
|
10
|
+
has(orgId: string, eventType: string, logDate: string, id: string): boolean;
|
|
11
|
+
/** Write a CSV body verbatim; returns the saved path. Best-effort. */
|
|
12
|
+
save(orgId: string, eventType: string, logDate: string, id: string, body: string): string;
|
|
13
|
+
/** Write a per-run manifest JSON under {root}/{orgId}/_manifests/; returns its path. */
|
|
14
|
+
writeManifest(orgId: string, manifest: unknown): string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=EventBaselineStore.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/events/EventBaselineStore.ts
|
|
2
|
+
// Local, on-disk archive of free EventLogFile CSVs. Mirrors HistoryStore: writes under
|
|
3
|
+
// ~/.sf/event-baseline/{orgId}/, takes an optional root for testability, and is best-effort
|
|
4
|
+
// (warns rather than throws) so a daily cron run never dies on a filesystem hiccup.
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import * as os from 'node:os';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
export class EventBaselineStore {
|
|
9
|
+
root;
|
|
10
|
+
constructor(root) {
|
|
11
|
+
this.root = root ?? EventBaselineStore.defaultRoot();
|
|
12
|
+
}
|
|
13
|
+
static defaultRoot() {
|
|
14
|
+
return path.join(os.homedir(), '.sf', 'event-baseline');
|
|
15
|
+
}
|
|
16
|
+
/** The per-org base directory logs for this org are stored under. */
|
|
17
|
+
orgDir(orgId) {
|
|
18
|
+
return path.join(this.root, orgId);
|
|
19
|
+
}
|
|
20
|
+
/** Absolute path a given log file is (or would be) stored at. */
|
|
21
|
+
pathFor(orgId, eventType, logDate, id) {
|
|
22
|
+
return path.join(this.root, orgId, eventType, `${logDate}-${id}.csv`);
|
|
23
|
+
}
|
|
24
|
+
/** True when this EventLogFile is already on disk — the dedup / idempotency check. */
|
|
25
|
+
has(orgId, eventType, logDate, id) {
|
|
26
|
+
return fs.existsSync(this.pathFor(orgId, eventType, logDate, id));
|
|
27
|
+
}
|
|
28
|
+
/** Write a CSV body verbatim; returns the saved path. Best-effort. */
|
|
29
|
+
save(orgId, eventType, logDate, id, body) {
|
|
30
|
+
const filePath = this.pathFor(orgId, eventType, logDate, id);
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
33
|
+
fs.writeFileSync(filePath, body, 'utf-8');
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
process.stderr.write(`[sf-audit] Warning: could not save event log ${id}: ${String(err)}\n`);
|
|
37
|
+
}
|
|
38
|
+
return filePath;
|
|
39
|
+
}
|
|
40
|
+
/** Write a per-run manifest JSON under {root}/{orgId}/_manifests/; returns its path. */
|
|
41
|
+
writeManifest(orgId, manifest) {
|
|
42
|
+
const dir = path.join(this.root, orgId, '_manifests');
|
|
43
|
+
const suffix = Math.random().toString(36).slice(2, 8);
|
|
44
|
+
const filePath = path.join(dir, `manifest-${Date.now()}-${suffix}.json`);
|
|
45
|
+
try {
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
fs.writeFileSync(filePath, JSON.stringify(manifest, null, 2), 'utf-8');
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
process.stderr.write(`[sf-audit] Warning: could not write event manifest: ${String(err)}\n`);
|
|
51
|
+
}
|
|
52
|
+
return filePath;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=EventBaselineStore.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface EventLogQueryOptions {
|
|
2
|
+
/** Number of days of LogDate to request (LAST_N_DAYS:N). */
|
|
3
|
+
since: number;
|
|
4
|
+
/** Optional EventType allow-list (already sanitised or not — we sanitise again). */
|
|
5
|
+
types?: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reduce free-form `--types` input to safe EventType tokens. EventTypes are PascalCase
|
|
9
|
+
* identifiers (Login, ApiTotalUsage, LightningError, …), so we strip anything that is not
|
|
10
|
+
* alphanumeric. This doubles as the SOQL-injection guard for the IN clause.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeTypes(raw: string | undefined): string[];
|
|
13
|
+
/** Normalise a Salesforce LogDate (datetime) to a YYYY-MM-DD string for filenames. */
|
|
14
|
+
export declare function toLogDate(raw: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Build the read-only EventLogFile discovery query. `Interval = 'Daily'` excludes the paid
|
|
17
|
+
* hourly logs; `LogDate = LAST_N_DAYS:N` bounds the window. `since` is coerced to a
|
|
18
|
+
* non-negative integer and `types` are sanitised, so the interpolated string is injection-safe.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildEventLogQuery(opts: EventLogQueryOptions): string;
|
|
21
|
+
//# sourceMappingURL=eventLogQuery.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Pure helpers for the `audit events pull` command. Kept free of I/O so they are
|
|
2
|
+
// unit-testable without an org connection or the oclif command harness.
|
|
3
|
+
/**
|
|
4
|
+
* Reduce free-form `--types` input to safe EventType tokens. EventTypes are PascalCase
|
|
5
|
+
* identifiers (Login, ApiTotalUsage, LightningError, …), so we strip anything that is not
|
|
6
|
+
* alphanumeric. This doubles as the SOQL-injection guard for the IN clause.
|
|
7
|
+
*/
|
|
8
|
+
export function sanitizeTypes(raw) {
|
|
9
|
+
if (!raw)
|
|
10
|
+
return [];
|
|
11
|
+
return raw
|
|
12
|
+
.split(',')
|
|
13
|
+
.map((t) => t.replace(/[^A-Za-z0-9]/g, '').trim())
|
|
14
|
+
.filter((t) => t.length > 0);
|
|
15
|
+
}
|
|
16
|
+
/** Normalise a Salesforce LogDate (datetime) to a YYYY-MM-DD string for filenames. */
|
|
17
|
+
export function toLogDate(raw) {
|
|
18
|
+
return String(raw).slice(0, 10);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the read-only EventLogFile discovery query. `Interval = 'Daily'` excludes the paid
|
|
22
|
+
* hourly logs; `LogDate = LAST_N_DAYS:N` bounds the window. `since` is coerced to a
|
|
23
|
+
* non-negative integer and `types` are sanitised, so the interpolated string is injection-safe.
|
|
24
|
+
*/
|
|
25
|
+
export function buildEventLogQuery(opts) {
|
|
26
|
+
const since = Math.max(0, Math.trunc(opts.since));
|
|
27
|
+
const types = (opts.types ?? []).filter((t) => t.length > 0);
|
|
28
|
+
const typeClause = types.length > 0 ? ` AND EventType IN (${types.map((t) => `'${t}'`).join(', ')})` : '';
|
|
29
|
+
return ('SELECT Id, EventType, LogDate, LogFileLength, Interval, LogFileFieldNames ' +
|
|
30
|
+
'FROM EventLogFile ' +
|
|
31
|
+
`WHERE Interval = 'Daily' AND LogDate = LAST_N_DAYS:${since}${typeClause} ` +
|
|
32
|
+
'ORDER BY LogDate');
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=eventLogQuery.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SoqlClient } from '../api/SoqlClient.js';
|
|
2
|
+
import type { RestClient } from '../api/RestClient.js';
|
|
3
|
+
import type { EventLogAccess } from '../context/AuditCache.js';
|
|
4
|
+
import { EventBaselineStore } from './EventBaselineStore.js';
|
|
5
|
+
/** The subset of EventLogFile fields the discovery query returns. */
|
|
6
|
+
export interface EventLogFileRow {
|
|
7
|
+
Id: string;
|
|
8
|
+
EventType: string;
|
|
9
|
+
LogDate: string;
|
|
10
|
+
LogFileLength?: number;
|
|
11
|
+
Interval?: string;
|
|
12
|
+
LogFileFieldNames?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Outcome for one EventLogFile row in a run. */
|
|
15
|
+
export interface PulledLog {
|
|
16
|
+
id: string;
|
|
17
|
+
eventType: string;
|
|
18
|
+
logDate: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
savedPath: string;
|
|
21
|
+
status: 'downloaded' | 'skipped' | 'failed';
|
|
22
|
+
}
|
|
23
|
+
/** Structured result of a pull run — returned by the command. */
|
|
24
|
+
export interface EventsPullResult {
|
|
25
|
+
orgId: string;
|
|
26
|
+
since: number;
|
|
27
|
+
storagePath: string;
|
|
28
|
+
found: number;
|
|
29
|
+
downloaded: number;
|
|
30
|
+
skipped: number;
|
|
31
|
+
failed: number;
|
|
32
|
+
totalBytes: number;
|
|
33
|
+
logs: PulledLog[];
|
|
34
|
+
manifestPath?: string;
|
|
35
|
+
/** Set when the EventLogFile query itself failed (no crash); tells license vs permission apart. */
|
|
36
|
+
accessError?: EventLogAccess;
|
|
37
|
+
}
|
|
38
|
+
export interface PullDeps {
|
|
39
|
+
soql: SoqlClient;
|
|
40
|
+
rest: RestClient;
|
|
41
|
+
store: EventBaselineStore;
|
|
42
|
+
orgId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PullOptions {
|
|
45
|
+
since: number;
|
|
46
|
+
types?: string[];
|
|
47
|
+
/** Optional sink for non-fatal warnings (per-file download failures). */
|
|
48
|
+
warn?: (msg: string) => void;
|
|
49
|
+
}
|
|
50
|
+
export declare function pullEventLogs(deps: PullDeps, opts: PullOptions): Promise<EventsPullResult>;
|
|
51
|
+
//# sourceMappingURL=pullEventLogs.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { classifyEventLogAccessError } from '../checks/eventLogAccess.js';
|
|
2
|
+
import { buildEventLogQuery, toLogDate } from './eventLogQuery.js';
|
|
3
|
+
export async function pullEventLogs(deps, opts) {
|
|
4
|
+
const { soql, rest, store, orgId } = deps;
|
|
5
|
+
const since = opts.since;
|
|
6
|
+
const storagePath = store.orgDir(orgId);
|
|
7
|
+
const base = {
|
|
8
|
+
orgId,
|
|
9
|
+
since,
|
|
10
|
+
storagePath,
|
|
11
|
+
found: 0,
|
|
12
|
+
downloaded: 0,
|
|
13
|
+
skipped: 0,
|
|
14
|
+
failed: 0,
|
|
15
|
+
totalBytes: 0,
|
|
16
|
+
logs: [],
|
|
17
|
+
};
|
|
18
|
+
let rows;
|
|
19
|
+
try {
|
|
20
|
+
rows = await soql.queryAll(buildEventLogQuery({ since, types: opts.types }));
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
// Inaccessible EventLogFile (unlicensed / no permission) must not crash the command.
|
|
24
|
+
return { ...base, accessError: classifyEventLogAccessError(err) };
|
|
25
|
+
}
|
|
26
|
+
base.found = rows.length;
|
|
27
|
+
for (const row of rows) {
|
|
28
|
+
const logDate = toLogDate(row.LogDate);
|
|
29
|
+
if (store.has(orgId, row.EventType, logDate, row.Id)) {
|
|
30
|
+
base.skipped += 1;
|
|
31
|
+
base.logs.push({
|
|
32
|
+
id: row.Id,
|
|
33
|
+
eventType: row.EventType,
|
|
34
|
+
logDate,
|
|
35
|
+
bytes: 0,
|
|
36
|
+
savedPath: store.pathFor(orgId, row.EventType, logDate, row.Id),
|
|
37
|
+
status: 'skipped',
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const body = await rest.getRaw(`/sobjects/EventLogFile/${row.Id}/LogFile`);
|
|
43
|
+
const savedPath = store.save(orgId, row.EventType, logDate, row.Id, body);
|
|
44
|
+
const bytes = Buffer.byteLength(body, 'utf-8');
|
|
45
|
+
base.downloaded += 1;
|
|
46
|
+
base.totalBytes += bytes;
|
|
47
|
+
base.logs.push({ id: row.Id, eventType: row.EventType, logDate, bytes, savedPath, status: 'downloaded' });
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
base.failed += 1;
|
|
51
|
+
base.logs.push({
|
|
52
|
+
id: row.Id,
|
|
53
|
+
eventType: row.EventType,
|
|
54
|
+
logDate,
|
|
55
|
+
bytes: 0,
|
|
56
|
+
savedPath: store.pathFor(orgId, row.EventType, logDate, row.Id),
|
|
57
|
+
status: 'failed',
|
|
58
|
+
});
|
|
59
|
+
opts.warn?.(`Failed to download EventLogFile ${row.Id} (${row.EventType} ${logDate}): ${String(err)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Only write a manifest when something was actually captured — a pure all-skipped or
|
|
63
|
+
// empty run leaves no new record to make.
|
|
64
|
+
if (base.downloaded > 0) {
|
|
65
|
+
base.manifestPath = store.writeManifest(orgId, {
|
|
66
|
+
orgId,
|
|
67
|
+
since,
|
|
68
|
+
pulledAt: new Date().toISOString(),
|
|
69
|
+
found: base.found,
|
|
70
|
+
downloaded: base.downloaded,
|
|
71
|
+
skipped: base.skipped,
|
|
72
|
+
failed: base.failed,
|
|
73
|
+
totalBytes: base.totalBytes,
|
|
74
|
+
logs: base.logs,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return base;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=pullEventLogs.js.map
|
|
@@ -65,6 +65,22 @@ export const CHECK_META = {
|
|
|
65
65
|
'public-content-exposure': { effort: 'quick', impact: 'Documents marked externally available and public static resources are retrievable without authentication by anyone with the URL.' },
|
|
66
66
|
'privileged-access': { effort: 'moderate', impact: 'Shadow admins hold full org control outside the admin profile, so a single takeover bypasses admin-focused monitoring and owns everything.' },
|
|
67
67
|
'separation-of-duties': { effort: 'moderate', impact: 'A single user holding a toxic permission combination can self-escalate, commit fraud, or tamper undetected with no second party to stop them.' },
|
|
68
|
+
'guest-object-exposure': { effort: 'moderate', impact: 'Grades guest-readable objects by ACTUAL UI-API reachability: objects the UI API models are bulk-readable unauthenticated via GraphQL (CRITICAL, incl. guest-owned records under a Private OWD, enabling mass PII exfiltration without login); objects readable only in the sharing model but not UI-API-modelled (Calendar, AuthSession, etc.) are separated as MEDIUM defense-in-depth, with UserRecordAccess as ground-truth read confirmation.' },
|
|
69
|
+
'guest-site-options': { effort: 'quick', impact: 'Guest file access and member visibility let unauthenticated visitors download public files and enumerate site members.' },
|
|
70
|
+
'threat-detection': { effort: 'moderate', impact: 'Without Guest User Anomaly storage, malicious guest bulk-reads are never flagged and cannot be reconstructed after the fact.' },
|
|
71
|
+
'guest-record-access-policy': { effort: 'quick', impact: 'Without "Secure guest user record access" enforced, guests own the records they submit and can read them under a Private OWD, turning a public form into an unauthenticated bulk-read surface.' },
|
|
72
|
+
'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.' },
|
|
73
|
+
'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.' },
|
|
74
|
+
'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.' },
|
|
75
|
+
'classic-sites': { effort: 'moderate', impact: 'Active classic Visualforce sites expose a second unauthenticated guest surface that the Experience Cloud checks never inspect.' },
|
|
76
|
+
'auth-providers': { effort: 'moderate', impact: 'Unvetted social/SAML identity providers with just-in-time provisioning can let attackers federate in or auto-create over-privileged users.' },
|
|
77
|
+
'guest-api-access': { effort: 'quick', impact: 'A guest user with API access can drive the raw REST/Bulk API, turning readable objects into scriptable mass extraction (and Hard Delete into irreversible destruction) without login.' },
|
|
78
|
+
'external-credentials': { effort: 'moderate', impact: 'Callouts with no or custom authentication can be spoofed or leak a static secret, exposing the integrated system and the data crossing it.' },
|
|
79
|
+
'login-anomaly': { effort: 'quick', impact: 'An account logging in from many distinct IPs signals credential sharing or compromise; caught late, it means an attacker already has a working session.' },
|
|
80
|
+
'session-hardening': { effort: 'quick', impact: 'Weak clickjack/CSRF/session-lock/XSS settings let attackers hijack authenticated sessions via framing, forged requests, or injected script.' },
|
|
81
|
+
'encryption-coverage': { effort: 'moderate', impact: 'Fields labelled PII/PHI but stored in plaintext are unprotected at rest and on export — the sensitivity is known, the protection is missing.' },
|
|
82
|
+
'experience-csp': { effort: 'moderate', impact: 'Relaxed CSP or disabled Lightning Web Security on a public site lets injected/third-party scripts run against unauthenticated visitors.' },
|
|
83
|
+
'sandbox-data-masking': { effort: 'moderate', impact: 'Unmasked production PII/PHI copied into a sandbox spreads sensitive data into a lower-trust environment with broader access and weaker monitoring.' },
|
|
68
84
|
};
|
|
69
85
|
export function getCheckMeta(id) {
|
|
70
86
|
return CHECK_META[id];
|
package/lib/lib/wire.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import type { Connection } from '@salesforce/core';
|
|
|
2
2
|
import { SoqlClientImpl } from '../api/SoqlClientImpl.js';
|
|
3
3
|
import { ToolingClientImpl } from '../api/ToolingClientImpl.js';
|
|
4
4
|
import { RestClientImpl } from '../api/RestClientImpl.js';
|
|
5
|
+
import { MetadataClientImpl } from '../api/MetadataClientImpl.js';
|
|
5
6
|
import type { AuditContext } from '../context/AuditContext.js';
|
|
6
7
|
import type { OrgInfo } from '../context/OrgInfo.js';
|
|
7
8
|
export declare function buildApiClients(conn: Connection): {
|
|
8
9
|
soql: SoqlClientImpl;
|
|
9
10
|
tooling: ToolingClientImpl;
|
|
10
11
|
rest: RestClientImpl;
|
|
12
|
+
metadata: MetadataClientImpl;
|
|
11
13
|
};
|
|
12
14
|
export declare function resolveOrgInfo(conn: Connection): Promise<OrgInfo>;
|
|
13
15
|
export declare function buildAuditContext(conn: Connection, orgInfo: OrgInfo): AuditContext;
|
package/lib/lib/wire.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { SoqlClientImpl } from '../api/SoqlClientImpl.js';
|
|
2
2
|
import { ToolingClientImpl } from '../api/ToolingClientImpl.js';
|
|
3
3
|
import { RestClientImpl } from '../api/RestClientImpl.js';
|
|
4
|
+
import { MetadataClientImpl } from '../api/MetadataClientImpl.js';
|
|
4
5
|
export function buildApiClients(conn) {
|
|
5
6
|
return {
|
|
6
7
|
soql: new SoqlClientImpl(conn),
|
|
7
8
|
tooling: new ToolingClientImpl(conn),
|
|
8
9
|
rest: new RestClientImpl(conn),
|
|
10
|
+
metadata: new MetadataClientImpl(conn),
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
13
|
export async function resolveOrgInfo(conn) {
|
|
@@ -28,6 +30,7 @@ export function buildAuditContext(conn, orgInfo) {
|
|
|
28
30
|
soql: clients.soql,
|
|
29
31
|
tooling: clients.tooling,
|
|
30
32
|
rest: clients.rest,
|
|
33
|
+
metadata: clients.metadata,
|
|
31
34
|
orgInfo,
|
|
32
35
|
cache: {},
|
|
33
36
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclabsnz/sf-audit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Salesforce Security Audit — native sf plugin",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -42,10 +42,21 @@
|
|
|
42
42
|
"devPlugins": [],
|
|
43
43
|
"topics": {
|
|
44
44
|
"audit": {
|
|
45
|
-
"description": "Salesforce security audit commands"
|
|
45
|
+
"description": "Salesforce security audit commands",
|
|
46
|
+
"subtopics": {
|
|
47
|
+
"events": {
|
|
48
|
+
"description": "Capture free EventLogFile logs to local disk"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
},
|
|
54
|
+
"pnpm": {
|
|
55
|
+
"overrides": {
|
|
56
|
+
"form-data": "^4.0.6",
|
|
57
|
+
"js-yaml@3": "^3.15.0"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
49
60
|
"overrides": {
|
|
50
61
|
"handlebars": "^4.7.9",
|
|
51
62
|
"minimatch@5": {
|