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

CORS on git smart http protocol can not work on main branch #16350

Closed
1 of 6 tasks
snowyu opened this issue Jul 6, 2021 · 7 comments · Fixed by #16496
Closed
1 of 6 tasks

CORS on git smart http protocol can not work on main branch #16350

snowyu opened this issue Jul 6, 2021 · 7 comments · Fixed by #16496
Labels

Comments

@snowyu
Copy link

snowyu commented Jul 6, 2021

  • Gitea version (or commit ref): 27c1578
  • Git version: 2.25.1
  • Operating system:
    Distributor ID:	Ubuntu
    Description:	Ubuntu 20.04.2 LTS
    Release:	20.04
    Codename:	focal
    
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

This feature #5719(#5700) can not work now.

The browser say:

Access to XMLHttpRequest at 'http://localhost:3000/name/repo.git/info/refs?service=git-upload-pack' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

And the response header has nothing CORS header return.

The server report:

Completed OPTIONS /name/repo.git/info/refs?service=git-upload-pack 405 Method Not Allowed in 780.91µs

I've found it was incorrectly rejected before entering httpBase.

common = append(common, context.Contexter())

The context.Contexter() reject it.

Just add the following code before context.Contexter() to fix:

	common = append(common, CorsHandler) // added here
	// Removed: toolbox.Toolboxer middleware will provide debug informations which seems unnecessary
	common = append(common, context.Contexter())
@snowyu
Copy link
Author

snowyu commented Jul 6, 2021

It seems that the new [cors] configuration section will replace the old ACCESS_CONTROL_ALLOW_ORIGIN config.

@noerw
Copy link
Member

noerw commented Jul 10, 2021

So it works after you updated your config? In that case, please close this issue :)

Maybe related: #16100

@noerw noerw added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Jul 10, 2021
@snowyu
Copy link
Author

snowyu commented Jul 10, 2021

No,It will only work after modifying the above code.

If you have read the source code, you will find the feature of cors is the same as the ACCESS_CONTROL_ALLOW_ORIGIN config.

So I think you can deprecate the old ACCESS_CONTROL_ALLOW_ORIGIN.

@snowyu
Copy link
Author

snowyu commented Jul 10, 2021

Enh, Maybe My changes can fix the #16100.

@noerw noerw added type/bug and removed issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail labels Jul 10, 2021
@lunny
Copy link
Member

lunny commented Jul 18, 2021

Could you send a PR to fix that? I'm thinking we may should use different cors settings for smart http, api and others.

@snowyu
Copy link
Author

snowyu commented Jul 20, 2021

Ok. I've added support for CORS on most repo operations. But I have no idea how to wtite an unit test.

zeripath added a commit to zeripath/gitea that referenced this issue Jul 20, 2021
Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.

This is mostly because the OPTIONS method is not being handled by
httpBase anymore.

This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.

Fix go-gitea#16350
Close go-gitea#16491

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor

In order to provide a test it would be helpful if you could simply list the requests that lightning git would make over the smart protocol - then you would simply write a test that ensures that the appropriate headers are sent back.

Another option is to point to the smart git protocol documentation here.

lunny added a commit that referenced this issue Jul 21, 2021
Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.

This is mostly because the OPTIONS method is not being handled by
httpBase anymore.

This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.

Fix #16350
Close #16491

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
zeripath added a commit to zeripath/gitea that referenced this issue Jul 21, 2021
Backport go-gitea#16496

Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.

This is mostly because the OPTIONS method is not being handled by
httpBase anymore.

This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.

Fix go-gitea#16350
Close go-gitea#16491

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Jul 21, 2021
Backport #16496

Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.

This is mostly because the OPTIONS method is not being handled by
httpBase anymore.

This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.

Fix #16350
Close #16491

Signed-off-by: Andrew Thornton <art27@cantab.net>
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this issue Aug 10, 2021
Unfortunately the chi changes have resulted in the CORS headers for the
git smart http protocol going missing.

This is mostly because the OPTIONS method is not being handled by
httpBase anymore.

This PR adds a GetOptions, PostOptions and Options methods to web
handler to allow OPTIONS method requests to still reach the httpBase
function.

Fix go-gitea#16350
Close go-gitea#16491

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
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