local-auth-audit.mjs
sha256:c2dbf04d56308f3bbf2d06e6d2eb022b8948b1e827195fe525a44e5e18d5f9c0
feat(auth): Phase B Connect cloud agent (RFC 8628) + Hermes…
Human
minor
⚠ breaking
11 days ago
| 1 | /** |
| 2 | * Phase 8 P1b-b — local auth audit events (§7.3). No secrets in logs. |
| 3 | */ |
| 4 | |
| 5 | import fs from 'fs'; |
| 6 | import path from 'path'; |
| 7 | |
| 8 | /** |
| 9 | * Append a local-auth audit event to data_dir/hub_audit.log. |
| 10 | * @param {string} dataDir |
| 11 | * @param {string} eventName |
| 12 | * @param {Record<string, unknown>} fields |
| 13 | */ |
| 14 | export function appendLocalAuthAudit(dataDir, eventName, fields) { |
| 15 | if (!dataDir) return; |
| 16 | const logPath = path.join(dataDir, 'hub_audit.log'); |
| 17 | const dir = path.dirname(logPath); |
| 18 | if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); |
| 19 | const line = |
| 20 | JSON.stringify({ |
| 21 | ts: new Date().toISOString(), |
| 22 | event: eventName, |
| 23 | ...fields, |
| 24 | }) + '\n'; |
| 25 | fs.appendFileSync(logPath, line, 'utf8'); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param {import('express').Request} req |
| 30 | * @returns {{ ip: string, ua: string }} |
| 31 | */ |
| 32 | export function requestAuditMeta(req) { |
| 33 | const ip = |
| 34 | (typeof req.ip === 'string' && req.ip) || |
| 35 | (typeof req.headers['x-forwarded-for'] === 'string' |
| 36 | ? req.headers['x-forwarded-for'].split(',')[0].trim() |
| 37 | : '') || |
| 38 | 'unknown'; |
| 39 | const ua = String(req.headers['user-agent'] || '').slice(0, 256); |
| 40 | return { ip, ua }; |
| 41 | } |
File History
1 commit
sha256:93bcf8f9bd56d8c5b9339f4ec73b9ebd66571398d56262d38eedc2cfa9db9882
fix(test): align Band B landing assertion with desktop MCP …
Human
11 days ago