Personal Telegram developer console for GitHub
feat: allowlist safe workspace audit metadata
davoodmehraban89 committed
Oct 3, 2026 at 13:29 UTC
fee3ab3f68648ca688a5644443785c9489605ee9
1 file changed
+47
-4
src/core/router.js
+47
-4
@@ -1,3 +1,41 @@
1
+const AUDIT_METADATA_KEYS = Object.freeze(new Set([
2
+ 'repoId',
3
+ 'workspaceId',
4
+ 'intentId',
5
+ 'path',
6
+ 'contentDigest',
7
+ 'commitMessageDigest',
8
+ 'baseHeadSha',
9
+ 'targetBranch',
10
+ 'commitSha',
11
+ 'branch',
12
+ 'idempotent'
13
+]));
14
+
15
+function sanitizeAuditMetadata(value) {
16
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
17
+ const safe = {};
18
+ for (const [key, raw] of Object.entries(value)) {
19
+ if (!AUDIT_METADATA_KEYS.has(key)) continue;
20
+ if (typeof raw === 'number' && Number.isSafeInteger(raw)) {
21
+ safe[key] = raw;
22
+ continue;
23
+ }
24
+ if (typeof raw === 'boolean') {
25
+ safe[key] = raw;
26
+ continue;
27
+ }
28
+ if (typeof raw === 'string') safe[key] = raw.slice(0, 240);
29
+ }
30
+ return safe;
31
+}
32
+
33
+function withoutAuditMetadata(result) {
34
+ if (!result || typeof result !== 'object' || Array.isArray(result) || !Object.hasOwn(result, 'audit')) return result;
35
+ const { audit, ...publicResult } = result;
36
+ return publicResult;
37
+}
38
+
39
export class PluginRouter {
40
constructor({ registry, policy, audit } = {}) {
41
if (!registry) throw new Error('PluginRouter registry is required');
@@ -38,6 +76,7 @@ export class PluginRouter {
76
isOwner: context.isOwner === true,
77
approved: context.approved === true
78
});
79
+ const routeAudit = sanitizeAuditMetadata(route.audit);
80
81
this.audit.log({
82
event: 'action_attempt',
@@ -47,7 +86,8 @@ export class PluginRouter {
86
outcome: decision.allowed
87
? 'allowed'
88
: (decision.requiresApproval ? 'approval_required' : 'denied'),
50
- reason: decision.reason
89
+ reason: decision.reason,
90
+ ...routeAudit
91
});
92
93
if (!decision.allowed) {
@@ -74,9 +114,11 @@ export class PluginRouter {
114
pluginId,
115
actionId,
116
risk: decision.risk,
77
- outcome: 'success'
117
+ outcome: 'success',
118
+ ...routeAudit,
119
+ ...sanitizeAuditMetadata(result?.audit)
120
});
79
- return result;
121
+ return withoutAuditMetadata(result);
122
} catch (error) {
123
this.audit.log({
124
event: 'action_result',
@@ -84,7 +126,8 @@ export class PluginRouter {
126
actionId,
127
risk: decision.risk,
128
outcome: 'error',
87
- error: error?.message || 'Unknown plugin error'
129
+ error: error?.message || 'Unknown plugin error',
130
+ ...routeAudit
131
});
132
throw error;
133
}