Skip to content
Back to skills

Br Audit Enrichment

ASecurity

Enrich better-route 0.5.0 audit events with safe operational metadata. Use when adding AuditEnricherMiddleware, AuditMiddleware context fields, auth user/provider metadata, hashed Idempotency-Key logging, resource/action audit fields, or reviewing sensitive REST write routes that need traceable but redacted audit events.

  • 22 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 5, 2026
ai-agentsphp

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 5, 2026

npx -y skills add Lonsdale201/wp-agent-skills --skill br-audit-enrichment --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Br Audit Enrichment?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Br Audit Enrichment
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lonsdale201-br-audit-enrichment/badge)](https://www.skillsdirectory.com/skills/lonsdale201-br-audit-enrichment)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: br-audit-enrichment
description: Enrich better-route 0.5.0 audit events with safe operational metadata. Use when adding AuditEnricherMiddleware, AuditMiddleware context fields, auth user/provider metadata, hashed Idempotency-Key logging, resource/action audit fields, or reviewing sensitive REST write routes that need traceable but redacted audit events.
---

# better-route: Audit enrichment

Use audit enrichment when the standard route/method/status/duration event is not enough to debug or review sensitive operations.

## Pattern

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

$router->middleware([
    $jwt,
    new AuditEnricherMiddleware([
        'resource' => 'account',
        'action' => 'update',
    ]),
    new AuditMiddleware($logger),
]);
```

`AuditEnricherMiddleware` writes safe fields to `RequestContext::$attributes['audit']`. `AuditMiddleware` merges that array into success/error events.

## Fields

The enricher can add:

- `authProvider`
- `authUserId`
- `authSubject`
- `idempotencyKey` as `sha1(raw-key)`, not the raw header
- optional `clientIp`
- static fields passed by the route, group, or integration

## Rules

- Run auth before audit enrichment if auth fields are needed.
- Hash idempotency keys; do not log raw keys.
- Keep payment tokens, card data, secrets, cookies, bearer tokens, and full request bodies out of audit events.
- Add stable domain fields such as `resource`, `action`, and public-safe resource IDs.
- Use a private logger destination. Client error responses stay scrubbed; audit logs can be more useful but still need redaction.

## Source refs

- `libraries/better-route/src/Middleware/Audit/AuditEnricherMiddleware.php`
- `libraries/better-route/src/Middleware/Audit/AuditMiddleware.php`
- `libraries/better-route/src/Observability/AuditEventFactory.php`
- `libraries/better-route/tests/BuiltInMiddlewareTest.php`

Files in this skill

  • SKILL.md1.9 KB
  • agents/openai.yaml219 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…