Skip to content

fix(core/api): gate group + join-request + conditional-binding mutations#81

Merged
BK1031 merged 1 commit into
mainfrom
bk1031/harden-group-gates
Jun 17, 2026
Merged

fix(core/api): gate group + join-request + conditional-binding mutations#81
BK1031 merged 1 commit into
mainfrom
bk1031/harden-group-gates

Conversation

@BK1031

@BK1031 BK1031 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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:

  • `POST /groups/:id/members` (CRITICAL) — add anyone to Admins
  • `POST /groups/:id/owners` (CRITICAL) — make anyone a group owner
  • `POST /groups` (UPDATE path), `DELETE /groups/:id`, `DELETE /groups/:id/members/:entityID`, `DELETE /groups/:id/owners/:entityID` (HIGH × 4)
  • `POST /groups/:id/requests/:requestID/approve` and `/reject` (HIGH × 2)
  • `POST /groups/:id/conditional-bindings` and `DELETE` (HIGH × 2)
  • Plus medium-severity: `CreateGroupJoinRequest`, `DeleteGroupJoinRequest`, comment create/delete

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

  • Without auth, `POST /groups/:id/members` → 403
  • As a non-owner non-admin user, `POST /groups/:id/members` → 403
  • As the group's owner, `POST /groups/:id/members` → 200
  • As an admin, `POST /groups/:id/members` on any group → 200
  • An internal SA's bearer (sentinel:all) → 200
  • `CreateGroupJoinRequest` from user A with body `entity_id=B` → 403; with their own → 200
  • Comments: delete-your-own works; delete-someone-else's → 403 unless owner/admin

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.
Base automatically changed from bk1031/harden-token-gates to main June 17, 2026 08:29
@BK1031 BK1031 merged commit eef7ff8 into main Jun 17, 2026
15 checks passed
@BK1031 BK1031 deleted the bk1031/harden-group-gates branch June 17, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant