@cclabsnz/sf-audit 1.13.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/README.md +15 -4
- package/lib/checks/impl/AuditTrailCheck.js +18 -1
- package/lib/checks/impl/LegacyApiVersionCheck.js +14 -2
- package/lib/checks/impl/LightningMessageChannelCheck.d.ts +10 -0
- package/lib/checks/impl/LightningMessageChannelCheck.js +107 -0
- package/lib/checks/impl/MfaEnforcementCheck.js +19 -1
- package/lib/checks/impl/NamedCredentialsCheck.js +42 -29
- package/lib/checks/registry.js +2 -0
- package/lib/commands/audit/incident/collect.d.ts +22 -0
- package/lib/commands/audit/incident/collect.js +46 -0
- package/lib/commands/audit/incident/report.d.ts +29 -0
- package/lib/commands/audit/incident/report.js +87 -0
- package/lib/compliance/mapping.js +2 -1
- package/lib/findings/CheckMeta.js +1 -0
- package/lib/incident/analyse/actions.d.ts +22 -0
- package/lib/incident/analyse/actions.js +73 -0
- package/lib/incident/analyse/actors.d.ts +56 -0
- package/lib/incident/analyse/actors.js +231 -0
- package/lib/incident/analyse/baseline.d.ts +24 -0
- package/lib/incident/analyse/baseline.js +66 -0
- package/lib/incident/analyse/configDelta.d.ts +33 -0
- package/lib/incident/analyse/configDelta.js +98 -0
- package/lib/incident/analyse/index.d.ts +41 -0
- package/lib/incident/analyse/index.js +68 -0
- package/lib/incident/analyse/outcomes.d.ts +28 -0
- package/lib/incident/analyse/outcomes.js +32 -0
- package/lib/incident/analyse/responses.d.ts +59 -0
- package/lib/incident/analyse/responses.js +201 -0
- package/lib/incident/analyse/verdict.d.ts +40 -0
- package/lib/incident/analyse/verdict.js +149 -0
- package/lib/incident/bundleIo.d.ts +34 -0
- package/lib/incident/bundleIo.js +74 -0
- package/lib/incident/collect/collectBundle.d.ts +21 -0
- package/lib/incident/collect/collectBundle.js +130 -0
- package/lib/incident/collect/discoverWaves.d.ts +15 -0
- package/lib/incident/collect/discoverWaves.js +90 -0
- package/lib/incident/collect/followUp.d.ts +14 -0
- package/lib/incident/collect/followUp.js +64 -0
- package/lib/incident/collect/orgErrors.d.ts +5 -0
- package/lib/incident/collect/orgErrors.js +11 -0
- package/lib/incident/collect/snapshotOrg.d.ts +18 -0
- package/lib/incident/collect/snapshotOrg.js +117 -0
- package/lib/incident/collect/streamGuestLogs.d.ts +17 -0
- package/lib/incident/collect/streamGuestLogs.js +116 -0
- package/lib/incident/csv.d.ts +32 -0
- package/lib/incident/csv.js +176 -0
- package/lib/incident/ipRanges.d.ts +23 -0
- package/lib/incident/ipRanges.js +64 -0
- package/lib/incident/model.d.ts +132 -0
- package/lib/incident/model.js +26 -0
- package/lib/incident/render/evidence.d.ts +15 -0
- package/lib/incident/render/evidence.js +52 -0
- package/lib/incident/render/html.d.ts +7 -0
- package/lib/incident/render/html.js +144 -0
- package/lib/incident/render/labels.d.ts +9 -0
- package/lib/incident/render/labels.js +22 -0
- package/lib/incident/render/markdown.d.ts +17 -0
- package/lib/incident/render/markdown.js +91 -0
- package/lib/incident/render/redact.d.ts +7 -0
- package/lib/incident/render/redact.js +62 -0
- package/lib/incident/text.d.ts +9 -0
- package/lib/incident/text.js +43 -0
- package/package.json +20 -8
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export const FORBIDDEN_WORDS = /\b(attack|breach)\w*/i;
|
|
2
|
+
export function isScannerLike(a) {
|
|
3
|
+
return a.steady && (a.markers.length > 0 || a.emptyUaShare > 0.5);
|
|
4
|
+
}
|
|
5
|
+
export function classify(v) {
|
|
6
|
+
if (v.outcomes.identityLinks.length > 0)
|
|
7
|
+
return 'internal-testing';
|
|
8
|
+
if (v.actors.some(isScannerLike))
|
|
9
|
+
return 'automated-scan';
|
|
10
|
+
// Organic needs a spike with no isolated source AND nothing returned: content returned to
|
|
11
|
+
// unattributed traffic is not shown to be organic.
|
|
12
|
+
if (v.spikes.some((s) => s.isSpike) && v.actors.length === 0 && v.responses.returnedContent.length === 0 && notAssessedReasons(v).length === 0)
|
|
13
|
+
return 'organic';
|
|
14
|
+
return 'indeterminate';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Why a wave cannot be called no-evidence. No-evidence is allowed only when this is empty:
|
|
18
|
+
* the required logs are present, the empty-reply size came from a reference set, every
|
|
19
|
+
* controller call parsed, EVERY data-access call was joined to a reply size (any unjoined read
|
|
20
|
+
* could be the one that returned content), and every wave day has a baseline median.
|
|
21
|
+
* The join test uses data-access joins, not all joins: a joined auth reply says nothing about
|
|
22
|
+
* what a data read returned (stricter than `joined > 0`).
|
|
23
|
+
*/
|
|
24
|
+
export function notAssessedReasons(v) {
|
|
25
|
+
const out = [];
|
|
26
|
+
if (!v.requiredLogsPresent)
|
|
27
|
+
out.push('AuraRequest or Sites logs were not collected for every wave day');
|
|
28
|
+
if (v.responses.emptySizeInferred)
|
|
29
|
+
out.push('the empty-reply size could only be inferred from the replies under test');
|
|
30
|
+
const { dataAccessCalls, dataAccessJoined, unparsedCalls } = v.responses;
|
|
31
|
+
if (unparsedCalls > 0)
|
|
32
|
+
out.push(`${unparsedCalls} controller calls could not be parsed, so what they did is unknown`);
|
|
33
|
+
if (dataAccessJoined < dataAccessCalls) {
|
|
34
|
+
out.push(dataAccessJoined === 0
|
|
35
|
+
? `none of the ${dataAccessCalls} data-access calls could be joined to a reply size`
|
|
36
|
+
: `only ${dataAccessJoined} of ${dataAccessCalls} data-access calls could be joined to a reply size`);
|
|
37
|
+
}
|
|
38
|
+
const contextual = v.responses.returnedContent.length - decisiveReturned(v).length;
|
|
39
|
+
if (contextual > 0)
|
|
40
|
+
out.push(`${contextual} replies to other guest traffic returned content that cannot be ruled out as the actor's`);
|
|
41
|
+
if (v.outcomes.sharedEgressLogins > 0)
|
|
42
|
+
out.push(`${v.outcomes.sharedEgressLogins} successful logins from shared actor IPs could not be attributed`);
|
|
43
|
+
if (!v.spikes.every((s) => s.baselineMedian !== null))
|
|
44
|
+
out.push('no baseline day was collected, so wave-day volume could not be compared');
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returned content that decides the result. With an isolated actor, only the actor's replies
|
|
49
|
+
* count: a public site returns content to its ordinary visitors all the time. Without one,
|
|
50
|
+
* every guest reply counts, because nothing separates the actor from the visitors.
|
|
51
|
+
*/
|
|
52
|
+
export function decisiveReturned(v) {
|
|
53
|
+
const all = v.responses.returnedContent;
|
|
54
|
+
if (v.actors.length === 0)
|
|
55
|
+
return all;
|
|
56
|
+
// An attacker can read from addresses outside its block. Non-actor content is only context
|
|
57
|
+
// when its action is ordinary traffic: seen on baseline days from blocks absent on the wave days.
|
|
58
|
+
const normal = new Set(v.responses.baselineActions);
|
|
59
|
+
return all.filter((x) => x.actorId !== '' || !normal.has(x.action));
|
|
60
|
+
}
|
|
61
|
+
/** Precedence: access-gained > content-returned > not-assessed > no-evidence. */
|
|
62
|
+
export function outcomeOf(v) {
|
|
63
|
+
if (v.outcomes.successfulLogins > 0)
|
|
64
|
+
return 'access-gained';
|
|
65
|
+
if (decisiveReturned(v).length > 0)
|
|
66
|
+
return 'content-returned';
|
|
67
|
+
if (notAssessedReasons(v).length > 0)
|
|
68
|
+
return 'not-assessed';
|
|
69
|
+
return 'no-evidence';
|
|
70
|
+
}
|
|
71
|
+
/** Org-wide limits: they hold for the whole report, including one with zero waves. */
|
|
72
|
+
export function globalLimitsFor(m, followUp) {
|
|
73
|
+
const out = [
|
|
74
|
+
'Guest traffic carries no identity: activity by one person behind a shared proxy or NAT is only visible if it lifts that block well above its own history; a slow probe inside normal proxy volume cannot be seen in these logs.',
|
|
75
|
+
];
|
|
76
|
+
if (!m.detectorAvailable)
|
|
77
|
+
out.push('Guest User Anomaly events were not available; waves come from the supplied window only.');
|
|
78
|
+
if (m.audit.inaccessible)
|
|
79
|
+
out.push('The setup audit trail could not be read, so configuration changes are unknown.');
|
|
80
|
+
if (m.audit.truncatedWindows.length > 0)
|
|
81
|
+
out.push(`The setup audit trail was truncated for ${m.audit.truncatedWindows.length} window(s); some changes may be missing.`);
|
|
82
|
+
if (m.ipRangeFiles.length === 0)
|
|
83
|
+
out.push('Hosting provider not assessed: no --ip-ranges files were supplied.');
|
|
84
|
+
if (!m.limits.queryAllFiles)
|
|
85
|
+
out.push('The collecting user lacks Query All Files, so files owned by or shared with guest users were not checked.');
|
|
86
|
+
if (!m.limits.viewAllData)
|
|
87
|
+
out.push('The collecting user lacks View All Data, so record visibility checks are partial.');
|
|
88
|
+
for (const w of m.snapshotWarnings ?? [])
|
|
89
|
+
out.push(`Guest configuration was read only in part: ${w}`);
|
|
90
|
+
if (followUp?.truncated)
|
|
91
|
+
out.push('Login history for actor IPs was truncated at 10,000 rows per batch; some logins may be missing.');
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
/** Limits specific to one wave. Org-wide limits live in globalLimitsFor. */
|
|
95
|
+
export function limitsFor(v) {
|
|
96
|
+
const out = ['Response bodies are never logged by Salesforce, so the content of any reply is unknown; only its size is.'];
|
|
97
|
+
if (outcomeOf(v) === 'not-assessed')
|
|
98
|
+
out.push(`Not assessed: ${notAssessedReasons(v).join('; ')}.`);
|
|
99
|
+
if (!v.requiredLogsPresent)
|
|
100
|
+
out.push(`AuraRequest or Sites logs were not collected for ${v.wave.days.join(', ')}, so reply sizes could not be assessed.`);
|
|
101
|
+
if (v.actors.some((a) => !a.hostingAssessed && a.block.includes(':')))
|
|
102
|
+
out.push('Hosting provider not assessed for IPv6 addresses.');
|
|
103
|
+
if (v.actors.length === 0 && (v.spikes.some((s) => s.isSpike) || v.wave.eventIds.length > 0)) {
|
|
104
|
+
out.push('No single source block was isolated; reply sizes were assessed across all guest traffic on the wave days.');
|
|
105
|
+
}
|
|
106
|
+
if (v.responses.emptySizeInferred) {
|
|
107
|
+
out.push('The empty-reply size was inferred from the replies being tested; a scanner receiving identical non-empty replies would not be detected.');
|
|
108
|
+
}
|
|
109
|
+
if (v.outcomes.selfRegistrationsInActorWindow.length > 0)
|
|
110
|
+
out.push('Self-registrations occurred during the actor window; the audit trail records no IP, so they cannot be attributed.');
|
|
111
|
+
if (v.responses.unparsedCalls > 0)
|
|
112
|
+
out.push(`${v.responses.unparsedCalls} controller calls could not be parsed; their nature is unknown.`);
|
|
113
|
+
const contextual = v.responses.returnedContent.length - decisiveReturned(v).length;
|
|
114
|
+
if (contextual > 0)
|
|
115
|
+
out.push(`${contextual} replies to other guest traffic on the wave days were larger than empty; a public site returns content to its visitors, so these are listed in the evidence but do not decide the result.`);
|
|
116
|
+
if (v.responses.judgedAgainstFallback > 0 && v.responses.emptySize !== null) {
|
|
117
|
+
out.push(`${v.responses.judgedAgainstFallback} data-access calls were judged against the site-wide reference size of ${v.responses.emptySize} bytes because their action had no empty size of its own; smaller non-empty replies may have been missed.`);
|
|
118
|
+
}
|
|
119
|
+
if (v.responses.ambiguousCalls > 0)
|
|
120
|
+
out.push(`${v.responses.ambiguousCalls} calls shared a request id with other rows, so their reply sizes could not be told apart.`);
|
|
121
|
+
if (v.responses.unmatchedCalls > 0)
|
|
122
|
+
out.push(`${v.responses.unmatchedCalls} data-access or auth calls had no matching Sites row; their reply sizes are unknown.`);
|
|
123
|
+
const sharedIps = v.actors.flatMap((a) => a.sharedEgressIps);
|
|
124
|
+
if (sharedIps.length > 0) {
|
|
125
|
+
out.push(`${sharedIps.length} actor IP(s) are shared by many users (a proxy or NAT): ${v.outcomes.sharedEgressLogins} logins from them are not counted as access, and one person's activity behind them cannot be separated in these logs.`);
|
|
126
|
+
}
|
|
127
|
+
if (v.outcomes.identityLinks.length > 0 && v.actors.some(isScannerLike))
|
|
128
|
+
out.push('An identity link and scanner-like traffic were both seen; the link alone does not show the traffic was authorised.');
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
export function nextStepsFor(v, asymmetries, m) {
|
|
132
|
+
const steps = [];
|
|
133
|
+
const days = v.wave.days.join(', ');
|
|
134
|
+
for (const a of v.actors) {
|
|
135
|
+
if (isScannerLike(a))
|
|
136
|
+
steps.push(`Confirm with your security team whether an authorised test ran on ${days} from ${a.block}${a.hosting ? ` (${a.hosting})` : ''}. If none did, treat this as an incident.`);
|
|
137
|
+
}
|
|
138
|
+
const decisive = decisiveReturned(v).length;
|
|
139
|
+
if (decisive > 0)
|
|
140
|
+
steps.push(`Replay the ${decisive} data-access calls that returned content, as the guest user, to establish what they returned.`);
|
|
141
|
+
for (const l of v.outcomes.identityLinks)
|
|
142
|
+
steps.push(`Confirm the testing with ${l.userName} (${l.email}); deactivate that user if the test is complete.`);
|
|
143
|
+
for (const s of asymmetries)
|
|
144
|
+
steps.push(`Review whether the ${s.comparedChanges} guest-access changes made to ${s.comparedSite} between waves should also apply to ${s.site}.`);
|
|
145
|
+
if (!m.limits.queryAllFiles)
|
|
146
|
+
steps.push('Re-run collection as a user with Query All Files to check guest-owned files.');
|
|
147
|
+
return steps;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=verdict.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AnomalyEvent, AuditRow, BundleManifest, FollowUp, LoginDayCount, LogType } from './model.js';
|
|
2
|
+
export declare const BUNDLE_PATHS: {
|
|
3
|
+
readonly manifest: 'manifest.json';
|
|
4
|
+
readonly anomalies: 'anomalies.json';
|
|
5
|
+
readonly audit: 'org/audit.json';
|
|
6
|
+
readonly loginsByDay: 'org/logins-by-day.json';
|
|
7
|
+
readonly followUp: 'org/followup.json';
|
|
8
|
+
};
|
|
9
|
+
export declare function logPath(type: LogType, day: string): string;
|
|
10
|
+
export declare function sha256File(path: string): Promise<string>;
|
|
11
|
+
export declare function writeJsonAtomic(path: string, value: unknown): void;
|
|
12
|
+
export declare class BundleIntegrityError extends Error {
|
|
13
|
+
readonly files: string[];
|
|
14
|
+
constructor(files: string[]);
|
|
15
|
+
}
|
|
16
|
+
export declare class BundleIncompleteError extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
export interface Bundle {
|
|
20
|
+
dir: string;
|
|
21
|
+
manifest: BundleManifest;
|
|
22
|
+
manifestSha256: string;
|
|
23
|
+
anomalies: AnomalyEvent[];
|
|
24
|
+
audit: AuditRow[];
|
|
25
|
+
loginsByDay: LoginDayCount[];
|
|
26
|
+
followUp: FollowUp;
|
|
27
|
+
rows(type: LogType, day: string): AsyncIterable<Record<string, string>>;
|
|
28
|
+
hasLog(type: LogType, day: string): boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Loads a bundle after checking every file against the manifest's sha256. */
|
|
31
|
+
export declare function loadBundle(dir: string, opts?: {
|
|
32
|
+
allowIncomplete?: boolean;
|
|
33
|
+
}): Promise<Bundle>;
|
|
34
|
+
//# sourceMappingURL=bundleIo.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createReadStream, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { readCsvRecords } from './csv.js';
|
|
5
|
+
export const BUNDLE_PATHS = {
|
|
6
|
+
manifest: 'manifest.json',
|
|
7
|
+
anomalies: 'anomalies.json',
|
|
8
|
+
audit: 'org/audit.json',
|
|
9
|
+
loginsByDay: 'org/logins-by-day.json',
|
|
10
|
+
followUp: 'org/followup.json',
|
|
11
|
+
};
|
|
12
|
+
export function logPath(type, day) {
|
|
13
|
+
return `logs/${type}/${day}.csv`;
|
|
14
|
+
}
|
|
15
|
+
export async function sha256File(path) {
|
|
16
|
+
const h = createHash('sha256');
|
|
17
|
+
for await (const chunk of createReadStream(path))
|
|
18
|
+
h.update(chunk);
|
|
19
|
+
return h.digest('hex');
|
|
20
|
+
}
|
|
21
|
+
export function writeJsonAtomic(path, value) {
|
|
22
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
23
|
+
const part = `${path}.part`;
|
|
24
|
+
writeFileSync(part, JSON.stringify(value, null, 2));
|
|
25
|
+
renameSync(part, path);
|
|
26
|
+
}
|
|
27
|
+
export class BundleIntegrityError extends Error {
|
|
28
|
+
files;
|
|
29
|
+
constructor(files) {
|
|
30
|
+
super(`Bundle files missing or changed since collection: ${files.join(', ')}`);
|
|
31
|
+
this.files = files;
|
|
32
|
+
this.name = 'BundleIntegrityError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class BundleIncompleteError extends Error {
|
|
36
|
+
constructor() {
|
|
37
|
+
super('Bundle collection did not finish (follow-up or sealing failed). Re-run incident collect into the same directory to resume.');
|
|
38
|
+
this.name = 'BundleIncompleteError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Loads a bundle after checking every file against the manifest's sha256. */
|
|
42
|
+
export async function loadBundle(dir, opts = {}) {
|
|
43
|
+
const manifestPath = join(dir, BUNDLE_PATHS.manifest);
|
|
44
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
45
|
+
const bad = [];
|
|
46
|
+
for (const [rel, expected] of Object.entries(manifest.files)) {
|
|
47
|
+
const p = join(dir, rel);
|
|
48
|
+
if (!existsSync(p) || (await sha256File(p)) !== expected)
|
|
49
|
+
bad.push(rel);
|
|
50
|
+
}
|
|
51
|
+
if (bad.length > 0)
|
|
52
|
+
throw new BundleIntegrityError(bad);
|
|
53
|
+
if (manifest.complete !== true && !opts.allowIncomplete)
|
|
54
|
+
throw new BundleIncompleteError();
|
|
55
|
+
const json = (rel) => JSON.parse(readFileSync(join(dir, rel), 'utf-8'));
|
|
56
|
+
const collected = new Map(manifest.logs.filter((l) => l.status === 'collected' && l.file).map((l) => [`${l.type}|${l.day}`, l.file]));
|
|
57
|
+
return {
|
|
58
|
+
dir,
|
|
59
|
+
manifest,
|
|
60
|
+
manifestSha256: await sha256File(manifestPath),
|
|
61
|
+
anomalies: json(BUNDLE_PATHS.anomalies),
|
|
62
|
+
audit: json(BUNDLE_PATHS.audit),
|
|
63
|
+
loginsByDay: json(BUNDLE_PATHS.loginsByDay),
|
|
64
|
+
followUp: json(BUNDLE_PATHS.followUp),
|
|
65
|
+
hasLog: (type, day) => collected.has(`${type}|${day}`),
|
|
66
|
+
rows: (type, day) => {
|
|
67
|
+
const rel = collected.get(`${type}|${day}`);
|
|
68
|
+
if (!rel)
|
|
69
|
+
return (async function* () { })();
|
|
70
|
+
return readCsvRecords(join(dir, rel));
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=bundleIo.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RestClient, SoqlClient } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { BundleManifest } from '../model.js';
|
|
3
|
+
export interface CollectOptions {
|
|
4
|
+
sinceDays: number;
|
|
5
|
+
window?: string;
|
|
6
|
+
event?: string;
|
|
7
|
+
ipRangeFiles: string[];
|
|
8
|
+
outputDir: string;
|
|
9
|
+
warn: (m: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function defaultIncidentRoot(): string;
|
|
12
|
+
export declare function collectBundle(ctx: {
|
|
13
|
+
soql: SoqlClient;
|
|
14
|
+
rest: RestClient;
|
|
15
|
+
orgId: string;
|
|
16
|
+
orgName: string;
|
|
17
|
+
}, opts: CollectOptions): Promise<{
|
|
18
|
+
dir: string;
|
|
19
|
+
manifest: BundleManifest;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=collectBundle.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/incident/collect/collectBundle.ts
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
|
+
import { BUNDLE_PATHS, loadBundle, sha256File, writeJsonAtomic } from '../bundleIo.js';
|
|
6
|
+
import { findActors } from '../analyse/actors.js';
|
|
7
|
+
import { loadIpRanges, rangeFileName } from '../ipRanges.js';
|
|
8
|
+
import { buildWaves, parseDayWindow, readAnomalies, wavesFromWindow } from './discoverWaves.js';
|
|
9
|
+
import { fetchAuditTrail, loginsByDay, readLimits, snapshotGuests } from './snapshotOrg.js';
|
|
10
|
+
import { collectionDays, streamGuestLogs } from './streamGuestLogs.js';
|
|
11
|
+
import { followUpIps } from './followUp.js';
|
|
12
|
+
export function defaultIncidentRoot() {
|
|
13
|
+
return join(homedir(), '.sf', 'incidents');
|
|
14
|
+
}
|
|
15
|
+
const addDays = (d, n) => new Date(Date.parse(`${d}T00:00:00Z`) + n * 86_400_000).toISOString().slice(0, 10);
|
|
16
|
+
/**
|
|
17
|
+
* Resume: logs a previous run into the same directory already collected, whose file still
|
|
18
|
+
* matches the sha256 that run recorded. Anything else is downloaded again.
|
|
19
|
+
*/
|
|
20
|
+
async function priorLogs(dir, orgId, guestIds) {
|
|
21
|
+
const out = new Map();
|
|
22
|
+
const p = join(dir, BUNDLE_PATHS.manifest);
|
|
23
|
+
if (!existsSync(p))
|
|
24
|
+
return out;
|
|
25
|
+
const prev = JSON.parse(readFileSync(p, 'utf-8'));
|
|
26
|
+
const prevGuests = new Set(prev.guests.map((g) => g.id15));
|
|
27
|
+
if (prev.orgId !== orgId || prevGuests.size !== guestIds.size || [...guestIds].some((g) => !prevGuests.has(g)))
|
|
28
|
+
return out;
|
|
29
|
+
for (const l of prev.logs) {
|
|
30
|
+
if (l.status !== 'collected' || !l.file || !prev.files[l.file])
|
|
31
|
+
continue;
|
|
32
|
+
const full = join(dir, l.file);
|
|
33
|
+
if (existsSync(full) && (await sha256File(full)) === prev.files[l.file])
|
|
34
|
+
out.set(`${l.type}|${l.day}`, l);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
export async function collectBundle(ctx, opts) {
|
|
39
|
+
const dir = opts.outputDir;
|
|
40
|
+
mkdirSync(dir, { recursive: true });
|
|
41
|
+
const collectedAt = new Date().toISOString();
|
|
42
|
+
const anomalies = await readAnomalies(ctx.soql, opts.sinceDays);
|
|
43
|
+
if (!anomalies.available && !opts.window) {
|
|
44
|
+
throw new Error('Guest User Anomaly events are not available in this org (Threat Detection storage off or not licensed). Re-run with --window YYYY-MM-DD/YYYY-MM-DD.');
|
|
45
|
+
}
|
|
46
|
+
const { guests, warnings: snapshotWarnings } = await snapshotGuests(ctx.soql, anomalies.events.map((e) => e.userId15), opts.warn);
|
|
47
|
+
const waves = opts.window ? wavesFromWindow(parseDayWindow(opts.window), guests) : buildWaves(anomalies.events, guests, { event: opts.event, warn: opts.warn });
|
|
48
|
+
if (!opts.window && opts.event && waves.length === 0) {
|
|
49
|
+
throw new Error(`--event ${opts.event} matches no Guest User Anomaly wave in the last ${opts.sinceDays} days. Check the EventIdentifier or widen --since.`);
|
|
50
|
+
}
|
|
51
|
+
if (!opts.window && waves.length === 0)
|
|
52
|
+
opts.warn(`No anomaly waves found in the last ${opts.sinceDays} days; widen --since or pass --window.`);
|
|
53
|
+
// Window mode has no wave event ids, so match on the wave's guest and UTC day instead.
|
|
54
|
+
const events = anomalies.events.filter((e) => waves.some((w) => opts.window
|
|
55
|
+
? w.guestId15 === e.userId15 && w.days.includes(new Date(e.eventDate).toISOString().slice(0, 10))
|
|
56
|
+
: w.eventIds.includes(e.eventIdentifier)));
|
|
57
|
+
const days = collectionDays(waves);
|
|
58
|
+
const guestIds = new Set(guests.map((g) => g.id15));
|
|
59
|
+
const reuse = await priorLogs(dir, ctx.orgId, guestIds);
|
|
60
|
+
// Checkpoint: rewrite an incomplete manifest after every log so a killed run resumes from the
|
|
61
|
+
// logs already filtered instead of downloading everything again.
|
|
62
|
+
const soFar = [];
|
|
63
|
+
const hashes = {};
|
|
64
|
+
const checkpoint = async (c) => {
|
|
65
|
+
soFar.push(c);
|
|
66
|
+
if (c.status === 'collected' && c.file)
|
|
67
|
+
hashes[c.file] = await sha256File(join(dir, c.file));
|
|
68
|
+
const partial = {
|
|
69
|
+
version: 1, complete: false, orgId: ctx.orgId, orgName: ctx.orgName, collectedAt, sinceDays: opts.sinceDays,
|
|
70
|
+
detectorAvailable: anomalies.available, waves, guests, logs: soFar,
|
|
71
|
+
audit: { from: '', to: '', truncatedWindows: [], inaccessible: true },
|
|
72
|
+
limits: { queryAllFiles: false, viewAllData: false }, ipRangeFiles: [], files: { ...hashes },
|
|
73
|
+
};
|
|
74
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.manifest), partial);
|
|
75
|
+
};
|
|
76
|
+
let logs;
|
|
77
|
+
try {
|
|
78
|
+
logs = await streamGuestLogs(ctx, dir, days, guestIds, opts.warn, (t, d) => reuse.get(`${t}|${d}`), checkpoint);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
rmSync(join(dir, '.tmp'), { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
const limits = await readLimits(ctx.soql);
|
|
84
|
+
const auditFrom = waves.length ? addDays(waves.map((w) => w.days[0]).sort()[0], -7) : collectedAt.slice(0, 10);
|
|
85
|
+
const audit = await fetchAuditTrail(ctx.soql, auditFrom, collectedAt.slice(0, 10), guests);
|
|
86
|
+
const loginCounts = await loginsByDay(ctx.soql, days);
|
|
87
|
+
const ipRangeFiles = [];
|
|
88
|
+
for (const [index, f] of opts.ipRangeFiles.entries()) {
|
|
89
|
+
// Indexed, so two files with the same name (aws/ranges.txt, gcp/ranges.txt) cannot overwrite each other.
|
|
90
|
+
const rel = `ip-ranges/${index}-${basename(f)}`;
|
|
91
|
+
mkdirSync(join(dir, 'ip-ranges'), { recursive: true });
|
|
92
|
+
copyFileSync(f, join(dir, rel));
|
|
93
|
+
ipRangeFiles.push(rel);
|
|
94
|
+
}
|
|
95
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.anomalies), events);
|
|
96
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.audit), audit.rows);
|
|
97
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.loginsByDay), loginCounts);
|
|
98
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.followUp), { logins: [], users: [] });
|
|
99
|
+
const manifest = {
|
|
100
|
+
version: 1, complete: false, orgId: ctx.orgId, orgName: ctx.orgName, collectedAt, sinceDays: opts.sinceDays,
|
|
101
|
+
detectorAvailable: anomalies.available, waves, guests, logs, audit: audit.coverage, limits, ipRangeFiles, snapshotWarnings, files: {},
|
|
102
|
+
};
|
|
103
|
+
const seal = async (complete) => {
|
|
104
|
+
manifest.complete = complete;
|
|
105
|
+
const rels = [BUNDLE_PATHS.anomalies, BUNDLE_PATHS.audit, BUNDLE_PATHS.loginsByDay, BUNDLE_PATHS.followUp, ...ipRangeFiles,
|
|
106
|
+
...logs.filter((l) => l.status === 'collected' && l.file).map((l) => l.file)];
|
|
107
|
+
manifest.files = {};
|
|
108
|
+
for (const rel of rels) {
|
|
109
|
+
if (!existsSync(join(dir, rel)))
|
|
110
|
+
throw new Error(`Bundle file missing at seal: ${rel}`);
|
|
111
|
+
manifest.files[rel] = await sha256File(join(dir, rel));
|
|
112
|
+
}
|
|
113
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.manifest), manifest);
|
|
114
|
+
};
|
|
115
|
+
await seal(false);
|
|
116
|
+
// Second pass: actor IPs need the collected logs, and their logins need the org.
|
|
117
|
+
const draft = await loadBundle(dir, { allowIncomplete: true });
|
|
118
|
+
const ranges = ipRangeFiles.length ? loadIpRanges(ipRangeFiles.map((rel) => ({ name: rangeFileName(rel), text: readFileSync(join(dir, rel), 'utf-8') }))) : null;
|
|
119
|
+
const ips = new Set();
|
|
120
|
+
for (const w of waves)
|
|
121
|
+
for (const a of await findActors(draft, w, ranges))
|
|
122
|
+
a.ips.forEach((ip) => ips.add(ip));
|
|
123
|
+
for (const e of events)
|
|
124
|
+
if (e.sourceIp)
|
|
125
|
+
ips.add(e.sourceIp);
|
|
126
|
+
writeJsonAtomic(join(dir, BUNDLE_PATHS.followUp), await followUpIps(ctx.soql, [...ips]));
|
|
127
|
+
await seal(true);
|
|
128
|
+
return { dir, manifest };
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=collectBundle.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SoqlClient } from '@cclabsnz/sf-core';
|
|
2
|
+
import { type AnomalyEvent, type GuestUser, type Wave } from '../model.js';
|
|
3
|
+
/** GuestUserAnomalyEventStore rejects ORDER BY EventDate ASC, so sorting happens client-side. */
|
|
4
|
+
export declare function readAnomalies(soql: SoqlClient, sinceDays: number): Promise<{
|
|
5
|
+
available: boolean;
|
|
6
|
+
events: AnomalyEvent[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare function buildWaves(events: AnomalyEvent[], guests: GuestUser[], opts: {
|
|
9
|
+
event?: string;
|
|
10
|
+
warn?: (m: string) => void;
|
|
11
|
+
}): Wave[];
|
|
12
|
+
export declare function wavesFromWindow(days: string[], guests: GuestUser[]): Wave[];
|
|
13
|
+
export declare const MAX_WINDOW_DAYS = 31;
|
|
14
|
+
export declare function parseDayWindow(spec: string): string[];
|
|
15
|
+
//# sourceMappingURL=discoverWaves.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { degrades } from './orgErrors.js';
|
|
2
|
+
import { id15 } from '../model.js';
|
|
3
|
+
/** GuestUserAnomalyEventStore rejects ORDER BY EventDate ASC, so sorting happens client-side. */
|
|
4
|
+
export async function readAnomalies(soql, sinceDays) {
|
|
5
|
+
const days = Math.max(1, Math.min(365, Math.floor(sinceDays)));
|
|
6
|
+
try {
|
|
7
|
+
const rows = await soql.queryAll('SELECT EventIdentifier, EventDate, Score, Summary, Username, UserId, SourceIp, UserAgent, TotalControllerEvents, RequestedEntities, SoqlCommands ' +
|
|
8
|
+
`FROM GuestUserAnomalyEventStore WHERE EventDate = LAST_N_DAYS:${days}`);
|
|
9
|
+
const events = rows.map((r) => ({
|
|
10
|
+
eventIdentifier: r.EventIdentifier,
|
|
11
|
+
eventDate: r.EventDate,
|
|
12
|
+
score: Number(r.Score ?? 0),
|
|
13
|
+
userId15: id15(r.UserId) ?? '',
|
|
14
|
+
username: r.Username ?? '',
|
|
15
|
+
sourceIp: r.SourceIp ?? undefined,
|
|
16
|
+
userAgent: r.UserAgent ?? undefined,
|
|
17
|
+
summary: r.Summary ?? undefined,
|
|
18
|
+
totalControllerEvents: r.TotalControllerEvents ?? undefined,
|
|
19
|
+
requestedEntities: r.RequestedEntities ?? undefined,
|
|
20
|
+
soqlCommands: r.SoqlCommands ?? undefined,
|
|
21
|
+
})).sort((a, c) => a.eventDate.localeCompare(c.eventDate));
|
|
22
|
+
return { available: true, events };
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
if (!degrades(e))
|
|
26
|
+
throw e;
|
|
27
|
+
return { available: false, events: [] };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const dayOf = (iso) => new Date(iso).toISOString().slice(0, 10);
|
|
31
|
+
const nextDay = (d) => new Date(Date.parse(`${d}T00:00:00Z`) + 86_400_000).toISOString().slice(0, 10);
|
|
32
|
+
const siteFor = (g, fallback) => g?.siteNames[0] ?? g?.username ?? fallback;
|
|
33
|
+
export function buildWaves(events, guests, opts) {
|
|
34
|
+
const byGuest = new Map();
|
|
35
|
+
for (const e of [...events].sort((a, c) => a.eventDate.localeCompare(c.eventDate))) {
|
|
36
|
+
if (!e.userId15) {
|
|
37
|
+
opts.warn?.(`Skipping Guest User Anomaly event ${e.eventIdentifier}: it names no user, so its rows cannot be attributed to a guest.`);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const list = byGuest.get(e.userId15) ?? [];
|
|
41
|
+
list.push(e);
|
|
42
|
+
byGuest.set(e.userId15, list);
|
|
43
|
+
}
|
|
44
|
+
const raw = [];
|
|
45
|
+
for (const [guestId15, list] of byGuest) {
|
|
46
|
+
const g = guests.find((x) => x.id15 === guestId15);
|
|
47
|
+
let cur;
|
|
48
|
+
for (const e of list) {
|
|
49
|
+
const d = dayOf(e.eventDate);
|
|
50
|
+
const last = cur?.days[cur.days.length - 1];
|
|
51
|
+
if (cur && (d === last || d === nextDay(last))) {
|
|
52
|
+
if (d !== last)
|
|
53
|
+
cur.days.push(d);
|
|
54
|
+
cur.eventIds.push(e.eventIdentifier);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
cur = { guestId15, site: siteFor(g, e.username), days: [d], eventIds: [e.eventIdentifier] };
|
|
58
|
+
raw.push(cur);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return raw
|
|
63
|
+
.filter((w) => !opts.event || w.eventIds.includes(opts.event))
|
|
64
|
+
.sort((a, c) => a.days[0].localeCompare(c.days[0]) || a.site.localeCompare(c.site))
|
|
65
|
+
.map((w, i) => ({ id: `W${i + 1}`, ...w }));
|
|
66
|
+
}
|
|
67
|
+
export function wavesFromWindow(days, guests) {
|
|
68
|
+
return guests.filter((g) => g.active).map((g, i) => ({ id: `W${i + 1}`, guestId15: g.id15, site: siteFor(g, g.username), days, eventIds: [] }));
|
|
69
|
+
}
|
|
70
|
+
export const MAX_WINDOW_DAYS = 31;
|
|
71
|
+
const realDay = (d) => { const t = Date.parse(`${d}T00:00:00Z`); return !Number.isNaN(t) && new Date(t).toISOString().slice(0, 10) === d; };
|
|
72
|
+
export function parseDayWindow(spec) {
|
|
73
|
+
const m = /^(\d{4}-\d{2}-\d{2})\/(?:(\d{4}-\d{2}-\d{2})|P(\d+)D)$/.exec(spec.trim());
|
|
74
|
+
if (!m)
|
|
75
|
+
throw new Error(`--window must be YYYY-MM-DD/YYYY-MM-DD or YYYY-MM-DD/PnD, got "${spec}"`);
|
|
76
|
+
const start = m[1];
|
|
77
|
+
if (!realDay(start) || (m[2] && !realDay(m[2])))
|
|
78
|
+
throw new Error(`--window contains a date that does not exist (YYYY-MM-DD expected), got "${spec}"`);
|
|
79
|
+
const spanDays = m[2] ? (Date.parse(`${m[2]}T00:00:00Z`) - Date.parse(`${start}T00:00:00Z`)) / 86_400_000 + 1 : Number(m[3]);
|
|
80
|
+
if (spanDays < 1)
|
|
81
|
+
throw new Error(`--window end must not be before its start, got "${spec}"`);
|
|
82
|
+
if (spanDays > MAX_WINDOW_DAYS)
|
|
83
|
+
throw new Error(`--window spans ${spanDays} days; the limit is ${MAX_WINDOW_DAYS}. Split it into several runs.`);
|
|
84
|
+
const end = m[2] ?? new Date(Date.parse(`${start}T00:00:00Z`) + (spanDays - 1) * 86_400_000).toISOString().slice(0, 10);
|
|
85
|
+
const out = [];
|
|
86
|
+
for (let d = start; d <= end; d = nextDay(d))
|
|
87
|
+
out.push(d);
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=discoverWaves.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SoqlClient } from '@cclabsnz/sf-core';
|
|
2
|
+
import { type FollowUp } from '../model.js';
|
|
3
|
+
/**
|
|
4
|
+
* The forms LoginHistory.SourceIp may hold for one address. IPv4 has one; IPv6 is queried as
|
|
5
|
+
* compressed, fully expanded, and zero-padded, because an exact-match IN list misses any form
|
|
6
|
+
* it does not name. Matching afterwards is on normaliseIp, so all forms compare equal.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ipForms(raw: string): string[];
|
|
9
|
+
/**
|
|
10
|
+
* LoginHistory for actor IPs with no date bound: the identifying login in the motivating
|
|
11
|
+
* case came five days after the wave. SourceIp does not support LIKE, hence an IN list.
|
|
12
|
+
*/
|
|
13
|
+
export declare function followUpIps(soql: SoqlClient, ips: string[]): Promise<FollowUp>;
|
|
14
|
+
//# sourceMappingURL=followUp.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DEFAULTS, id15 } from '../model.js';
|
|
2
|
+
import { normaliseIp } from '../analyse/actors.js';
|
|
3
|
+
const CHUNK = 100;
|
|
4
|
+
/** Addresses per LoginHistory query (each IPv6 address contributes up to three literals). */
|
|
5
|
+
const IP_BATCH = 30;
|
|
6
|
+
const cleanIp = (ip) => (/^[0-9A-Fa-f:.]+$/.test(ip) ? ip : null);
|
|
7
|
+
/**
|
|
8
|
+
* The forms LoginHistory.SourceIp may hold for one address. IPv4 has one; IPv6 is queried as
|
|
9
|
+
* compressed, fully expanded, and zero-padded, because an exact-match IN list misses any form
|
|
10
|
+
* it does not name. Matching afterwards is on normaliseIp, so all forms compare equal.
|
|
11
|
+
*/
|
|
12
|
+
export function ipForms(raw) {
|
|
13
|
+
const compressed = normaliseIp(raw);
|
|
14
|
+
if (!compressed.includes(':') || compressed.includes('.'))
|
|
15
|
+
return [compressed];
|
|
16
|
+
const [head, tail] = compressed.split('::');
|
|
17
|
+
const left = head ? head.split(':') : [];
|
|
18
|
+
const right = tail !== undefined && tail !== '' ? tail.split(':') : [];
|
|
19
|
+
const groups = tail === undefined ? left : [...left, ...Array(8 - left.length - right.length).fill('0'), ...right];
|
|
20
|
+
if (groups.length !== 8)
|
|
21
|
+
return [compressed];
|
|
22
|
+
return [...new Set([compressed, groups.join(':'), groups.map((g) => g.padStart(4, '0')).join(':')])];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* LoginHistory for actor IPs with no date bound: the identifying login in the motivating
|
|
26
|
+
* case came five days after the wave. SourceIp does not support LIKE, hence an IN list.
|
|
27
|
+
*/
|
|
28
|
+
export async function followUpIps(soql, ips) {
|
|
29
|
+
// Each address with all its textual forms, kept together so a re-query covers every form.
|
|
30
|
+
const perIp = [...new Map(ips.map((ip) => [normaliseIp(ip), ipForms(ip).map(cleanIp).filter((x) => x !== null)])).values()]
|
|
31
|
+
.filter((forms) => forms.length > 0);
|
|
32
|
+
const logins = [];
|
|
33
|
+
let truncated = false;
|
|
34
|
+
const query = (forms) => soql.queryAll(`SELECT LoginTime, UserId, SourceIp, Status, LoginUrl, Browser FROM LoginHistory WHERE SourceIp IN (${forms.map((ip) => `'${ip}'`).join(',')})`);
|
|
35
|
+
const keep = (rows) => { for (const r of rows)
|
|
36
|
+
logins.push({ loginTime: r.LoginTime, userId15: id15(r.UserId), sourceIp: r.SourceIp, status: r.Status, loginUrl: r.LoginUrl, browser: r.Browser }); };
|
|
37
|
+
// Batches keep the client's API budget small. A batch that hits the row cap may have had one
|
|
38
|
+
// busy address crowd the others out, so only then is it re-queried one address at a time.
|
|
39
|
+
for (let i = 0; i < perIp.length; i += IP_BATCH) {
|
|
40
|
+
const batch = perIp.slice(i, i + IP_BATCH);
|
|
41
|
+
const rows = await query(batch.flat());
|
|
42
|
+
if (rows.length < DEFAULTS.auditPageCap) {
|
|
43
|
+
keep(rows);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
for (const forms of batch) {
|
|
47
|
+
const single = await query(forms);
|
|
48
|
+
if (single.length >= DEFAULTS.auditPageCap)
|
|
49
|
+
truncated = true;
|
|
50
|
+
keep(single);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const userIds = [...new Set(logins.map((l) => l.userId15))];
|
|
54
|
+
const users = [];
|
|
55
|
+
for (let i = 0; i < userIds.length; i += CHUNK) {
|
|
56
|
+
const list = userIds.slice(i, i + CHUNK).map((u) => `'${u.replace(/[^A-Za-z0-9]/g, '')}'`).join(',');
|
|
57
|
+
const rows = await soql.queryAll(`SELECT Id, Name, Email, CreatedDate, CreatedById, Profile.Name, IsActive FROM User WHERE Id IN (${list})`);
|
|
58
|
+
for (const u of rows)
|
|
59
|
+
users.push({ id15: id15(u.Id), name: u.Name, email: u.Email, createdDate: u.CreatedDate, createdById15: id15(u.CreatedById), profileName: u.Profile?.Name ?? '', isActive: u.IsActive });
|
|
60
|
+
}
|
|
61
|
+
logins.sort((a, c) => a.loginTime.localeCompare(c.loginTime));
|
|
62
|
+
return truncated ? { logins, users, truncated } : { logins, users };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=followUp.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type OrgErrorKind = 'unavailable' | 'no-permission' | 'error';
|
|
2
|
+
/** Only 'unavailable' and 'no-permission' may degrade collection; everything else must abort it. */
|
|
3
|
+
export declare function classifyOrgError(e: unknown): OrgErrorKind;
|
|
4
|
+
export declare const degrades: (e: unknown) => boolean;
|
|
5
|
+
//# sourceMappingURL=orgErrors.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Only 'unavailable' and 'no-permission' may degrade collection; everything else must abort it. */
|
|
2
|
+
export function classifyOrgError(e) {
|
|
3
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
4
|
+
if (/INVALID_TYPE|is not supported|not supported/i.test(m))
|
|
5
|
+
return 'unavailable';
|
|
6
|
+
if (/INSUFFICIENT_ACCESS|HTTP 403/i.test(m))
|
|
7
|
+
return 'no-permission';
|
|
8
|
+
return 'error';
|
|
9
|
+
}
|
|
10
|
+
export const degrades = (e) => classifyOrgError(e) !== 'error';
|
|
11
|
+
//# sourceMappingURL=orgErrors.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SoqlClient } from '@cclabsnz/sf-core';
|
|
2
|
+
import { type AuditCoverage, type AuditRow, type GuestUser, type LoginDayCount, type RunningUserLimits } from '../model.js';
|
|
3
|
+
/** Active guests plus any user an anomaly event named, so a since-deactivated guest's rows survive filtering. */
|
|
4
|
+
export declare function snapshotGuests(soql: SoqlClient, extraIds: string[], warn?: (m: string) => void): Promise<{
|
|
5
|
+
guests: GuestUser[];
|
|
6
|
+
warnings: string[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare function readLimits(soql: SoqlClient): Promise<RunningUserLimits>;
|
|
9
|
+
/**
|
|
10
|
+
* SetupAuditTrail cannot filter on Section and queryAll stops at 10,000 rows, so the range is
|
|
11
|
+
* walked in 4-day windows and any window that comes back full is split in half until it fits.
|
|
12
|
+
*/
|
|
13
|
+
export declare function fetchAuditTrail(soql: SoqlClient, from: string, to: string, guests: GuestUser[]): Promise<{
|
|
14
|
+
rows: AuditRow[];
|
|
15
|
+
coverage: AuditCoverage;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function loginsByDay(soql: SoqlClient, days: string[]): Promise<LoginDayCount[]>;
|
|
18
|
+
//# sourceMappingURL=snapshotOrg.d.ts.map
|