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

/api/v1/version should not give 403 for authenticated users/tokens #26035

Closed
rgl opened this issue Jul 21, 2023 · 1 comment · Fixed by #26134
Closed

/api/v1/version should not give 403 for authenticated users/tokens #26035

rgl opened this issue Jul 21, 2023 · 1 comment · Fixed by #26134
Labels

Comments

@rgl
Copy link

rgl commented Jul 21, 2023

Description

Before gitea 1.20.0, a token with the repo scope could access the /api/v1/version endpoint.

In gitea 1.20.0, a token with the write:repository scope cannot access the /api/v1/version endpoint.

Here's the partial bash script that I've used to create the token and test it:

# see https://try.gitea.io/api/swagger#/user/userCreateToken
echo "Creating Gitea $RENOVATE_USERNAME user personal access token..."
curl \
    --silent \
    --show-error \
    --fail-with-body \
    -u "$RENOVATE_USERNAME:$RENOVATE_PASSWORD" \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"name": "renovate", "scopes": ["write:repository"]}' \
    "$gitea_url/api/v1/users/$RENOVATE_USERNAME/tokens" \
    | jq -r .sha1 \
    >tmp/renovate-gitea-token.txt

# try the token.
echo "Trying the Gitea $RENOVATE_USERNAME user personal access token..."
RENOVATE_TOKEN="$(cat tmp/renovate-gitea-token.txt)"
export RENOVATE_TOKEN
curl \
    -s \
    --silent \
    --show-error \
    --fail-with-body \
    -H "Authorization: token $RENOVATE_TOKEN" \
    -H 'Accept: application/json' \
    "$gitea_url/api/v1/version" \
    | jq \
    > /dev/null

Gitea Version

1.20.0

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

In docker, as configured in the first part of the bash script at https://github.com/rgl/my-ubuntu-ansible-playbooks/blob/main/renovate.sh

Database

SQLite

@rgl rgl added the type/bug label Jul 21, 2023
@wxiaoguang
Copy link
Contributor

It seems that it's related to my (unresolved) review comment:

#24767 (review)

If I understand correctly, /version could always be accessed without a token (it doesn't really require the misc scope token).

But .... if it is accessed by a token without "misc" scope, then it becomes inaccessible? It really looks strange.

@lunny lunny added this to the 1.20.1 milestone Jul 21, 2023
@delvh delvh removed this from the 1.20.1 milestone Jul 22, 2023
lunny pushed a commit that referenced this issue Jul 26, 2023
Backport #26134 by @wxiaoguang

Fix #26035

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2023
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
…o-gitea#26149)

Backport go-gitea#26134 by @wxiaoguang

Fix go-gitea#26035

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
(cherry picked from commit a8445e9)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants