-
Notifications
You must be signed in to change notification settings - Fork 0
Enable specific users to have admin powers to delete any poll #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7c92c0d
4f3f1d7
1377e93
92547eb
8e03147
3809049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ export class UserService { | |
| worldID: true, | ||
| name: true, | ||
| profilePicture: true, | ||
| isAdmin: true, | ||
| pollsCreatedCount: true, | ||
| pollsParticipatedCount: true, | ||
| }, | ||
|
|
@@ -110,6 +111,7 @@ export class UserService { | |
| worldID: user.worldID, | ||
| worldProfilePic: user.profilePicture, | ||
| name: user.name, | ||
| isAdmin: user.isAdmin, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -456,4 +458,12 @@ export class UserService { | |
|
|
||
| return await this.databaseService.user.count({ where }) | ||
| } | ||
|
|
||
| async listAdmins(): Promise<string[]> { | ||
| const admins = await this.databaseService.user.findMany({ | ||
| where: { isAdmin: true }, | ||
| select: { worldID: true }, | ||
| }) | ||
| return admins.map(admin => admin.worldID) | ||
| } | ||
|
Comment on lines
+462
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCritical: Missing authorization for admin list endpoint. The Consider adding proper authorization to restrict access to this endpoint: + // Add authorization decorator in controller
+ @UseGuards(AdminGuard) // or similar authorization mechanism
async listAdmins(): Promise<string[]> {
const admins = await this.databaseService.user.findMany({
where: { isAdmin: true },
select: { worldID: true },
})
return admins.map(admin => admin.worldID)
}Additionally, verify if returning admin worldIDs is necessary or if the endpoint should be restricted to specific use cases. 🏁 Script executed: #!/bin/bash
# Description: Check how this method is used in the controller and if there are authorization guards
# Expected: Find the controller method and any authorization decorators
rg -A 10 -B 5 "listAdmins" src/user/user.controller.ts
rg -A 5 -B 5 "@.*Guard|@.*Auth" src/user/user.controller.tsLength of output: 384 Critical: Secure the The controller’s • File: src/user/user.controller.ts Proposed fix – restrict access to authenticated admins only: - @Get('listAdmins')
- @Public()
+ @Get('listAdmins')
+ @UseGuards(JwtAuthGuard, RolesGuard) // or your existing AdminGuard
+ @Roles('admin') // ensure only users with isAdmin=true
async listAdmins(): Promise<string[]> {
return await this.userService.listAdmins();
}• Remove the
🤖 Prompt for AI Agents |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify if admin status should be publicly exposed.
The
isAdminfield is now included in the database query for user data retrieval. While the implementation is correct, consider whether admin status should be publicly accessible through thegetUserDataendpoint.🏁 Script executed:
Length of output: 505
Restrict public exposure of admin status
The
getUserDataendpoint insrc/user/user.controller.tsis publicly accessible (no authorization decorators), which means the newisAdminflag can be fetched by any caller. Exposing admin status in an open API poses a security risk and may aid malicious reconnaissance.• File: src/user/user.controller.ts
– Method:
getUserData(no@UseGuards(...)or equivalent)• Snippet:
@Get('getUserData') - async getUserData( + @UseGuards(AuthGuard) // <-- add appropriate guard + @ApiBearerAuth() // <-- document secured endpoint + @ApiOperation({ summary: 'Retrieve user data (authenticated)' }) async getUserData(Please either restrict this endpoint with proper authorization checks (e.g. JWT/session guard) or remove
isAdminfrom the public response.🤖 Prompt for AI Agents