netlify / git-gateway

A Gateway to Git APIs
MIT License
400 stars 89 forks source link

fix file/directory target path not in encoded form #52

Closed artemtech closed 3 years ago

artemtech commented 4 years ago

Fix #44 .

The idea is based on GitLab API specification that need "%2F" in repository subfolders and repository name. let say we have these scenario:

  1. GITGATEWAY_GITLAB_REPO=artemtech/play-netlifycms (in .env file), and
  2. We will looking for content/post/2015-01-04-first-post.md file

in gitlab.go, these repo will be encoded into artemtech%2Fplay-netlifycms. But, the repository contents is not encoded as well (not in %2F form), see:
/gitlab.com/api/v4/projects/artemtech%2Fplay-netlifycms/repository/files/content/post/2015-01-04-first-post.md/raw

we need to encode content/post/2015-01-04-first-post.md part, into content%2Fpost%2F2015-01-04-first-post.md.

so the Opaque URL will become: /gitlab.com/api/v4/projects/artemtech%2Fplay-netlifycms/repository/files/content%2Fpost%2F2015-01-04-first-post.md/raw

mraerino commented 4 years ago

hey netlify folks! if anyone is going to merge this, please make sure it still works in our infra by testing on staging. This we are important because we are not observing #44 and I wonder why.

heopz-vpf commented 4 years ago

Hello. Thanks @artemtech. Im try, and it works perfect for recieving files, but when im trying to delete from admin panel, this link again generates without %2F and of course 404 eror

artemtech commented 4 years ago

@heopz-vpf would you please to test it out again, i've tested it in my setup and it working now.

heopzzz commented 4 years ago

Thanks @artemtech ! It works perfect now.

artemtech commented 4 years ago

thanks @lbischof ! your suggestion also works in my setup and we can do sorting our posts ^^

craig0990 commented 4 years ago

Came across this issue recently, and running docker build against the forked branch in this PR fixed the issue immediately for me. Would be great if I could run upstream instead of a fork :)

erezrokah commented 4 years ago

Sorry for the delay reviewing this. We'll try to follow up on this next week. I would add small comment on the code, that I think it is better to add some unit tests for this scenario - it would make it easier for us to reproduce the issue.

LorenzBischof commented 3 years ago

This is not needed. The correct Apache configuration is described here: https://stackoverflow.com/a/9933890

I fixed this by adding nocanon to the ProxyPass. I also added AllowEncodedSlashes NoDecode, because otherwise Apache returns a 404 error.

mraerino commented 3 years ago

@artemtech can you close this issue if you're able to fix this in your webserver config?

artemtech commented 3 years ago

This is not needed. The correct Apache configuration is described here: https://stackoverflow.com/a/9933890

I fixed this by adding nocanon to the ProxyPass. I also added AllowEncodedSlashes NoDecode, because otherwise Apache returns a 404 error.

ah i see,

in webserver view, your approach also worked in my nginx setup, by doing some rewrite url like this: https://serverfault.com/a/906479

i think i should open issue in this repo: https://github.com/hfte/netlify-cms-with-selfhosted-gotrue-and-git-gateway , because i followed that deploy journey :)

this is my rewrite config in my nginx setup:

location /.netlify/git/ {
        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        rewrite ^ $request_uri;
        rewrite ^/.netlify/git(/.*) $1 break;
        return 400;
        proxy_pass http://gitgateway$uri;
    }

thanks all, will close this PR @mraerino