Skip to content

Repository Archive API does not process URL Format Parameter correctly

Summary

When accessing the archive ressource at https://[GitLab Instance URL]/api/v4/projects/:id/repository/archive the format URL parameter is not being processed correctly.

Steps to reproduce

Issue a GET request to https://[GitLab Instance URL]/api/v4/projects/:id/repository/archive?format=:format

Where :id is the ProjectID of any Project you have access to and :format is any of the supported formats listed here.

Example Project

Example: https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-ce/repository/archive?format=tar.gz

What is the current bug behavior?

The Server replies with HTTP-Status Code 406 and the following error message: {"error":"The requested format ':format' is not supported."}

For the example this error text is: {"error":"The requested format 'tar.gz' is not supported."} (Which is ironic since tar.gz is the default format which you get if you ommit the parameter)

What is the expected correct behavior?

The Server should provide the repository archive in the requested format.

Relevant logs and/or screenshots

Output from gitlab-ctl tail:

==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/api/v4/projects/20/repository/archive?format=zip" for xxx.xxx.xxx.xxx at 2018-05-02 23:34:53 +0200

==> /var/log/gitlab/gitlab-rails/api_json.log <==
{"time":"2018-05-02T21:34:53.542Z","severity":"INFO","duration":0.4,"db":0.0,"view":0.4,"status":406,"method":"GET","path":"/api/v4/projects/20/repository/archive","params":{"format":"zip"},"host":"lab.domain.com","ip":"xxx.xxx.xxx.xxx, 127.0.0.1","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"}

==> /var/log/gitlab/gitlab-workhorse/current <==
2018-05-02_21:34:53.59216 lab.domain.com 127.0.0.1:55130 - - [2018/05/02:23:34:53 +0200] "GET /api/v4/projects/20/repository/archive?format=zip HTTP/1.1" 406 56 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" 0.081

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

This bug happens on GitLab.com

Results of GitLab application Check

This bug happens on GitLab.com

Possible fixes

Not totally sure, but this might be a starting point to look at. The format parameter seems to not be passed on correctly from rails. https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/api/repositories.rb#L89

Additonal Information

This Issue has allready been reported and closed down due to lack of activity at: https://gitlab.com/gitlab-com/support-forum/issues/3067

I have also taken the time to test each of the allowed format parameters, the result is the same for each of them. The format parameter can still be provided as a header field and works as intended.

Another workaround is to request .../archive.:format instead of .../archive?format=:format.
Example: https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab-ce/repository/archive.zip

Edited by FatalMerlin