-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix(CORS): CORS on git smart http protocol can not work. fixes #16350 #16491
Conversation
m.Get("/objects/info/{file:[^/]*}", CorsHandler(), repo.GetTextFile("")) | ||
m.Get("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", CorsHandler(), repo.GetLooseObject) | ||
m.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", CorsHandler(), repo.GetPackFile) | ||
m.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", CorsHandler(), repo.GetIdxFile) | ||
}, ignSignInAndCsrf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add it after ignSignInAdnCsrf
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this. But it does not work. MUST PUT CorsHandler
in first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then move the CorsHandler call first...
m.Group("", CorsHandler(), func() { ... }, ignSignInAndCsrf)
…he workaround it is, do not merge
Signed-off-by: Andrew Thornton <art27@cantab.net>
///* | ||
if setting.CORSConfig.Enabled { | ||
corsHandle := cors.Handler(cors.Options{ | ||
//Scheme: setting.CORSConfig.Scheme, // FIXME: the cors middleware needs scheme option | ||
AllowedOrigins: setting.CORSConfig.AllowDomain, | ||
//setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option | ||
AllowedMethods: setting.CORSConfig.Methods, | ||
AllowedHeaders: []string{"*"}, | ||
// OptionsPassthrough: true, | ||
Debug: true, | ||
AllowCredentials: setting.CORSConfig.AllowCredentials, | ||
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()), | ||
}) | ||
common = append(common, corsHandle) | ||
} | ||
//*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this section if you're adding it specifically below?
Codecov Report
@@ Coverage Diff @@
## main #16491 +/- ##
==========================================
+ Coverage 45.33% 45.49% +0.16%
==========================================
Files 718 718
Lines 84202 84258 +56
==========================================
+ Hits 38169 38337 +168
+ Misses 39895 39758 -137
- Partials 6138 6163 +25
Continue to review full report at Codecov.
|
@@ -60,6 +60,7 @@ func CorsHandler() func(next http.Handler) http.Handler { | |||
AllowedOrigins: setting.CORSConfig.AllowDomain, | |||
//setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option | |||
AllowedMethods: setting.CORSConfig.Methods, | |||
AllowedHeaders: []string{"*"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly we've just added the correct headers we need so in general I think this is a mistake.
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>
Please could you try #16496 instead. |
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>
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>
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>
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>
No description provided.