Merge pull request #18990 from Budibase/user-update-checks

tighten user update check
This commit is contained in:
melohagan
2026-06-16 15:34:31 +01:00
committed by GitHub
2 changed files with 42 additions and 0 deletions
@@ -109,6 +109,10 @@ export const save = async (ctx: UserCtx<UnsavedUser, SaveUserResponse>) => {
export const changeTenantOwnerEmail = async (
ctx: Ctx<ChangeTenantOwnerEmailRequest, void>
) => {
if (!ctx.internal) {
ctx.throw(403, "Unauthorized")
}
const { newAccountEmail, originalEmail, tenantIds } = ctx.request.body
try {
for (const tenantId of tenantIds) {
@@ -1528,5 +1528,43 @@ describe("/api/global/users", () => {
.set(config.defaultHeaders())
.expect(403)
})
it("should reject authenticated users on self-hosted", async () => {
const originalEmail = `original-${structures.uuid()}@example.com`
const newEmail = `new-${structures.uuid()}@example.com`
const tenantId = config.getTenantId()
const tenantUser = await config.doInTenant(async () => {
return await userSdk.db.save(
structures.users.user({
email: originalEmail,
tenantId,
roles: {},
}),
{ requirePassword: false, isAccountHolder: true }
)
})
config.selfHosted()
try {
await config.request
.put(`/api/global/users/tenant/owner`)
.send({
newAccountEmail: newEmail,
originalEmail,
tenantIds: [tenantId],
})
.set(config.defaultHeaders())
.expect(403)
} finally {
config.cloudHosted()
}
const unchangedUser = await config.doInTenant(async () => {
return await userSdk.db.getUser(tenantUser._id!)
})
expect(unchangedUser!.email).toBe(originalEmail)
})
})
})