# Br Audit Enrichment

> 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.

- **Type:** Skill
- **Install:** `agentstack add skill-lonsdale201-wp-agent-skills-br-audit-enrichment`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Lonsdale201](https://agentstack.voostack.com/s/lonsdale201)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Lonsdale201](https://github.com/Lonsdale201)
- **Source:** https://github.com/Lonsdale201/wp-agent-skills/tree/main/better-route/br-audit-enrichment

## Install

```sh
agentstack add skill-lonsdale201-wp-agent-skills-br-audit-enrichment
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 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`

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Lonsdale201](https://github.com/Lonsdale201)
- **Source:** [Lonsdale201/wp-agent-skills](https://github.com/Lonsdale201/wp-agent-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-lonsdale201-wp-agent-skills-br-audit-enrichment
- Seller: https://agentstack.voostack.com/s/lonsdale201
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
