Skip to content

Sign in not possible behind tinyproxy with sub-path #31202

Closed
@LauKr

Description

@LauKr

Description

Running Gitea behind a Reverse Proxy using a sub-path doesn't allow login.
This issue was first occurring with the update 1.21.10 -> 1.21.11 and
continues with 1.22.0.

After entering credentials and pressing the "Sign In" button, the
unauthenticated "root" site is shown again, like after a logout.

From the release notes
we noted the following change which seems suspicious:

Fix to delete the cookie when AppSubURL is non-empty (#30375) (#30468)

Therefore, we checked our configurations and ensured, they used trailing slashes:

$ grep -r "git-staging" /etc/gitea-staging /etc/tinyproxy/ 
/etc/gitea-staging/app.ini:ROOT_URL = https://192.168.1.12/git-staging/
/etc/tinyproxy/tinyproxy.conf:ReversePath "/git-staging/" "http://127.0.0.1:3333/"

The logs from our reverse proxy show a behavior as requested by the
documentation:

May 29 16:16:31 debian-git tinyproxy[390434]: Connect (file descriptor 5): 127.0.0.1
May 29 16:16:31 debian-git tinyproxy[390434]: Request (file descriptor 5): POST /git-staging/user/login HTTP/1.1
May 29 16:16:31 debian-git tinyproxy[390434]: Rewriting URL: /git-staging/user/login -> http://127.0.0.1:3333/user/login
May 29 16:16:31 debian-git tinyproxy[390434]: No upstream proxy for 127.0.0.1
May 29 16:16:31 debian-git tinyproxy[390434]: opensock: opening connection to 127.0.0.1:3333
May 29 16:16:31 debian-git tinyproxy[390434]: opensock: getaddrinfo returned for 127.0.0.1:3333
May 29 16:16:31 debian-git tinyproxy[390434]: Established connection to host "127.0.0.1" using file descriptor 6.
May 29 16:16:31 debian-git tinyproxy[390434]: Closed connection between local client (fd:5) and remote client (fd:6)
May 29 16:16:31 debian-git tinyproxy[390434]: Connect (file descriptor 5): 127.0.0.1
May 29 16:16:31 debian-git tinyproxy[390434]: Request (file descriptor 5): GET /git-staging/ HTTP/1.1
May 29 16:16:31 debian-git tinyproxy[390434]: Rewriting URL: /git-staging/ -> http://127.0.0.1:3333/
May 29 16:16:31 debian-git tinyproxy[390434]: No upstream proxy for 127.0.0.1
May 29 16:16:31 debian-git tinyproxy[390434]: opensock: opening connection to 127.0.0.1:3333
May 29 16:16:31 debian-git tinyproxy[390434]: opensock: getaddrinfo returned for 127.0.0.1:3333
May 29 16:16:31 debian-git tinyproxy[390434]: Established connection to host "127.0.0.1" using file descriptor 6.
May 29 16:16:31 debian-git tinyproxy[390434]: Closed connection between local client (fd:5) and remote client (fd:6)

We see the equivalent to

Make the reverse-proxy pass https://common.example.com/gitea/foo to http://gitea:3000/foo

Rewriting URL: /git-staging/user/login -> http://127.0.0.1:3333/user/login

The corresponding Gitea logs are:

May 29 16:53:07 debian-git gitea[390439]: 2024/05/29 16:53:07 ...eb/routing/logger.go:102:func1() [I] router: completed POST /user/login for 127.0.0.1:56322, 303 See Other in 68.6ms @ auth/auth.go:196(auth.SignInPost)
May 29 16:53:07 debian-git gitea[390439]: 2024/05/29 16:53:07 .../context_response.go:70:HTML() [D] Template: home
May 29 16:53:07 debian-git gitea[390439]: 2024/05/29 16:53:07 ...eb/routing/logger.go:102:func1() [I] router: completed GET / for 127.0.0.1:56324, 200 OK in 3.6ms @ web/home.go:32(web.Home)

Access logs in Gitea:

127.0.0.1 - - [29/May/2024:16:52:57 +0200] "GET /user/login HTTP/1.1" 200 10629 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
127.0.0.1 - - [29/May/2024:16:53:00 +0200] "POST /user/login HTTP/1.1" 303 0 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
127.0.0.1 - - [29/May/2024:16:53:00 +0200] "GET / HTTP/1.1" 200 14214 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
127.0.0.1 - - [29/May/2024:16:53:02 +0200] "GET /user/login?redirect_to=%2fgit-staging%2f HTTP/1.1" 200 10629 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
127.0.0.1 - - [29/May/2024:16:53:07 +0200] "POST /user/login HTTP/1.1" 303 0 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"
127.0.0.1 - - [29/May/2024:16:53:07 +0200] "GET / HTTP/1.1" 200 14214 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0"

Resolving

After reverting commit b18c04e (and commenting
out two sections undefined afterwards, see patch), we are able to use the normal
login again, when using our custom built binary. Thus, this also shows that our
error is connected to this change.

Gitea Version

1.21.11 and 1.22.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.39.2

Operating System

Debian Bookworm

How are you running Gitea?

The binary is pulled from the official server. Execution is happening through systemd on Debian 6.1.85-1 (2024-04-11) 86_64.
The Gitea server is listening locally via HTTP and is served by a tinyproxy reverse proxy. TLS is terminated by stunnel in front of tinyproxy.

Database

SQLite

Metadata

Metadata

Assignees

Labels

issue/needs-feedbackFor bugs, we need more details. For features, the feature must be described in more detailissue/not-a-bugThe reported issue is the intended behavior or the problem is not inside Gitea

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions