@nocobase/audit 0.0.0-stage → 0.1.0-beta.1
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/LICENSE.txt +127 -0
- package/README.md +71 -2
- package/dist/config.d.ts +35 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +91 -0
- package/dist/config.js.map +1 -0
- package/dist/file-output.d.ts +26 -0
- package/dist/file-output.d.ts.map +1 -0
- package/dist/file-output.js +269 -0
- package/dist/file-output.js.map +1 -0
- package/dist/file-transport.d.ts +5 -0
- package/dist/file-transport.d.ts.map +1 -0
- package/dist/file-transport.js +88 -0
- package/dist/file-transport.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/ip.d.ts +4 -0
- package/dist/ip.d.ts.map +1 -0
- package/dist/ip.js +36 -0
- package/dist/ip.js.map +1 -0
- package/dist/locales/de-DE.d.ts +4 -0
- package/dist/locales/de-DE.d.ts.map +1 -0
- package/dist/locales/de-DE.js +11 -0
- package/dist/locales/de-DE.js.map +1 -0
- package/dist/locales/en-US.d.ts +13 -0
- package/dist/locales/en-US.d.ts.map +1 -0
- package/dist/locales/en-US.js +11 -0
- package/dist/locales/en-US.js.map +1 -0
- package/dist/locales/es-ES.d.ts +4 -0
- package/dist/locales/es-ES.d.ts.map +1 -0
- package/dist/locales/es-ES.js +11 -0
- package/dist/locales/es-ES.js.map +1 -0
- package/dist/locales/fr-FR.d.ts +4 -0
- package/dist/locales/fr-FR.d.ts.map +1 -0
- package/dist/locales/fr-FR.js +11 -0
- package/dist/locales/fr-FR.js.map +1 -0
- package/dist/locales/id-ID.d.ts +4 -0
- package/dist/locales/id-ID.d.ts.map +1 -0
- package/dist/locales/id-ID.js +11 -0
- package/dist/locales/id-ID.js.map +1 -0
- package/dist/locales/index.d.ts +4 -0
- package/dist/locales/index.d.ts.map +1 -0
- package/dist/locales/index.js +16 -0
- package/dist/locales/index.js.map +1 -0
- package/dist/locales/ja-JP.d.ts +4 -0
- package/dist/locales/ja-JP.d.ts.map +1 -0
- package/dist/locales/ja-JP.js +11 -0
- package/dist/locales/ja-JP.js.map +1 -0
- package/dist/locales/ko-KR.d.ts +4 -0
- package/dist/locales/ko-KR.d.ts.map +1 -0
- package/dist/locales/ko-KR.js +11 -0
- package/dist/locales/ko-KR.js.map +1 -0
- package/dist/locales/pt-BR.d.ts +4 -0
- package/dist/locales/pt-BR.d.ts.map +1 -0
- package/dist/locales/pt-BR.js +11 -0
- package/dist/locales/pt-BR.js.map +1 -0
- package/dist/locales/ru-RU.d.ts +4 -0
- package/dist/locales/ru-RU.d.ts.map +1 -0
- package/dist/locales/ru-RU.js +11 -0
- package/dist/locales/ru-RU.js.map +1 -0
- package/dist/locales/vi-VN.d.ts +4 -0
- package/dist/locales/vi-VN.d.ts.map +1 -0
- package/dist/locales/vi-VN.js +11 -0
- package/dist/locales/vi-VN.js.map +1 -0
- package/dist/locales/zh-CN.d.ts +4 -0
- package/dist/locales/zh-CN.d.ts.map +1 -0
- package/dist/locales/zh-CN.js +11 -0
- package/dist/locales/zh-CN.js.map +1 -0
- package/dist/locales/zh-TW.d.ts +4 -0
- package/dist/locales/zh-TW.d.ts.map +1 -0
- package/dist/locales/zh-TW.js +11 -0
- package/dist/locales/zh-TW.js.map +1 -0
- package/dist/redact.d.ts +13 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +167 -0
- package/dist/redact.js.map +1 -0
- package/dist/repository.d.ts +4 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +22 -0
- package/dist/repository.js.map +1 -0
- package/dist/request.d.ts +76 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +298 -0
- package/dist/request.js.map +1 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +81 -0
- package/dist/runtime.js.map +1 -0
- package/dist/service.d.ts +51 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +139 -0
- package/dist/service.js.map +1 -0
- package/package.json +61 -3
package/dist/request.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { findTargetHandler } from 'hono/utils/handler';
|
|
2
|
+
import { parseAuditAddress } from './ip.js';
|
|
3
|
+
import { auditSnapshot, copyAuditRedactRules, readAuditBody, } from './redact.js';
|
|
4
|
+
import { repositoryAuditOptions } from './repository.js';
|
|
5
|
+
const auditDeclaration = Symbol('describeAudit');
|
|
6
|
+
const writes = new Set(['POST', 'PATCH', 'PUT', 'DELETE']);
|
|
7
|
+
export function describeAudit(declaration) {
|
|
8
|
+
const resolve = typeof declaration === 'function'
|
|
9
|
+
? (context) => {
|
|
10
|
+
const resolved = declaration(context);
|
|
11
|
+
return resolved === undefined ? undefined : copyDeclaration(resolved);
|
|
12
|
+
}
|
|
13
|
+
: staticResolver(declaration);
|
|
14
|
+
const middleware = async (_context, next) => next();
|
|
15
|
+
Object.defineProperty(middleware, auditDeclaration, { value: resolve });
|
|
16
|
+
return middleware;
|
|
17
|
+
}
|
|
18
|
+
function staticResolver(declaration) {
|
|
19
|
+
const captured = copyDeclaration(declaration);
|
|
20
|
+
return () => captured;
|
|
21
|
+
}
|
|
22
|
+
function copyDeclaration(declaration) {
|
|
23
|
+
if (declaration === false)
|
|
24
|
+
return false;
|
|
25
|
+
const { redact, operationName } = declaration;
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
...declaration,
|
|
28
|
+
redact: redact === undefined ? undefined : copyAuditRedactRules(redact),
|
|
29
|
+
operationName: typeof operationName === 'object'
|
|
30
|
+
? Object.freeze({ ...operationName })
|
|
31
|
+
: operationName,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function routeAudit(context, host, autoDetect, report) {
|
|
35
|
+
const routes = context.req.matchedRoutes;
|
|
36
|
+
const route = routes.find((item, index) => index >= context.req.routeIndex && item.method !== 'ALL');
|
|
37
|
+
if (!route)
|
|
38
|
+
return undefined;
|
|
39
|
+
let declaration;
|
|
40
|
+
for (const [index, candidate] of routes.entries()) {
|
|
41
|
+
if (candidate.method !== route.method || candidate.path !== route.path)
|
|
42
|
+
continue;
|
|
43
|
+
const resolve = findTargetHandler(candidate.handler)[auditDeclaration];
|
|
44
|
+
if (!resolve)
|
|
45
|
+
continue;
|
|
46
|
+
const previous = context.req.routeIndex;
|
|
47
|
+
try {
|
|
48
|
+
context.req.routeIndex = index;
|
|
49
|
+
const resolved = resolve(context);
|
|
50
|
+
if (resolved === false)
|
|
51
|
+
return false;
|
|
52
|
+
if (resolved)
|
|
53
|
+
declaration = { ...resolved, ...declaration };
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
report();
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
context.req.routeIndex = previous;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const spec = host.declaredRouteOf(context);
|
|
64
|
+
if (spec?.repository) {
|
|
65
|
+
const { exposure, collection, action } = spec.repository;
|
|
66
|
+
const repository = repositoryAuditOptions(exposure, collection, action);
|
|
67
|
+
if (repository === false)
|
|
68
|
+
return false;
|
|
69
|
+
declaration = { ...repository, ...declaration };
|
|
70
|
+
}
|
|
71
|
+
if (!declaration && (!autoDetect || !writes.has(context.req.method)))
|
|
72
|
+
return undefined;
|
|
73
|
+
if (!declaration && (spec?.hide || !spec?.operationId))
|
|
74
|
+
return undefined;
|
|
75
|
+
const operationId = typeof spec?.operationId === 'string'
|
|
76
|
+
? spec.operationId
|
|
77
|
+
: spec?.operationId?.(route);
|
|
78
|
+
return {
|
|
79
|
+
action: declaration?.action ??
|
|
80
|
+
host.declaredRouteActionOf(context) ??
|
|
81
|
+
operationId ??
|
|
82
|
+
`${context.req.method} ${route.path}`,
|
|
83
|
+
resource: declaration?.resource ?? spec?.tags?.[0] ?? route.path,
|
|
84
|
+
summary: spec?.summary?.trim(),
|
|
85
|
+
options: declaration ?? {},
|
|
86
|
+
context,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Read a scalar record key from a bounded execution result. */
|
|
90
|
+
export function auditRecordKey(value, ...path) {
|
|
91
|
+
for (const segment of path) {
|
|
92
|
+
if (!value || typeof value !== 'object' || !Object.hasOwn(value, segment))
|
|
93
|
+
return undefined;
|
|
94
|
+
value = Reflect.get(value, segment);
|
|
95
|
+
}
|
|
96
|
+
return typeof value === 'string' || typeof value === 'number'
|
|
97
|
+
? value
|
|
98
|
+
: undefined;
|
|
99
|
+
}
|
|
100
|
+
function targetsOf(value) {
|
|
101
|
+
if (!value)
|
|
102
|
+
return undefined;
|
|
103
|
+
return 'collection' in value ? { targets: [value] } : value;
|
|
104
|
+
}
|
|
105
|
+
function withRouteParams(context, resolve) {
|
|
106
|
+
const previous = context.req.routeIndex;
|
|
107
|
+
const route = context.req.matchedRoutes.findIndex((item, index) => index >= previous && item.method !== 'ALL');
|
|
108
|
+
if (route < 0)
|
|
109
|
+
return resolve();
|
|
110
|
+
try {
|
|
111
|
+
context.req.routeIndex = route;
|
|
112
|
+
return resolve();
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
context.req.routeIndex = previous;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function clientIp(context, peer, proxies, ipAddressHeaders) {
|
|
119
|
+
if (!peer)
|
|
120
|
+
return undefined;
|
|
121
|
+
const parsed = parseAuditAddress(peer);
|
|
122
|
+
if (!parsed || !proxies.check(parsed.address, parsed.family))
|
|
123
|
+
return peer;
|
|
124
|
+
for (const name of ipAddressHeaders) {
|
|
125
|
+
const forwarded = context.req.header(name)?.split(',');
|
|
126
|
+
if (!forwarded)
|
|
127
|
+
continue;
|
|
128
|
+
for (const value of forwarded.reverse()) {
|
|
129
|
+
const upstream = parseAuditAddress(value.trim());
|
|
130
|
+
if (!upstream || upstream.port)
|
|
131
|
+
break;
|
|
132
|
+
if (!proxies.check(upstream.address, upstream.family))
|
|
133
|
+
return upstream.address;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return peer;
|
|
137
|
+
}
|
|
138
|
+
function actorOf(context, service) {
|
|
139
|
+
const sessionContext = context;
|
|
140
|
+
const auth = sessionContext.get('auth');
|
|
141
|
+
if (auth?.credential?.type === 'run')
|
|
142
|
+
return {
|
|
143
|
+
type: 'agentRun',
|
|
144
|
+
userId: auth.user.id,
|
|
145
|
+
runId: auth.credential.id,
|
|
146
|
+
};
|
|
147
|
+
const resolved = service.resolveActor(context);
|
|
148
|
+
if (resolved)
|
|
149
|
+
return resolved;
|
|
150
|
+
const userId = auth?.user.id ?? sessionContext.get('authHttpIdentity')?.userId;
|
|
151
|
+
return userId ? { type: 'user', userId } : { type: 'anonymous' };
|
|
152
|
+
}
|
|
153
|
+
export function auditMiddleware(options) {
|
|
154
|
+
const { host, autoDetect, captureBody, report } = options;
|
|
155
|
+
const globalRedact = options.redact && copyAuditRedactRules(options.redact);
|
|
156
|
+
return async (context, next) => {
|
|
157
|
+
const started = performance.now();
|
|
158
|
+
let route;
|
|
159
|
+
let before;
|
|
160
|
+
try {
|
|
161
|
+
route = routeAudit(context, host, autoDetect, report);
|
|
162
|
+
if (route === undefined) {
|
|
163
|
+
const forwarded = host.matchForwardedRoute(context);
|
|
164
|
+
if (forwarded)
|
|
165
|
+
route = routeAudit(forwarded, host, autoDetect, report);
|
|
166
|
+
}
|
|
167
|
+
if (route) {
|
|
168
|
+
const matched = route;
|
|
169
|
+
before = targetsOf(withRouteParams(matched.context, () => matched.options.target?.(matched.context)));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
options.report();
|
|
174
|
+
}
|
|
175
|
+
if (!route)
|
|
176
|
+
return next();
|
|
177
|
+
const occurredAt = new Date().toISOString();
|
|
178
|
+
const declaration = route.options;
|
|
179
|
+
const capture = captureBody !== false &&
|
|
180
|
+
declaration.captureBody !== false &&
|
|
181
|
+
(captureBody === true || declaration.captureBody === true);
|
|
182
|
+
const body = capture ? readAuditBody(context.req.raw) : undefined;
|
|
183
|
+
const { resolveTargets } = declaration;
|
|
184
|
+
if (resolveTargets)
|
|
185
|
+
host.enableExecutionResult(context);
|
|
186
|
+
let actual = context;
|
|
187
|
+
if (route.context !== context)
|
|
188
|
+
host.observeForwardedContext(context, (child) => {
|
|
189
|
+
actual = child;
|
|
190
|
+
if (resolveTargets)
|
|
191
|
+
host.enableExecutionResult(child);
|
|
192
|
+
});
|
|
193
|
+
let thrown = false;
|
|
194
|
+
try {
|
|
195
|
+
await next();
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
thrown = true;
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
const status = thrown ? 500 : context.res.status;
|
|
203
|
+
const durationMs = Math.round(performance.now() - started);
|
|
204
|
+
const success = status >= 200 && status < 400;
|
|
205
|
+
const replay = success && context.res.headers.get('Idempotency-Replayed') === 'true';
|
|
206
|
+
if (!replay)
|
|
207
|
+
try {
|
|
208
|
+
const failedAuthentication = !success && declaration.authenticationAttempt;
|
|
209
|
+
const request = failedAuthentication ? undefined : await body;
|
|
210
|
+
const response = capture && success ? await readAuditBody(context.res) : undefined;
|
|
211
|
+
let targets = before;
|
|
212
|
+
if (success && resolveTargets) {
|
|
213
|
+
try {
|
|
214
|
+
targets =
|
|
215
|
+
targetsOf(resolveTargets({
|
|
216
|
+
status,
|
|
217
|
+
request,
|
|
218
|
+
response,
|
|
219
|
+
value: host.executionResultOf(actual),
|
|
220
|
+
}, actual)) ?? before;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
report('Could not resolve audit targets.');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const redact = declaration.redact && globalRedact
|
|
227
|
+
? {
|
|
228
|
+
fields: [
|
|
229
|
+
...(globalRedact.fields ?? []),
|
|
230
|
+
...(declaration.redact.fields ?? []),
|
|
231
|
+
],
|
|
232
|
+
paths: [
|
|
233
|
+
...(globalRedact.paths ?? []),
|
|
234
|
+
...(declaration.redact.paths ?? []),
|
|
235
|
+
],
|
|
236
|
+
}
|
|
237
|
+
: (declaration.redact ?? globalRedact);
|
|
238
|
+
const snapshot = (value) => auditSnapshot(value, redact);
|
|
239
|
+
const safeTarget = ({ collection, key, }) => ({
|
|
240
|
+
collection,
|
|
241
|
+
key: failedAuthentication ? undefined : snapshot(key),
|
|
242
|
+
});
|
|
243
|
+
const operation = declaration.operationName;
|
|
244
|
+
const operationName = (typeof operation === 'string'
|
|
245
|
+
? operation.trim()
|
|
246
|
+
: operation?.defaultValue?.trim()) ||
|
|
247
|
+
route.summary ||
|
|
248
|
+
route.action;
|
|
249
|
+
const operationNameI18n = operation && typeof operation === 'object'
|
|
250
|
+
? { ns: operation.ns, key: operation.key }
|
|
251
|
+
: undefined;
|
|
252
|
+
const roles = context
|
|
253
|
+
.get('authz')
|
|
254
|
+
?.resolvedGrantSources?.() ?? [];
|
|
255
|
+
let actor = failedAuthentication
|
|
256
|
+
? { type: 'anonymous' }
|
|
257
|
+
: actorOf(context, options.service);
|
|
258
|
+
if (actor.type === 'anonymous' &&
|
|
259
|
+
actual !== context &&
|
|
260
|
+
!failedAuthentication)
|
|
261
|
+
actor = actorOf(actual, options.service);
|
|
262
|
+
await options.service.record({
|
|
263
|
+
requestId: host.getRequestId(context),
|
|
264
|
+
action: route.action,
|
|
265
|
+
operationName,
|
|
266
|
+
operationNameI18n,
|
|
267
|
+
resource: route.resource,
|
|
268
|
+
actor,
|
|
269
|
+
roles: failedAuthentication
|
|
270
|
+
? []
|
|
271
|
+
: [
|
|
272
|
+
...new Set(roles
|
|
273
|
+
.filter(({ plugin }) => plugin === 'permission-sets')
|
|
274
|
+
.map(({ id }) => id)),
|
|
275
|
+
].slice(0, 256),
|
|
276
|
+
source: targets?.source && safeTarget(targets.source),
|
|
277
|
+
targets: targets?.targets.slice(0, 64).map(safeTarget) ?? [],
|
|
278
|
+
ip: clientIp(context, host.getClientAddress(context), options.proxies, options.ipAddressHeaders),
|
|
279
|
+
userAgent: context.req.header('user-agent')?.slice(0, 512),
|
|
280
|
+
outcome: success
|
|
281
|
+
? 'success'
|
|
282
|
+
: !failedAuthentication && (status === 401 || status === 403)
|
|
283
|
+
? 'denied'
|
|
284
|
+
: 'failure',
|
|
285
|
+
status,
|
|
286
|
+
durationMs,
|
|
287
|
+
occurredAt,
|
|
288
|
+
request: capture && !failedAuthentication ? snapshot(request) : undefined,
|
|
289
|
+
response: capture && success ? snapshot(response) : undefined,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
options.report();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,aAAa,GAEd,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAwCzD,MAAM,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAIjD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAwC3D,MAAM,UAAU,aAAa,CAC3B,WAAmC;IAEnC,MAAM,OAAO,GACX,OAAO,WAAW,KAAK,UAAU;QAC/B,CAAC,CAAC,CAAC,OAAgB,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;YACtC,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,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U;wBACV,UAAU;wBACV,OAAO,EACL,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;wBAClE,QAAQ,EAAE,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;qBAC9D,CAAC,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,CAAC,MAAM,EAAE,CAAC;gBACnB,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Application, ApplicationConfig } from '@nocobase/app-server/application';
|
|
2
|
+
import { ServiceProvider } from '@nocobase/service-provider';
|
|
3
|
+
/** Installs request auditing in an application assembled with app-server. */
|
|
4
|
+
export declare class AuditProvider<TConfig extends ApplicationConfig = ApplicationConfig> extends ServiceProvider<Application<TConfig>> {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
private readonly coordinator;
|
|
7
|
+
constructor(app: Application<TConfig>);
|
|
8
|
+
register(): void;
|
|
9
|
+
shutdown(): Promise<void>;
|
|
10
|
+
private logger;
|
|
11
|
+
private report;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAClB,MAAM,kCAAkC,CAAC;AAc1C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAU7D,6EAA6E;AAC7E,qBAAa,aAAa,CACxB,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,CACrD,SAAQ,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,SAAgB,IAAI,EAAE,MAAM,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;gBAE5B,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC;IAyD5B,QAAQ,IAAI,IAAI;IAMV,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/C,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,MAAM;CAQf"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { i18nToken } from '@nocobase/app-server/i18n';
|
|
2
|
+
import { loggingToken } from '@nocobase/app-server/logging';
|
|
3
|
+
import { apiExecutionResultOf, declaredRouteActionOf, declaredRouteOf, enableApiExecutionResult, getClientAddress, getRequestId, matchForwardedApiRoute, observeForwardedApiContext, repositoryEndpointOf, } from '@nocobase/app-server/router';
|
|
4
|
+
import { ServiceProvider } from '@nocobase/service-provider';
|
|
5
|
+
import { auditDefaults } from './config.js';
|
|
6
|
+
import { createTrustedAuditProxies } from './ip.js';
|
|
7
|
+
import locales from './locales/index.js';
|
|
8
|
+
import { auditMiddleware } from './request.js';
|
|
9
|
+
import { AuditCoordinator, auditServiceToken } from './service.js';
|
|
10
|
+
const namespace = '@nocobase/audit';
|
|
11
|
+
/** Installs request auditing in an application assembled with app-server. */
|
|
12
|
+
export class AuditProvider extends ServiceProvider {
|
|
13
|
+
name = namespace;
|
|
14
|
+
coordinator;
|
|
15
|
+
constructor(app) {
|
|
16
|
+
super(app);
|
|
17
|
+
this.coordinator = new AuditCoordinator((message, destination) => this.report(message, destination));
|
|
18
|
+
// Providers can register drivers in either register() or boot(). Introduce
|
|
19
|
+
// the service during composition so audit can shut down before those providers.
|
|
20
|
+
app.container.instance(auditServiceToken, this.coordinator);
|
|
21
|
+
const { config, paths } = app;
|
|
22
|
+
app.addApiMiddleware({
|
|
23
|
+
name: namespace,
|
|
24
|
+
register: async (router) => {
|
|
25
|
+
const audit = config.get('audit');
|
|
26
|
+
if (!(await this.coordinator.start(audit, paths)))
|
|
27
|
+
return;
|
|
28
|
+
const proxies = createTrustedAuditProxies(config.get('auth.advanced.ipAddress.trustedProxies'), (message) => {
|
|
29
|
+
const logger = this.logger();
|
|
30
|
+
if (logger)
|
|
31
|
+
logger.warn(message);
|
|
32
|
+
else
|
|
33
|
+
console.warn(message);
|
|
34
|
+
});
|
|
35
|
+
router.use('*', auditMiddleware({
|
|
36
|
+
host: {
|
|
37
|
+
declaredRouteOf(context) {
|
|
38
|
+
const spec = declaredRouteOf(context);
|
|
39
|
+
return (spec && { ...spec, repository: repositoryEndpointOf(spec) });
|
|
40
|
+
},
|
|
41
|
+
declaredRouteActionOf,
|
|
42
|
+
matchForwardedRoute: (context) => matchForwardedApiRoute(context, app.forwardedApiRoutes.routers),
|
|
43
|
+
observeForwardedContext: observeForwardedApiContext,
|
|
44
|
+
enableExecutionResult: enableApiExecutionResult,
|
|
45
|
+
executionResultOf: apiExecutionResultOf,
|
|
46
|
+
getClientAddress,
|
|
47
|
+
getRequestId,
|
|
48
|
+
},
|
|
49
|
+
service: this.coordinator,
|
|
50
|
+
autoDetect: audit?.autoDetect ?? auditDefaults.autoDetect,
|
|
51
|
+
captureBody: audit?.captureBody,
|
|
52
|
+
redact: audit?.redact,
|
|
53
|
+
proxies,
|
|
54
|
+
ipAddressHeaders: config.get('auth.advanced.ipAddress.ipAddressHeaders') ?? ['x-forwarded-for'],
|
|
55
|
+
report: (message = 'Could not collect audit event.') => this.report(message),
|
|
56
|
+
}));
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
register() {
|
|
61
|
+
this.app.container
|
|
62
|
+
.resolveIfCreated(i18nToken)
|
|
63
|
+
?.registerNamespace(namespace, locales);
|
|
64
|
+
}
|
|
65
|
+
async shutdown() {
|
|
66
|
+
await this.coordinator.close();
|
|
67
|
+
}
|
|
68
|
+
logger() {
|
|
69
|
+
return this.app.container
|
|
70
|
+
.resolveIfCreated(loggingToken)
|
|
71
|
+
?.getLogger('audit');
|
|
72
|
+
}
|
|
73
|
+
report(message, destination) {
|
|
74
|
+
const logger = this.logger();
|
|
75
|
+
if (logger)
|
|
76
|
+
logger.error({ destination }, message);
|
|
77
|
+
else
|
|
78
|
+
console.error(destination ? `${message} Destination: ${destination}.` : message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAoB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC,6EAA6E;AAC7E,MAAM,OAAO,aAEX,SAAQ,eAAqC;IAC7B,IAAI,GAAW,SAAS,CAAC;IACxB,WAAW,CAAmB;IAE/C,YAAmB,GAAyB;QAC1C,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAgB,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAC/D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAClC,CAAC;QACF,2EAA2E;QAC3E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|
|
1
|
+
import { type ServiceToken } from '@nocobase/service-provider';
|
|
2
|
+
import type { Context } from 'hono';
|
|
3
|
+
import { type AuditConfig } from './config.js';
|
|
4
|
+
import type { AuditActor, AuditEvent } from './index.js';
|
|
5
|
+
export interface AuditTransportContext {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly paths: {
|
|
8
|
+
readonly storageDir: string;
|
|
9
|
+
};
|
|
10
|
+
/** Report a destination warning without including event contents. */
|
|
11
|
+
readonly report?: (message: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface AuditTransport {
|
|
14
|
+
/** Honor cancellation and settle the write when it is finished. */
|
|
15
|
+
write(event: AuditEvent, options: {
|
|
16
|
+
readonly signal: AbortSignal;
|
|
17
|
+
}): void | Promise<void>;
|
|
18
|
+
close?(): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface AuditTransportDriver {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
createTransport(options: Readonly<Record<string, unknown>>, context: AuditTransportContext): AuditTransport;
|
|
23
|
+
}
|
|
24
|
+
/** Classify a session already selected by the authentication middleware. */
|
|
25
|
+
export type AuditActorResolver = (context: Context) => AuditActor | undefined;
|
|
26
|
+
export interface AuditService {
|
|
27
|
+
registerDriver(driver: AuditTransportDriver): void;
|
|
28
|
+
registerActorResolver(resolver: AuditActorResolver): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const auditServiceToken: ServiceToken<AuditService>;
|
|
31
|
+
type Report = (message: string, destination?: string) => void;
|
|
32
|
+
export declare class AuditCoordinator implements AuditService {
|
|
33
|
+
private readonly report;
|
|
34
|
+
private readonly fileDriver;
|
|
35
|
+
private readonly drivers;
|
|
36
|
+
private readonly actorResolvers;
|
|
37
|
+
private readonly destinations;
|
|
38
|
+
private started;
|
|
39
|
+
private closed;
|
|
40
|
+
constructor(report: Report);
|
|
41
|
+
registerDriver(driver: AuditTransportDriver): void;
|
|
42
|
+
registerActorResolver(resolver: AuditActorResolver): void;
|
|
43
|
+
resolveActor(context: Context): AuditActor | undefined;
|
|
44
|
+
start(config: AuditConfig | undefined, paths: AuditTransportContext['paths']): Promise<boolean>;
|
|
45
|
+
record(event: AuditEvent): Promise<void>;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
private deliver;
|
|
48
|
+
private withDeadline;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,KAAK,CACH,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;KAAE,GACxC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,eAAe,CACb,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM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,OAAO;YA0BP,YAAY;CAmB3B"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createServiceToken, } from '@nocobase/service-provider';
|
|
2
|
+
import { auditDefaults, isAuditName, validateAuditConfig, } from './config.js';
|
|
3
|
+
import { createFileAuditDriver } from './file-transport.js';
|
|
4
|
+
export const auditServiceToken = createServiceToken('@nocobase/audit');
|
|
5
|
+
const deliveryTimeout = 1_000;
|
|
6
|
+
const maxPendingPerDestination = 64;
|
|
7
|
+
export class AuditCoordinator {
|
|
8
|
+
report;
|
|
9
|
+
fileDriver = createFileAuditDriver();
|
|
10
|
+
drivers = new Map([
|
|
11
|
+
[this.fileDriver.name, this.fileDriver],
|
|
12
|
+
]);
|
|
13
|
+
actorResolvers = [];
|
|
14
|
+
destinations = [];
|
|
15
|
+
started = false;
|
|
16
|
+
closed = false;
|
|
17
|
+
constructor(report) {
|
|
18
|
+
this.report = report;
|
|
19
|
+
}
|
|
20
|
+
registerDriver(driver) {
|
|
21
|
+
if (this.started)
|
|
22
|
+
throw new Error('Register audit drivers before routes are installed.');
|
|
23
|
+
if (!isAuditName(driver.name) ||
|
|
24
|
+
typeof driver.createTransport !== 'function')
|
|
25
|
+
throw new Error('An audit driver requires a valid name and a factory.');
|
|
26
|
+
if (this.drivers.has(driver.name))
|
|
27
|
+
throw new Error(`Audit driver "${driver.name}" is already registered.`);
|
|
28
|
+
this.drivers.set(driver.name, driver);
|
|
29
|
+
}
|
|
30
|
+
registerActorResolver(resolver) {
|
|
31
|
+
this.actorResolvers.push(resolver);
|
|
32
|
+
}
|
|
33
|
+
resolveActor(context) {
|
|
34
|
+
for (const resolve of this.actorResolvers) {
|
|
35
|
+
const actor = resolve(context);
|
|
36
|
+
if (actor)
|
|
37
|
+
return actor;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
async start(config, paths) {
|
|
42
|
+
this.started = true;
|
|
43
|
+
if (config === undefined)
|
|
44
|
+
return false;
|
|
45
|
+
validateAuditConfig(config, (path, message) => {
|
|
46
|
+
throw new Error(`audit${path ? `.${path}` : ''} ${message}`);
|
|
47
|
+
});
|
|
48
|
+
if (!(config.enabled ?? auditDefaults.enabled))
|
|
49
|
+
return false;
|
|
50
|
+
const definitions = Object.entries(config.transports ?? {});
|
|
51
|
+
for (const [name, definition] of definitions) {
|
|
52
|
+
if (!this.drivers.has(definition.driver))
|
|
53
|
+
throw new Error(`Audit destination "${name}" uses unregistered driver "${definition.driver}".`);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
for (const [name, definition] of definitions) {
|
|
57
|
+
const { driver, options = {} } = definition;
|
|
58
|
+
try {
|
|
59
|
+
const transport = this.drivers.get(driver).createTransport(options, {
|
|
60
|
+
name,
|
|
61
|
+
paths,
|
|
62
|
+
report: (message) => this.report(message, name),
|
|
63
|
+
});
|
|
64
|
+
if (!transport || typeof transport.write !== 'function')
|
|
65
|
+
throw new Error();
|
|
66
|
+
this.destinations.push({ name, transport, pending: new Map() });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
throw new Error(`Invalid configuration for audit destination "${name}" (driver "${driver}").`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
await this.close();
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
await this.fileDriver.prepare();
|
|
78
|
+
return this.destinations.length > 0;
|
|
79
|
+
}
|
|
80
|
+
async record(event) {
|
|
81
|
+
if (this.closed)
|
|
82
|
+
return;
|
|
83
|
+
await Promise.all(this.destinations.map((destination) => this.deliver(destination, event)));
|
|
84
|
+
}
|
|
85
|
+
async close() {
|
|
86
|
+
if (this.closed)
|
|
87
|
+
return;
|
|
88
|
+
this.closed = true;
|
|
89
|
+
await Promise.all(this.destinations.map(async ({ name, transport, pending }) => {
|
|
90
|
+
for (const controller of pending.keys())
|
|
91
|
+
controller.abort();
|
|
92
|
+
await this.withDeadline(Promise.allSettled(pending.values()), () => this.report('Audit writes did not settle during shutdown.', name));
|
|
93
|
+
await this.withDeadline(Promise.resolve()
|
|
94
|
+
.then(() => transport.close?.())
|
|
95
|
+
.catch(() => {
|
|
96
|
+
this.report('Could not close audit destination.', name);
|
|
97
|
+
}), () => this.report('Audit destination shutdown timed out.', name));
|
|
98
|
+
}));
|
|
99
|
+
this.destinations.length = 0;
|
|
100
|
+
}
|
|
101
|
+
async deliver(destination, event) {
|
|
102
|
+
const { transport, pending, name } = destination;
|
|
103
|
+
if (pending.size >= maxPendingPerDestination) {
|
|
104
|
+
this.report('Audit destination has too many pending writes.', name);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const controller = new AbortController();
|
|
108
|
+
const write = Promise.resolve()
|
|
109
|
+
.then(() => transport.write(structuredClone(event), { signal: controller.signal }))
|
|
110
|
+
.catch(() => {
|
|
111
|
+
if (!controller.signal.aborted)
|
|
112
|
+
this.report('Could not write audit event.', name);
|
|
113
|
+
})
|
|
114
|
+
.finally(() => pending.delete(controller));
|
|
115
|
+
pending.set(controller, write);
|
|
116
|
+
await this.withDeadline(write, () => {
|
|
117
|
+
controller.abort();
|
|
118
|
+
this.report('Audit destination write timed out.', name);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async withDeadline(operation, onTimeout) {
|
|
122
|
+
let timer;
|
|
123
|
+
try {
|
|
124
|
+
await Promise.race([
|
|
125
|
+
operation,
|
|
126
|
+
new Promise((resolve) => {
|
|
127
|
+
timer = setTimeout(() => {
|
|
128
|
+
resolve();
|
|
129
|
+
onTimeout();
|
|
130
|
+
}, deliveryTimeout);
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
clearTimeout(timer);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service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