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

WebGUI: Escape character in folder or file name prevents access #17938

Closed
2 of 6 tasks
sebveit opened this issue Dec 9, 2021 · 4 comments · Fixed by #17997 or #18086
Closed
2 of 6 tasks

WebGUI: Escape character in folder or file name prevents access #17938

sebveit opened this issue Dec 9, 2021 · 4 comments · Fixed by #17997 or #18086
Labels

Comments

@sebveit
Copy link

sebveit commented Dec 9, 2021

  • Gitea version (or commit ref): 1.15.7 built with GNU Make 4.1, go1.16.10 : bindata, sqlite, sqlite_unlock_notify
  • Git version: 2.30.2
  • Operating system: Debian GNU/Linux 11 (bullseye)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:

Description

I've cloned a repository from GitHub that uses the percentage character (%) in file and folder names a lot. This %-char prevents the access, via the web GUI of Gitea, to the file or folder containing this char in its name.
It looks like Gitea is displaying the %-char correctly but fails to provide the correct URL when clicking on it.
When I modify the URL and try to access it, nginx answers with 400 Bad Request.

Example

Expected URL: https://try.gitea.io/sebveit/meta-openwrt/src/branch/master/recipes-tweaks/busybox/busybox_%.bbappend
Actual URL: https://try.gitea.io/sebveit/meta-openwrt/src/branch/master/recipes-tweaks/busybox/busybox_%25.bbappend

Reverse Proxy

I'm using nginx (1.18) as a reverse proxy for Gitea. My config for nginx is the following:

server {
    listen 443 ssl;
    server_name gitea.somedomain.tld;
    ssl_certificate     /etc/nginx/ssl/gitea.somedomain.tld.crt;
    ssl_certificate_key /etc/nginx/ssl/gitea.somedomain.tld.key;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 50M;
    }
}

I hope that helps pinpointing the bug. Let me know if you need additional information.
BTW, Gitea is really nice and slim compared to the bloated GitLab.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Dec 9, 2021

Maybe this is a bug for path processing. However Expected URL busybox_%.bbappend is not correct, either. Non-standard characters should be encoded due to RFC.

Unfortunately, at this moment, the URL can open the target is:

https://try.gitea.io/sebveit/meta-openwrt/src/branch/master/recipes-tweaks/busybox/busybox_%2525.bbappend

I am not sure it is correct or not. @zeripath can you help to take a look for this?

@zeripath
Copy link
Contributor

zeripath commented Dec 15, 2021

OK so this used to work in 1.14.7 but is broken from 1.15.0

This is going to be related to the chi migration.

@zeripath
Copy link
Contributor

This is interesting the ctx.Params("*") appears to be "" even though the requestURI is correct...

@zeripath
Copy link
Contributor

zeripath commented Dec 15, 2021

Right the problem is:

s, _ := url.PathUnescape(chi.URLParam(ctx.Req, strings.TrimPrefix(p, ":")))

This is double unescaping the Params("*") value.

Now I need to double check that this is always the case.


Yup it is.

Therefore we should just drop this.


Nope that's not the solution.

The problem is with the routeParams.

I think I've solved this now.

zeripath added a commit to zeripath/gitea that referenced this issue Dec 15, 2021
There was an unfortunate regression in go-gitea#14293 which has led to the double decoding
of url parameter elements if they contain a '%'. This is due to an issue
with the way chi decodes its RoutePath. In detail the problem lies in
mux.go where the routeHTTP path uses the URL.RawPath or even the
URL.Path instead of the escaped path to do routing.

This PR simply forcibly sets the routePath to that of the EscapedPath.

Fix go-gitea#17938

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Dec 16, 2021
There was an unfortunate regression in #14293 which has led to the double decoding
of url parameter elements if they contain a '%'. This is due to an issue
with the way chi decodes its RoutePath. In detail the problem lies in
mux.go where the routeHTTP path uses the URL.RawPath or even the
URL.Path instead of the escaped path to do routing.

This PR simply forcibly sets the routePath to that of the EscapedPath.

Fix #17938

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Dec 16, 2021
There was an unfortunate regression in go-gitea#14293 which has led to the double decoding
of url parameter elements if they contain a '%'. This is due to an issue
with the way chi decodes its RoutePath. In detail the problem lies in
mux.go where the routeHTTP path uses the URL.RawPath or even the
URL.Path instead of the escaped path to do routing.

This PR simply forcibly sets the routePath to that of the EscapedPath.

Fix go-gitea#17938

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Dec 23, 2021
A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing go-gitea#18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviours too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix go-gitea#17938
Fix go-gitea#18060
Replace go-gitea#18062
Replace go-gitea#17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
wxiaoguang pushed a commit that referenced this issue Dec 24, 2021
A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing #18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviors too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix #17938
Fix #18060
Replace #18062
Replace #17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Dec 25, 2021
…ea#18086)

Backport go-gitea#18086

A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing go-gitea#18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviors too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix go-gitea#17938
Fix go-gitea#18060
Replace go-gitea#18062
Replace go-gitea#17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Dec 26, 2021
#18098)

Backport #18086

A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing #18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviors too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix #17938
Fix #18060
Replace #18062
Replace #17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
There was an unfortunate regression in go-gitea#14293 which has led to the double decoding
of url parameter elements if they contain a '%'. This is due to an issue
with the way chi decodes its RoutePath. In detail the problem lies in
mux.go where the routeHTTP path uses the URL.RawPath or even the
URL.Path instead of the escaped path to do routing.

This PR simply forcibly sets the routePath to that of the EscapedPath.

Fix go-gitea#17938

Signed-off-by: Andrew Thornton <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…ea#18086)

A consequence of forcibly setting the RoutePath to the escaped url is that the
auto routing to endpoints without terminal slashes fails (Causing go-gitea#18060.) This
failure raises the possibility that forcibly setting the RoutePath causes other
unexpected behaviors too.

Therefore, instead we should simply pre-escape the URL in the process registering
handler. Then the request URL will be properly escaped for all the following calls.

Fix go-gitea#17938
Fix go-gitea#18060
Replace go-gitea#18062
Replace go-gitea#17997

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants