Skip to content

Commit 35f2fad

Browse files
authored
Update handler.go
1 parent 0fa0b6b commit 35f2fad

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

server/v2/api/swagger/handler.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
1717
w.Header().Set("Access-Control-Allow-Origin", "*")
1818
w.Header().Set("Access-Control-Allow-Methods", "GET")
1919

20+
// Add security headers
21+
w.Header().Set("X-Content-Type-Options", "nosniff")
22+
w.Header().Set("X-Frame-Options", "DENY")
23+
w.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'")
24+
2025
if r.Method == http.MethodOptions {
2126
return
2227
}
@@ -27,15 +32,15 @@ func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2732
urlPath = "/index.html"
2833
}
2934

30-
// Basic path validation
31-
if strings.Contains(urlPath, "..") || strings.Contains(urlPath, "//") {
35+
// Clean the path before validation
36+
urlPath = filepath.Clean(urlPath)
37+
38+
// Validate path before any operations
39+
if strings.Contains(urlPath, "..") || strings.Contains(urlPath, "//") || strings.Contains(urlPath, "\\") {
3240
http.Error(w, "Invalid path", http.StatusBadRequest)
3341
return
3442
}
3543

36-
// Clean the path
37-
urlPath = filepath.Clean(urlPath)
38-
3944
// Open the file
4045
file, err := h.swaggerFS.Open(urlPath)
4146
if err != nil {

0 commit comments

Comments
 (0)