Br audit enrichment

From Lonsdale201/wp-agent-skills · View interactive version

Br audit enrichment is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Configure Better Route 1.1 audit events and safe enrichment. Use when logging route outcomes, authenticated identity, hashed idempotency keys, trusted client IPs, domain action metadata, or ensuring telemetry failures cannot change API behavior.

How to use this skill

Skill file

Better Route audit enrichment

Run authentication first, enrichment second, and audit logging around the downstream handler.

use BetterRoute\Middleware\Audit\AuditEnricherMiddleware;
use BetterRoute\Middleware\Audit\AuditMiddleware;

$router->middleware([
    $auth,
    new AuditEnricherMiddleware(
        staticFields: ['resource' => 'account', 'action' => 'update'],
        clientIpResolver: $trustedProxyResolver,
        includeClientIp: true
    ),
    new AuditMiddleware($logger),
]);

AuditEnricherMiddleware writes to the context audit attribute. It copies the normalized authentication provider, user ID, and subject; hashes an Idempotency-Key with SHA-1 for correlation; optionally resolves client IP; and merges reviewed static fields. Existing fields are retained, while later enrichment values with the same name win.

AuditMiddleware logs success or error with route, method, status, duration, correlation metadata, and enrichment. Logger exceptions are swallowed deliberately: observability is best-effort and must not change a successful response or mask the application exception already in flight.

Rules

Test successful responses, ApiException, unexpected exceptions, logger failure, missing authentication context, and spoofed forwarded headers.

Source references: src/Middleware/Audit/AuditEnricherMiddleware.php, src/Middleware/Audit/AuditMiddleware.php, src/Observability/AuditEventFactory.php.

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.