fix(core/api): gate group + join-request + conditional-binding mutations#81
Merged
Conversation
The audit caught two CRITICAL and many HIGH-severity holes in
core/api/group.go: every mutating endpoint (add member, add owner,
delete group, approve/reject join requests, conditional bindings)
ran with zero auth. Anyone reaching the API could add themselves to
the Admins group and instantly hold every admin gate.
Adds a single gate helper to api.go and applies it across the
affected handlers:
- requireGroupOwnerOrAdmin(c, groupID) — passes when the bearer
carries sentinel:all, owns the group, or is a global admin.
Matches the convention sentinel:all = internal-automation bypass.
- RequestUserIsGroupOwner(c, groupID) — new low-level helper
looking up GroupOwner rows for the bearer's entity. False for
unauthed.
Gated handlers (all in core/api/group.go + conditional_binding.go):
- CreateOrUpdateGroup: create path requires only RequestTokenExists
(creator becomes auto-owner); update path goes through the
owner-or-admin gate.
- DeleteGroup
- AddGroupMember / RemoveGroupMember
- AddGroupOwner / RemoveGroupOwner
- ApproveGroupJoinRequest / RejectGroupJoinRequest /
DeleteGroupJoinRequest
- CreateGroupJoinRequest: self-or-elevated — bearer's entity_id
must match req.EntityID, with admin/sentinel:all override.
Group owners can't backdoor people via this path; they'd use
AddGroupMember directly.
- CreateJoinRequestComment: self-or-elevated. Bearer must be the
claimed author OR group owner OR admin OR sentinel:all.
- DeleteJoinRequestComment: same shape, authorized against the
persisted comment's author. Adds service.GetJoinRequestComment.
- CreateGroupConditionalBinding / DeleteGroupConditionalBinding
GET endpoints in this file are left ungated for now — they'll be
covered in PR #83 (PII reads + enumeration) with at least an
authed-only check.
This was referenced Jun 17, 2026
This was referenced Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on top of #80 — base branch is `bk1031/harden-token-gates`. The diff shown here is just this PR's gates.
Audit holes covered
Two CRITICAL and many HIGH from the post-s2s-auth audit:
Fix shape
One new helper at the api.go level:
```go
func requireGroupOwnerOrAdmin(c, groupID) bool {
Any(
RequestTokenHasScope(c, "sentinel:all"),
RequestUserIsGroupOwner(c, groupID),
RequestUserIsAdmin(c),
)
}
```
Each gated handler calls it at the top; some special cases (join-request self-submission, comment self-authorship) check the bearer's entity directly.
GET endpoints left for PR #83 (PII reads).
Test plan