File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -28,13 +28,25 @@ import (
28
28
// HTTP implmentation git smart HTTP protocol
29
29
func HTTP (ctx * context.Context ) {
30
30
if len (setting .Repository .AccessControlAllowOrigin ) > 0 {
31
+ allowedOrigin := setting .Repository .AccessControlAllowOrigin
31
32
// Set CORS headers for browser-based git clients
32
- ctx .Resp .Header ().Set ("Access-Control-Allow-Origin" , setting . Repository . AccessControlAllowOrigin )
33
+ ctx .Resp .Header ().Set ("Access-Control-Allow-Origin" , allowedOrigin )
33
34
ctx .Resp .Header ().Set ("Access-Control-Allow-Headers" , "Content-Type, Authorization, User-Agent" )
34
35
35
36
// Handle preflight OPTIONS request
36
37
if ctx .Req .Method == "OPTIONS" {
37
- ctx .Status (http .StatusOK )
38
+ if allowedOrigin == "*" {
39
+ ctx .Status (http .StatusOK )
40
+ } else if allowedOrigin == "null" {
41
+ ctx .Status (http .StatusForbidden )
42
+ } else {
43
+ origin := ctx .Req .Header .Get ("Origin" )
44
+ if len (origin ) > 0 && origin == allowedOrigin {
45
+ ctx .Status (http .StatusOK )
46
+ } else {
47
+ ctx .Status (http .StatusForbidden )
48
+ }
49
+ }
38
50
return
39
51
}
40
52
}
You can’t perform that action at this time.
0 commit comments