Skip to content

Fix get release draft permission check#36659

Merged
silverwind merged 10 commits intogo-gitea:mainfrom
lunny:lunny/fix_get_release_draft
Feb 22, 2026
Merged

Fix get release draft permission check#36659
silverwind merged 10 commits intogo-gitea:mainfrom
lunny:lunny/fix_get_release_draft

Conversation

@lunny
Copy link
Copy Markdown
Member

@lunny lunny commented Feb 17, 2026

Draft release and it's attachments need a write permission to access.

@lunny lunny added type/bug backport/v1.25 This PR should be backported to Gitea 1.25 labels Feb 17, 2026
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 17, 2026
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 tightens API access control around draft releases to ensure they’re only visible to users with write permission and (when authenticated via token) an appropriate write-level repository scope, and extends the same protection to draft release attachments.

Changes:

  • Enforce draft-release visibility checks in GetRelease and ListReleases using a combined repo-permission + token-scope (write:repository) gate.
  • Apply the same draft visibility restriction to release attachment APIs (list/get) and shared release-repo matching.
  • Add integration tests and fixtures to validate draft release and draft attachment access behavior.

Reviewed changes

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

Show a summary per file
File Description
tests/integration/api_releases_test.go Adds a draft-release GET integration test (needs additional scope-coverage updates).
tests/integration/api_releases_attachment_test.go Adds a draft-release attachment access test and new API structs usage.
routers/api/v1/repo/release_attachment.go Blocks draft attachment access for unauthorized users (contains a redundant extra release DB lookup).
routers/api/v1/repo/release.go Introduces helper functions to enforce write-scope for draft release visibility and draft inclusion in listing.
models/fixtures/attachment.yml Adds a fixture attachment linked to a draft release for integration testing.

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

lunny and others added 5 commits February 19, 2026 13:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 22, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 22, 2026
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 22, 2026
@silverwind silverwind enabled auto-merge (squash) February 22, 2026 20:29
@silverwind silverwind merged commit 1eced4a into go-gitea:main Feb 22, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Feb 22, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 22, 2026
@lunny lunny deleted the lunny/fix_get_release_draft branch February 22, 2026 21:24
GiteaBot added a commit to GiteaBot/gitea that referenced this pull request Feb 22, 2026
Draft release and it's attachments need a write permission to access.

---------

Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Giteabot <teabot@gitea.io>
lunny added a commit that referenced this pull request Feb 22, 2026
Backport #36659 by @lunny

Draft release and it's attachments need a write permission to access.

Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
release_service "code.gitea.io/gitea/services/release"
)

func hasRepoWriteScope(ctx *context.APIContext) bool {
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.

The name is not right. It will be definitely abused in the future.

It returns true for anonymous user.

Comment on lines +38 to +42
if !canAccessDraftRelease(ctx) {
if !ctx.Written() {
ctx.APIErrorNotFound()
}
return false
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.

Why use this new error pattern?

You should make canAccessDraftRelease write reponse if it returns false

(Many places)

@wxiaoguang
Copy link
Copy Markdown
Contributor

Following up: Fix release draft access check logic #36720

zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 23, 2026
* giteaofficial/main: (81 commits)
  Add keyboard shortcuts for repository file and code search (go-gitea#36416)
  Refactor text utility classes to Tailwind CSS (go-gitea#36703)
  Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660)
  Fix force push time-line commit comments of pull request (go-gitea#36653)
  Fix get release draft permission check (go-gitea#36659)
  Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256)
  Update JS and PY deps (go-gitea#36708)
  Move jobparser from act repository to Gitea (go-gitea#36699)
  Fix push time bug (go-gitea#36693)
  Add icon to buttons "Close with Comment", "Close Pull Request", "Close Issue" (go-gitea#36654)
  various fixes (go-gitea#36697)
  Add AI Contribution Policy to CONTRIBUTING.md (go-gitea#36651)
  Add some validation on values provided to USER_DISABLED_FEATURES and EXTERNAL_USER_DISABLED_FEATURES (go-gitea#36688)
  Rework e2e tests (go-gitea#36634)
  Remove unused functions (go-gitea#36672)
  Add migration http transport for push/sync mirror lfs (go-gitea#36665)
  Fix track time issue id (go-gitea#36664)
  Refactor inline style attributes (go-gitea#36652)
  Update Nix flake (go-gitea#36679)
  Upgrade gogit to 5.16.5 (go-gitea#36680)
  ...

# Conflicts:
#	web_src/js/features/repo-issue-content.ts
silverwind added a commit to silverwind/gitea that referenced this pull request Feb 26, 2026
* main: (24 commits)
  Instance-wide (global) info banner and maintenance mode (go-gitea#36571)
  Add created_by filter to SearchIssues (go-gitea#36670)
  Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714)
  Fix release draft access check logic (go-gitea#36720)
  Change image transparency grid to CSS (go-gitea#36711)
  Avoid opening new tab when downloading actions logs (go-gitea#36740)
  Add validation constraints for repository creation fields (go-gitea#36671)
  Fix SVG height calculation in diff viewer (go-gitea#36748)
  Fix path resolving (go-gitea#36734)
  [skip ci] Updated translations via Crowdin
  Fix track time list permission check (go-gitea#36662)
  Fix incorrect setting loading order (go-gitea#36735)
  Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728)
  feat: Add workflow dependencies visualization (go-gitea#36248)
  Add keyboard shortcuts for repository file and code search (go-gitea#36416)
  Refactor text utility classes to Tailwind CSS (go-gitea#36703)
  Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660)
  Fix force push time-line commit comments of pull request (go-gitea#36653)
  Fix get release draft permission check (go-gitea#36659)
  Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256)
  ...

# Conflicts:
#	web_src/css/base.css
#	web_src/css/index.css
@lunny lunny added the backport/done All backports for this PR have been created label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.25 This PR should be backported to Gitea 1.25 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants