Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access private repo release files through API using bearer token anymore #25257

Closed
enz1ey opened this issue Jun 14, 2023 · 14 comments · Fixed by #25639 or #26430
Closed

Cannot access private repo release files through API using bearer token anymore #25257

enz1ey opened this issue Jun 14, 2023 · 14 comments · Fixed by #25639 or #26430
Labels

Comments

@enz1ey
Copy link

enz1ey commented Jun 14, 2023

Description

Apparently an RC release was pushed to Docker instances using the "lates" tag, so my Gitea instance is now running 1.20.0rc and I cannot downgrade. Since updating, I am no longer able to download files over HTTPS using my token. I am attempting to access the file URL and I am getting 404 errors. If I make the repository public, I am able to download the files just fine.

This bearer token works when listing releases via the API, just not downloading them. Nothing else has changed in my instance.

Gitea Version

1.20.0+rc0-48-g3afc3e4a7

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Docker

Database

MySQL

@lunny
Copy link
Member

lunny commented Jun 15, 2023

What's your download url?

@enz1ey
Copy link
Author

enz1ey commented Jun 21, 2023

What's your download url?

An example of a browser_download_url would be: https://git.my-domain.com/Owner/Repo/releases/download/20.1.34.78/FileName.exe

I am sending a GET request to this URL with a bearer token which is confirmed working elsewhere, as this is a private repository but I can still list releases and their assets.

I have also tested browsing to this exact URL inside an authenticated browser session, and I am able to download the file, so it's certainly not an issue with the URL.

@CMiksche
Copy link

CMiksche commented Jun 28, 2023

I have the same problem (with 1.20.0-rc2). I noticed it still works when a session is already open and the user authenticated....

@lunny
Copy link
Member

lunny commented Jun 29, 2023

What's your download url?

An example of a browser_download_url would be: https://git.my-domain.com/Owner/Repo/releases/download/20.1.34.78/FileName.exe

I am sending a GET request to this URL with a bearer token which is confirmed working elsewhere, as this is a private repository but I can still list releases and their assets.

I have also tested browsing to this exact URL inside an authenticated browser session, and I am able to download the file, so it's certainly not an issue with the URL.

There is no this route like releases/download.

@lunny lunny added this to the 1.20.0 milestone Jun 29, 2023
@CMiksche
Copy link

There is no this route like releases/download.

There is. See https://gitea.com/gitea/act_runner/releases/download/v0.2.0/act_runner-0.2.0-darwin-amd64

@lunny
Copy link
Member

lunny commented Jun 29, 2023

Yes, I found the problem. I just search API routes and found the attachments download URL in fact point to web routes. Since web routes have removed support token authentication. I think to resolve the bug, we have two options.

  1. create a new download route in API routes and return that URLs in API releases list.
  2. the web route download supports token authentication.

@CMiksche
Copy link

I think to resolve the bug, we have two options.

While 2. would probably be easier, I guess there was some good reason why token authentication was removed from the web routes. If we add token auth there again and somebody makes changes in the web routes, they probably don't think that this will affect the API routes.

So I think 1. is the better way because this is in line with the architecture of Gitea.

@lunny
Copy link
Member

lunny commented Jul 3, 2023

We can implement a new API like https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28 and change the release download url to the new URL.
The API has been implemented in https://github.com/go-gitea/gitea/blob/main/routers/api/v1/repo/release_attachment.go#L21, so we just need to return the correct asset URL from API requests.

silverwind pushed a commit that referenced this issue Jul 10, 2023
Fix #25257

---------

Co-authored-by: Giteabot <teabot@gitea.io>
GiteaBot added a commit to GiteaBot/gitea that referenced this issue Jul 10, 2023
Fix go-gitea#25257

---------

Co-authored-by: Giteabot <teabot@gitea.io>
KN4CK3R pushed a commit that referenced this issue Jul 10, 2023
Backport #25639 by @lunny

Fix #25257

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@CMiksche
Copy link

I just wanted to inform that the issue still persists with the stable version 1.20...

@lunny lunny reopened this Jul 19, 2023
@lunny
Copy link
Member

lunny commented Jul 19, 2023

@wxiaoguang wxiaoguang modified the milestones: 1.20.0, 1.20.1 Jul 21, 2023
@delvh delvh removed this from the 1.20.1 milestone Jul 22, 2023
@kirbylink
Copy link

I also noticed the bug in my local Gitea (version 1.20.1).
The general API call with my applications and an API token works.
Only the download still fails with 404.
Current version is fetched via the API and the browserDownloadUrl is called with the API token.
If I call up the URL in the browser with the user logged in, the download works.

@lunny
Copy link
Member

lunny commented Jul 27, 2023

#25639 missed a change, And I think #26175 #26430 should fix it.

@xiaoxinpro
Copy link

The issue persists in the latest 1.20.4 release

I wonder if this will be fixed

Because I am waiting for this issue to be fixed before I can upgrade to 1.20.x, otherwise I will be stuck with 1.19.3

@lunny
Copy link
Member

lunny commented Sep 8, 2023

Sorry forgot my PR #26430

lunny added a commit that referenced this issue Oct 1, 2023
…at (#26430) (#27379)

Backport #26430 by @lunny

Fix #26165
Fix #25257

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
lunny added a commit that referenced this issue Oct 1, 2023
…at (#26430) (#27378)

Backport #26430 by @lunny

Fix #26165
Fix #25257

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
7 participants