Adds an append-only audit-events collection that records who changed which document or global and when, plus sign-ins, failed logins and password resets. Actors include users, API keys, MCP agents and system calls. Only changed field paths are stored, not values. It requires Payload 3.90 or later, React 19 and the companion guard plugin for access policies, and supports Postgres, SQLite and MongoDB.
Audit log for Payload CMS: document, global and auth changes, with API keys and AI agents (MCP) as actors, and CSV / NDJSON export
Installation
npm i @focus-reactive/payload-plugin-audit-log37
Stars
5
Forks
33
Open Issues
Today
Last Updated
58
Weekly Downloads
v2.0.1
npm Version
311.0 KB
Unpacked Size
1
Dependencies
37+22 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 37 |
| Dec 4, 2026 | 37 |
| Dec 3, 2026 | 37 |
| Dec 2, 2026 | 37 |
| Dec 1, 2026 | 36 |
| Nov 30, 2026 | 35 |
| Nov 29, 2026 | 35 |
| Nov 28, 2026 | 34 |
| Nov 27, 2026 | 34 |
| Nov 26, 2026 | 34 |
| Nov 25, 2026 | 34 |
| Nov 24, 2026 | 34 |
| Nov 23, 2026 | 34 |
| Nov 22, 2026 | 34 |
| Nov 21, 2026 | 34 |
| Nov 20, 2026 | 33 |
| Nov 19, 2026 | 32 |
| Nov 18, 2026 | 32 |
| Nov 17, 2026 | 32 |
| Nov 16, 2026 | 32 |
| Nov 15, 2026 | 32 |
| Nov 14, 2026 | 32 |
| Nov 13, 2026 | 32 |
| Nov 12, 2026 | 32 |
| Nov 11, 2026 | 32 |
| Nov 10, 2026 | 32 |
| Nov 9, 2026 | 31 |
| Nov 8, 2026 | 31 |
| Nov 7, 2026 | 31 |
| Nov 6, 2026 | 31 |
| Nov 5, 2026 | 31 |
| Nov 4, 2026 | 30 |
| Nov 3, 2026 | 30 |
| Nov 2, 2026 | 30 |
| Nov 1, 2026 | 30 |
| Oct 31, 2026 | 30 |
| Oct 30, 2026 | 30 |
| Oct 29, 2026 | 30 |
| Oct 28, 2026 | 30 |
| Oct 27, 2026 | 30 |
| Oct 26, 2026 | 30 |
| Oct 25, 2026 | 30 |
| Oct 24, 2026 | 29 |
| Oct 23, 2026 | 29 |
| Oct 22, 2026 | 29 |
| Oct 21, 2026 | 29 |
| Oct 20, 2026 | 29 |
| Oct 19, 2026 | 29 |
| Oct 18, 2026 | 29 |
| Oct 17, 2026 | 27 |
| Oct 16, 2026 | 26 |
| Oct 15, 2026 | 26 |
| Oct 14, 2026 | 26 |
| Oct 13, 2026 | 25 |
| Oct 12, 2026 | 25 |
| Oct 11, 2026 | 25 |
| Oct 10, 2026 | 25 |
| Oct 9, 2026 | 25 |
| Oct 8, 2026 | 25 |
| Oct 7, 2026 | 25 |
| Oct 6, 2026 | 24 |
| Oct 5, 2026 | 24 |
| Oct 4, 2026 | 24 |
| Oct 3, 2026 | 23 |
| Oct 2, 2026 | 22 |
| Oct 1, 2026 | 22 |
| Sep 30, 2026 | 20 |
| Sep 29, 2026 | 20 |
| Sep 28, 2026 | 20 |
| Sep 27, 2026 | 20 |
| Sep 26, 2026 | 19 |
| Sep 25, 2026 | 18 |
| Sep 24, 2026 | 18 |
| Sep 23, 2026 | 18 |
| Sep 22, 2026 | 18 |
| Sep 21, 2026 | 18 |
| Sep 20, 2026 | 18 |
| Sep 19, 2026 | 18 |
| Sep 18, 2026 | 18 |
| Sep 17, 2026 | 18 |
| Sep 16, 2026 | 18 |
| Sep 15, 2026 | 18 |
| Sep 14, 2026 | 18 |
| Sep 13, 2026 | 17 |
| Sep 12, 2026 | 17 |
| Sep 11, 2026 | 17 |
| Sep 10, 2026 | 16 |
| Sep 9, 2026 | 16 |
| Sep 8, 2026 | 16 |
| Sep 7, 2026 | 15 |
| Sep 6, 2026 | 15 |
Shared by 15 plugins in focusreactive/payload-plugins.
77+77 since Nov 24
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 77 |
| Dec 4, 2026 | 87 |
| Dec 3, 2026 | 295 |
| Dec 2, 2026 | 493 |
| Dec 1, 2026 | 485 |
| Nov 30, 2026 | 481 |
| Nov 29, 2026 | 464 |
| Nov 28, 2026 | 443 |
| Nov 27, 2026 | 425 |
| Nov 26, 2026 | 210 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-audit-log)<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-audit-log"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-audit-log.svg" alt="Payload Directory"></a>README
Audit log for Payload CMS v3: an append-only collection of who changed which document or global and when, plus sign-ins, API keys and AI agents, with CSV / NDJSON export. A change records the paths of the fields that changed, not their values; What an event stores lists everything else it keeps.

