Skip to content

fix: bypass access control for audit writes and cleanup - #56

Merged
shaadcode merged 1 commit into
shaadcode:mainfrom
crazytweeks:fix/payload-4-system-writes
Oct 26, 2026
Merged

shaadcode merged 1 commit into
shaadcode:mainfrom
crazytweeks:fix/payload-4-system-writes

Conversation

@crazytweeks

@crazytweeks crazytweeks commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #55

Both places where the plugin writes as a system operation now pass overrideAccess: true:

  • bufferManager flush — payload.create(...)
  • log cleanup task — req.payload.delete(...)

Payload 4 defaults overrideAccess to false on the local API (it was true in v3). Audit-log relies on the default access control, so both calls are rejected with Forbidden when there is no user. The flush rejection is unhandled and drops the entry; the cleanup task catches the error and leaves expired rows behind.

This keeps the existing behavior on v3 and restores it on v4.

Tests

  • bun run test:unit — 29 passed
  • bun run check-types — clean
  • bun run lint — clean

The existing tests that assert the exact call arguments were updated. I also checked both paths against a minimal Payload 4.0.0-beta.4 app: a tracked update writes an audit row, and the cleanup task removes expired rows.

One note for testing on v4: Payload now defaults versions: true for every collection, and Audit-log sets timestamps: false, so buildConfig throws TimestampsRequired unless the app sets versions: false for that collection for now (I used a small plugin locally to do that). That's the separate item mentioned in the issue.

Payload 4 defaults overrideAccess to false on the local API, so the buffer flush and the cleanup task are rejected with Forbidden when they run without a user. Pass overrideAccess: true for these internal writes and update the tests that assert the call arguments.
@shaadcode

Copy link
Copy Markdown
Owner

thanks @crazytweeks

@shaadcode
shaadcode merged commit 605512c into shaadcode:main Oct 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit writes and log cleanup are rejected on Payload 4

2 participants