Skip to content

Commit 4ae5577

Browse files
fix: add field-level access control to internal auth fields (#16119)
Adds field-level access control to internal auth fields (`hash`, `salt`, `resetPasswordToken`, `resetPasswordExpiration`, `loginAttempts`, `lockUntil`, `_verificationToken`) to prevent external writes. This is a preventative measure. Users should configure collection-level access control on auth collections (e.g., restricting who can update users) rather than relying solely on field-level protections. Internal auth operations are unaffected as they use direct DB operations. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1213885887366085
1 parent 5c06266 commit 4ae5577

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

packages/payload/src/auth/baseFields/accountLock.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ export const accountLockFields: Field[] = [
44
{
55
name: 'loginAttempts',
66
type: 'number',
7+
access: {
8+
create: () => false,
9+
update: () => false,
10+
},
711
defaultValue: 0,
812
hidden: true,
913
},
1014
{
1115
name: 'lockUntil',
1216
type: 'date',
17+
access: {
18+
create: () => false,
19+
update: () => false,
20+
},
1321
hidden: true,
1422
},
1523
] as Field[]

packages/payload/src/auth/baseFields/auth.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,37 @@ export const baseAuthFields: Field[] = [
44
{
55
name: 'resetPasswordToken',
66
type: 'text',
7+
access: {
8+
create: () => false,
9+
update: () => false,
10+
},
711
hidden: true,
812
},
913
{
1014
name: 'resetPasswordExpiration',
1115
type: 'date',
16+
access: {
17+
create: () => false,
18+
update: () => false,
19+
},
1220
hidden: true,
1321
},
1422
{
1523
name: 'salt',
1624
type: 'text',
25+
access: {
26+
create: () => false,
27+
update: () => false,
28+
},
1729
hidden: true,
1830
},
1931
{
2032
name: 'hash',
2133
type: 'text',
34+
access: {
35+
create: () => false,
36+
update: () => false,
37+
},
2238
hidden: true,
2339
},
2440
]

packages/payload/src/auth/baseFields/verification.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Field, FieldHook } from '../../fields/config/types.js'
22

3+
import { defaultAccess } from '../defaultAccess.js'
4+
35
const autoRemoveVerificationToken: FieldHook = ({ data, operation, originalDoc, value }) => {
46
// If a user manually sets `_verified` to true,
57
// and it was `false`, set _verificationToken to `null`.
@@ -20,9 +22,9 @@ export const verificationFields: Field[] = [
2022
name: '_verified',
2123
type: 'checkbox',
2224
access: {
23-
create: ({ req: { user } }) => Boolean(user),
24-
read: ({ req: { user } }) => Boolean(user),
25-
update: ({ req: { user } }) => Boolean(user),
25+
create: defaultAccess,
26+
read: defaultAccess,
27+
update: defaultAccess,
2628
},
2729
admin: {
2830
components: {
@@ -34,6 +36,10 @@ export const verificationFields: Field[] = [
3436
{
3537
name: '_verificationToken',
3638
type: 'text',
39+
access: {
40+
create: () => false,
41+
update: () => false,
42+
},
3743
hidden: true,
3844
hooks: {
3945
beforeChange: [autoRemoveVerificationToken],

0 commit comments

Comments
 (0)