Repository navigation
fix: bypass access control for audit writes and cleanup - #56
Merged
shaadcode merged 1 commit intoOct 26, 2026
Merged
Conversation
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.
Owner
|
thanks @crazytweeks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #55
Both places where the plugin writes as a system operation now pass
overrideAccess: true:bufferManagerflush —payload.create(...)req.payload.delete(...)Payload 4 defaults
overrideAccesstofalseon the local API (it wastruein v3).Audit-logrelies on the default access control, so both calls are rejected withForbiddenwhen 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 passedbun run check-types— cleanbun run lint— cleanThe 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: truefor every collection, andAudit-logsetstimestamps: false, sobuildConfigthrowsTimestampsRequiredunless the app setsversions: falsefor that collection for now (I used a small plugin locally to do that). That's the separate item mentioned in the issue.