| Filter by actor, action or target | Changed field paths, IP and User-Agent |
|---|---|
![]() | ![]() |
Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to integrate the plugin into an existing Payload project.
I want to add an audit log to my Payload CMS v3 project using
@focus-reactive/payload-plugin-audit-log. Follow these steps in order, and stop to ask me where a step says so.
## Rules you must follow
- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles may read the log and which may export it.
- Write every policy entry by hand in `src/access.policy.ts`, and grant each capability and each
collection right explicitly to the roles I name. Nothing is open by default.
- When the boot or a request fails, fix the cause or ask me. Never use `anyone`, a looser gate,
`overrideAccess` or a removed or disabled check to make an error go away.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the plugin's collection.
## How it works
The plugin adds an append-only collection "audit-events" (admin group "Settings") that records document
and global changes (create, update, autosave, delete, publish, unpublish, version restore), sign-ins,
sign-outs, failed sign-ins and password resets. Each event stores the actor (user, API key, MCP agent,
system, anonymous), the target, the paths of changed fields, IP and User-Agent. Nobody can create, edit or
delete events over REST, GraphQL, the admin panel or the Local API; only the plugin writes them.
Who may read events is the `read` rule of "audit-events" in the project's access policy.
The plugin declares one capability that the project grants in the same policy:
- `export`: download the events the caller may read as CSV or NDJSON (GET /api/audit-log/export).
## Step 1: install
pnpm add @focus-reactive/payload-plugin-audit-log @focus-reactive/payload-plugin-guard
Check that `payload` and `@payloadcms/ui` are 3.90 or later; if they are not, upgrade them first.
React 19 is required. Postgres, SQLite and MongoDB are supported.
## Step 2: ask me about roles
Look at the auth collection named in `admin.user` and the roles it has. Ask me:
"Which roles may read the audit log?" and "Which roles may export it?"
Wait for my answers. Write each answer as a gate or filter in the policy file in step 3.
A role that may export must also be able to read: an export holds only the events its caller may read.
## Step 3: the access policy file
Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:
collections: {
'audit-events': { create: nobody, read: <the rule from my first answer>, update: nobody, delete: nobody },
},
plugins: {
'audit-log': { export: <the gate from my second answer> },
},
Only if I want old events deleted (retention, step 4): Payload then adds its jobs collection and a
global for scheduled jobs, so also add
collections: { 'payload-jobs': 'payload-default' }
globals: { 'payload-jobs-stats': { read: nobody, update: nobody } }
## Step 4: register the plugin and wrap the config
// payload.config.ts
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { auditLogPlugin } from '@focus-reactive/payload-plugin-audit-log'
import { accessPolicy } from './access.policy'
export default withAccessPolicy(
accessPolicy,
buildConfig({
// ...the existing config
plugins: [
// after any plugin that creates collections or globals
auditLogPlugin({
access: accessPolicy.plugins['audit-log'],
retention: { days: 365 }, // optional, default: keep forever
}),
],
})
)
With @payloadcms/plugin-mcp (order: 10), give the audit plugin a higher order so MCP keys and agents
are audited: Object.assign(auditLogPlugin({ ... }), { order: 11 })
Run `payload generate:importmap`, then start the app.
A missing or wrong policy entry stops the boot with a list of what to fix.
Fix each item; never loosen a rule to make an error go away.
Postgres / SQLite with migrations: run `payload migrate:create add_audit_log && payload migrate`.
With retention, make sure jobs run (jobs.autoRun, or a cron calling payload.jobs.run()).
Scripts and agents: wrap Local API calls to name the actor, otherwise they are logged as "system":
import { withAuditActor } from '@focus-reactive/payload-plugin-audit-log'
await withAuditActor({ type: 'system', label: 'nightly import' }, () => payload.update({ ... }))
## Step 5: verify, and show me the output
With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.
1. Anonymous export, expect 401:
curl -i 'http://localhost:3000/api/audit-log/export?format=csv'
2. The same request with the session cookie of a user whose role may not export, expect 403.
3. Anonymous read of the log, expect 403:
curl -i http://localhost:3000/api/audit-events
4. A read of the log with the session cookie of a user whose role may not read it, expect 403.
5. A write to the log with an admin's session cookie, expect 403:
curl -i -X POST http://localhost:3000/api/audit-events -H 'Content-Type: application/json' -d '{}'
Then edit and publish a document, sign in with a wrong password, open Settings → Audit log as a user who
may read it, and press Export CSV as a user who may export. Custom events (for example SSO logins): see
logAuditEvent in the plugin README.
pnpm add @focus-reactive/payload-plugin-audit-log @focus-reactive/payload-plugin-guard
// src/access.policy.ts
import { defineAccessPolicy, gate, nobody } from "@focus-reactive/payload-plugin-guard";
const isAdmin = gate(({ req }) => req.user?.collection === "users" && req.user.roles?.includes("admin"));
export const accessPolicy = defineAccessPolicy({
collections: {
// ...an entry for every collection of the project
"audit-events": { create: nobody, read: isAdmin, update: nobody, delete: nobody },
},
plugins: {
"audit-log": { export: isAdmin },
},
});
// payload.config.ts
import { withAccessPolicy } from "@focus-reactive/payload-plugin-guard";
import { auditLogPlugin } from "@focus-reactive/payload-plugin-audit-log";
import { buildConfig } from "payload";
import { accessPolicy } from "./access.policy";
export default withAccessPolicy(
accessPolicy,
buildConfig({
plugins: [auditLogPlugin({ access: accessPolicy.plugins["audit-log"], retention: { days: 365 } })],
})
);
payload and @payloadcms/ui 3.90+, react 19, and @focus-reactive/payload-plugin-guard.payload migrate:create and payload migrate after installing and after upgrades that change select options.payload generate:importmap for the export buttons.@payloadcms/plugin-mcp has order: 10, so give the audit plugin a higher order to audit its API keys.retention, Payload adds its jobs collection and the payload-jobs-stats global, so the policy also needs "payload-jobs": "payload-default" and globals: { "payload-jobs-stats": { read: nobody, update: nobody } }.| Action | When |
|---|---|
doc.create | A document is created or duplicated |
doc.update | A document is changed, autosaved, moved to trash or restored from trash |
doc.delete | A document is deleted permanently |
doc.publish / doc.unpublish | A document's status changes to / from published |
doc.restore | A version is restored |
global.update / global.publish / global.unpublish | A global is changed, autosaved, published or unpublished |
auth.login / auth.logout | Login or logout through Payload |
auth.login_failed | Failed REST or GraphQL login (metadata.reason: invalid_credentials or locked) |
auth.password_reset_requested / auth.password_reset | Forgot-password and reset-password |
audit.export / audit.retention_purge | The log was exported or purged |
payload.db calls and SQL get no events; seeds and migrations get none of their own. Local API calls without a user are recorded with the system actor.doc.update / doc.create / doc.delete events of the user or key collection.doc.update or global.update event with metadata.autosave: true. Filter on it to hide autosaves from a review.changes lists changed field paths. Array and block rows are matched by id: an edited row gives items.2.title, an added row items.2, a removed or reordered row items. JSON and rich text fields are reported by their own path.changes: ["…"], and the cause is logged.occurredAt, action, status, actor, onBehalfOf, agent, via, target (kind, slug, docId, label, locale), changes, overrideAccess, requestId, ip, userAgent, metadata.via is admin for a REST request of a user of the admin user collection signed in with the admin panel's session cookie, rest for any other REST request (an API key, a token in the Authorization header, another auth collection, no user), and graphql, mcp or local for the other channels.
It never depends on a header that a caller can set without signing in, such as Referer.metadata.identifierHash is a keyed hash of it (HMAC-SHA256 with the Payload secret, of the trimmed, lowercased identifier), so repeated attempts against one account can be grouped without keeping the text.
The actor is anonymous, without a label.metadata.notRecordedBefore with the number that were left out.Field values of the changed document are not stored, only their paths. These values are stored:
target.label: the document's useAsTitle field at the time of the event.actor.label and onBehalfOf.label: the user's email, name or username, or the label passed to withAuditActor / logAuditEvent.ip and userAgent from the request headers, unless recordIpAndUserAgent: false.metadata of audit.export: the format, the field names used in the export's filter (not their values) and the row limit.metadata of auth.login_failed: the reason and the identifier hash described above.metadata you pass to logAuditEvent, as given.user: a signed-in user.api_key: a request authenticated with a Payload API key.agent: an MCP request, or code that sets the actor to agent.system: a Local API call without a user.anonymous: a request without a user.withAuditActor labels every Local API call inside the callback. req.context.auditActor (CTX_ACTOR) sets the actor for one request.
import { withAuditActor } from "@focus-reactive/payload-plugin-audit-log";
await withAuditActor({ type: "system", label: "initial content" }, async () => {
await payload.create({ collection: "pages", data: { title: "Home" } });
});
logAuditEvent(payload, { action, target, status?, changes?, overrideAccess?, metadata?, actorOverride?, req?, headers? }) writes a custom event, such as an SSO login. It does nothing when the plugin is not installed or disabled.
| Option | Default | Meaning |
|---|---|---|
access | required | { export }: the gate from your access policy, accessPolicy.plugins["audit-log"] |
enabled | true | false adds nothing to the config |
slug | "audit-events" | Slug of the log collection |
excludeCollections | [] | Collections not to log; the log itself is always excluded |
excludeGlobals | [] | Globals not to log |
retention | not set | { days, queue?, cron? }: delete events older than days (1–36500) |
recordIpAndUserAgent | true | Store ip and userAgent from request headers |
maxChangedPaths | 200 | Maximum entries in changes; a longer list ends with … |
Invalid retention.days or maxChangedPaths throws when the config is built.
| What | Decided by |
|---|---|
Reading events (admin list, REST, GraphQL, Local API with overrideAccess: false) | the read rule of audit-events in your policy |
| Exporting | the export capability, and then the same read rule for each event |
| Creating, updating, deleting events | nobody: the plugin locks these operations, and the guard refuses a policy that grants them |
The plugin owns audit-events: it writes events and the retention job deletes old ones through the guard, and nothing else can, even with overrideAccess.
There is no default read rule: the policy entry is required, and the guard refuses to boot without it.
GET /api/audit-log/export?format=csv|ndjson, with the REST where filter and search (at most 200 characters).export capability.
Anonymous callers get 401; users of another auth collection and users without the capability get 403.read rule.GET /api/audit-log/capabilities).audit.export event.audit-log would hide the endpoints, so the guard refuses such a config at boot.retention.days registers a job that runs daily at 03:00 on queue default (override with cron / queue). It requires a jobs runner: jobs.autoRun or an external call to payload.jobs.handleSchedules() and payload.jobs.run(). Without retention events are kept forever.
find, findByID, findGlobal, REST GET) are unaffected.retention.days.payload.db, direct database access) are not audited, by design.ON DELETE SET NULL) are not recorded.ip and userAgent come from client headers; trust ip only behind a proxy that sets x-forwarded-for.job in via is never detected; label task handlers to get it.via: "admin" whichever client sent it, because a login carries no session yet.2.0 moves the plugin onto @focus-reactive/payload-plugin-guard; Upgrading to the guard explains the model all the plugins share, with a complete example.
Every access rule is now written by hand in your project's src/access.policy.ts, and nothing is open by default: an entry you leave out stops the boot, and a capability you do not grant is refused for everyone.
@payloadcms/* package 3.90 or later, with the React and Next versions Payload 3.90 requires, Node 22.22 or later, and @focus-reactive/payload-plugin-guard installed next to the plugin.access: { read } is replaced by the policy: the old read rule becomes the read entry of audit-events, and downloading the log is the export capability.
There is no default any more: 1.x let every user of the admin user collection read and export the whole log.audit-events are refused for everyone; only the plugin writes events./api/audit-events/export to /api/audit-log/export, and the search term is capped at 200 characters.
The admin buttons already use the new path.metadata.identifierHash replaces it, and at most 30 are recorded a minute per process.metadata.autosave: true.via is admin only for a REST request signed in with the admin panel's session cookie; 1.x read it from the Referer header.Upgrade payload and every @payloadcms/* package to 3.90 or later, run the server on Node 22.22 or later, and install the guard:
pnpm add @focus-reactive/payload-plugin-guard @focus-reactive/payload-plugin-audit-log.
Add the plugin's entries to src/access.policy.ts, with gates for your own roles; if the project has no policy file yet, write it first as the guide describes.
// src/access.policy.ts, inside defineAccessPolicy({ ... })
collections: {
"audit-events": { create: nobody, read: isAdmin, update: nobody, delete: nobody },
"payload-jobs": "payload-default", // only with retention
},
globals: {
"payload-jobs-stats": { read: nobody, update: nobody }, // only with retention
},
plugins: {
"audit-log": { export: isAdmin },
},
export: download the log as CSV or NDJSON from GET /api/audit-log/export.audit-events: read decides who may read the log in the admin and over the API; every write stays nobody.payload-jobs and payload-jobs-stats: Payload adds them when retention schedules the purge job.Pass access: accessPolicy.plugins["audit-log"] to auditLogPlugin, and export the config wrapped: export default withAccessPolicy(accessPolicy, buildConfig({ ... })).
Database: no migration; the log collection keeps its columns.
Re-test: an anonymous GET /api/audit-log/export?format=csv answers 401 and one from a user without export 403; POST /api/audit-events as an admin answers 403; a user without the read rule gets 403 from GET /api/audit-events; then change a document and sign in with a wrong password, and check that both appear in the log.
MIT
Topics
Tags
payload plugin workflows
Code-defined editorial workflows with stages, actions, transitions and publish guards for editors and AI agents
73797/wk37v3
payload plugin presets
Save and apply reusable block configurations as presets from the Payload admin blocks drawer
786.7k/wk37v3
payload plugin scheduling
Schedule future publication of drafts on collections and globals with a secured cron endpoint
77783/wk37v3
payload plugin guard
Central access policy file, typed predicates and guarded endpoints for Payload plugins and Local API calls
73664/wk37v3
payload plugin json form builder
Edit a Payload json field as real admin fields, with the form shape built in the admin panel
72441/wk37v3
payload plugin translator
Translate localized Payload content with an AI provider from the admin panel via background jobs
713.9k/wk37v3