Modify Content-Security-Policy for Swagger UI (#63568)
* Modify Content-Security-Policy for Swagger UI * check if CSP is empty Co-authored-by: João Calisto <joao.calisto@grafana.com> * check if CSP is empty in swagger.go --------- Co-authored-by: João Calisto <joao.calisto@grafana.com> Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
João Calisto
Sofia Papagiannaki
parent
1869da1d86
commit
9b4dde7430
+12
-1
@@ -2,10 +2,21 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
func openapi3(c *contextmodel.ReqContext) {
|
||||
c.HTML(http.StatusOK, "openapi3", nil)
|
||||
data := map[string]interface{}{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "openapi3", data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user