Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add role update restriction in user update process

Bill Yang967747cf2eae
diff --git a/server/src/lib/auth.ts b/server/src/lib/auth.ts
index c7c0cdde3..626d274c5 100644
--- a/server/src/lib/auth.ts
+++ b/server/src/lib/auth.ts
@@ -155,6 +155,19 @@ export let auth: AuthType | null = betterAuth({
}
},
},
+ update: {
+ before: async userUpdate => {
+ // Security: Prevent role field from being updated via regular update-user endpoint
+ // Role changes should only go through the admin setRole endpoint
+ if (userUpdate && typeof userUpdate === "object" && "role" in userUpdate) {
+ // Remove role from the update data
+ const { role: _, ...dataWithoutRole } = userUpdate;
+ return {
+ data: dataWithoutRole,
+ };
+ }
+ },
+ },
},
},
});
@@ -233,6 +246,19 @@ export function initAuth(allowedOrigins: string[]) {
}
},
},
+ update: {
+ before: async userUpdate => {
+ // Security: Prevent role field from being updated via regular update-user endpoint
+ // Role changes should only go through the admin setRole endpoint
+ if (userUpdate && typeof userUpdate === "object" && "role" in userUpdate) {
+ // Remove role from the update data
+ const { role: _, ...dataWithoutRole } = userUpdate;
+ return {
+ data: dataWithoutRole,
+ };
+ }
+ },
+ },
},
},
});