Skip to content

database: bound collaboration access mode by min(actor, admin) - #8227

Merged
unknwon merged 1 commit into
mainfrom
wh/fix-change-access-mode-to-owner
Jun 6, 2026
Merged

unknwon merged 1 commit into
mainfrom
wh/fix-change-access-mode-to-owner

Conversation

@wuhan005

@wuhan005 wuhan005 commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Describe the pull request

Tighten ChangeCollaborationAccessMode in the database layer so that:

  • The new access mode is capped at AccessModeAdmin. AccessModeOwner (value 4) is reserved for the repository owner and is no longer accepted on a collaboration record. This closes the off-by-one in the previous guard (mode > AccessModeOwner).
  • The new access mode is also bounded by the actor's own access mode. An actor can never grant a level above their own, so even if a future caller forgets the cap, an admin collaborator cannot escalate themselves or anyone else past admin.

Both call sites (POST /:username/:reponame/settings/collaboration/access_mode in the web UI, and PUT /api/v1/repos/:username/:reponame/collaborators/:collaborator in the API) now pass the caller's effective AccessMode through to the database function.

Advisory: GHSA-4565-r4x7-hg8j

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  • A collaborator with Admin access posts mode=4 for their own UID. The response is 204 but the stored access remains Admin.
  • A collaborator with Admin access posts mode=4 for another collaborator's UID. The target's access remains unchanged.
  • The repository owner can still perform all owner-level operations.
  • An organization owner (effective access Owner via the Owners team) can still change collaboration access modes up to Admin.

@wuhan005
wuhan005 marked this pull request as ready for review April 5, 2026 15:53
@wuhan005
wuhan005 requested a review from unknwon as a code owner April 5, 2026 15:53
Copilot AI review requested due to automatic review settings April 5, 2026 15:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens repository collaboration permission handling by preventing AccessModeOwner from being persisted for collaborator records in the database layer, closing an escalation path reachable via the web UI endpoint that accepts numeric mode values.

Changes:

  • Tighten ChangeCollaborationAccessMode validation to reject any mode greater than AccessModeAdmin (thereby disallowing AccessModeOwner on collaboration/access rows).
  • Add a security fix note to the 0.15.0+dev changelog.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/database/repo_collaboration.go Restricts persisted collaborator access mode to max Admin, preventing owner-level escalation via numeric mode input.
CHANGELOG.md Documents the security fix in the unreleased changelog section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/database/repo_collaboration.go Resolved
Comment thread CHANGELOG.md Outdated

### Fixed

- _Security:_ Repository collaborators with Admin access could escalate their own or others' access mode to Owner via the web UI.

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog entry doesn’t follow the pattern used by other recent _Security:_ bullets (they typically include a PR link and, when applicable, a GHSA/advisory reference). Consider appending the PR number link for consistency once available, and add an advisory link if this fix will be tracked via GHSA/CVE.

Suggested change
- _Security:_ Repository collaborators with Admin access could escalate their own or others' access mode to Owner via the web UI.
- _Security:_ Repository collaborators with Admin access could escalate their own or others' access mode to Owner via the web UI. _(PR link pending; add GHSA/CVE link if assigned)_

Copilot uses AI. Check for mistakes.

@unknwon unknwon Apr 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wuhan005 I think this feedback is legit. I think I saw one GHSA about this?

Comment thread internal/database/repo_collaboration.go Resolved
@unknwon unknwon added this to the 0.14.3 milestone Jun 6, 2026
Reject any attempt to change a collaboration access mode to a level
above the actor's own access mode, and cap the new mode at admin (owner
is reserved for the repository owner). Both the web settings handler and
the API `addCollaborator` handler now pass the caller's effective access
mode through to the database layer.
@unknwon
unknwon force-pushed the wh/fix-change-access-mode-to-owner branch from 1a806a5 to 11019a0 Compare June 6, 2026 01:23
@unknwon unknwon changed the title database: update access mode validation in ChangeCollaborationAccessMode database: bound collaboration access mode by actor and admin Jun 6, 2026
@unknwon unknwon changed the title database: bound collaboration access mode by actor and admin database: bound collaboration access mode by min(actor, admin) Jun 6, 2026
@unknwon
unknwon merged commit 1fdc9cc into main Jun 6, 2026
8 checks passed
@unknwon
unknwon deleted the wh/fix-change-access-mode-to-owner branch June 6, 2026 01:26
unknwon added a commit that referenced this pull request Jun 7, 2026
Co-authored-by: Joe Chen <jc@unknwon.io>
(cherry picked from commit 1fdc9cc)
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.

3 participants

⌂ 换网址