Skip to content

Commit 972dfb1

Browse files
committed
Tighten user data security
1 parent 65c1607 commit 972dfb1

File tree

3 files changed

+116
-43
lines changed

3 files changed

+116
-43
lines changed

backend/internal/graph/api/shared.resolvers.go

Lines changed: 73 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package api
2+
3+
import (
4+
"context"
5+
6+
"github.com/bcc-media/wayfarer/internal/services"
7+
)
8+
9+
// canAccessUser checks if currentUserID can access targetUserID's User object.
10+
//
11+
// Returns true if any of these conditions are met:
12+
// - currentUserID is the target user (self-access)
13+
// - currentUserID has admin or superadmin role
14+
// - currentUserID has M2M role (for system integration)
15+
//
16+
// Returns false otherwise.
17+
//
18+
// This function is used to protect User objects from unauthorized access
19+
// in GraphQL field resolvers that return User or [User] types.
20+
func canAccessUser(
21+
ctx context.Context,
22+
roleService *services.RoleService,
23+
currentUserID string,
24+
targetUserID string,
25+
) bool {
26+
// Self-access always allowed
27+
if currentUserID == targetUserID {
28+
return true
29+
}
30+
31+
// Admins and superadmins can access any user
32+
if roleService.IsAdmin(ctx, currentUserID) {
33+
return true
34+
}
35+
36+
// M2M service accounts can access any user
37+
if roleService.HasRole(ctx, currentUserID, services.RoleM2M) {
38+
return true
39+
}
40+
41+
return false
42+
}

yaak-workspace/yaak.rq_CreateContentAchievement.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ type: http_request
22
model: http_request
33
id: rq_CreateContentAchievement
44
createdAt: 2025-12-11T12:00:00
5-
updatedAt: 2025-12-13T17:42:53.341427
5+
updatedAt: 2025-12-13T19:24:01.550689
66
workspaceId: wk_XKsmbMdFg7
77
folderId: fl_Achievements
88
authentication: {}

0 commit comments

Comments
 (0)