Преглед на файлове

Add proper CORS preflight origin validation (#5740)

tags/v1.9.0-dev
silverwind преди 5 години
родител
ревизия
44759fd66c
променени са 1 файла, в които са добавени 14 реда и са изтрити 2 реда
  1. 14
    2
      routers/repo/http.go

+ 14
- 2
routers/repo/http.go Целия файл

@@ -28,13 +28,25 @@ import (
// HTTP implmentation git smart HTTP protocol
func HTTP(ctx *context.Context) {
if len(setting.Repository.AccessControlAllowOrigin) > 0 {
allowedOrigin := setting.Repository.AccessControlAllowOrigin
// Set CORS headers for browser-based git clients
ctx.Resp.Header().Set("Access-Control-Allow-Origin", setting.Repository.AccessControlAllowOrigin)
ctx.Resp.Header().Set("Access-Control-Allow-Origin", allowedOrigin)
ctx.Resp.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, User-Agent")

// Handle preflight OPTIONS request
if ctx.Req.Method == "OPTIONS" {
ctx.Status(http.StatusOK)
if allowedOrigin == "*" {
ctx.Status(http.StatusOK)
} else if allowedOrigin == "null" {
ctx.Status(http.StatusForbidden)
} else {
origin := ctx.Req.Header.Get("Origin")
if len(origin) > 0 && origin == allowedOrigin {
ctx.Status(http.StatusOK)
} else {
ctx.Status(http.StatusForbidden)
}
}
return
}
}

Loading…
Отказ
Запис