@@ -17,6 +17,11 @@ func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
17
17
w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
18
18
w .Header ().Set ("Access-Control-Allow-Methods" , "GET" )
19
19
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
+
20
25
if r .Method == http .MethodOptions {
21
26
return
22
27
}
@@ -27,15 +32,15 @@ func (h *swaggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
27
32
urlPath = "/index.html"
28
33
}
29
34
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 , "\\ " ) {
32
40
http .Error (w , "Invalid path" , http .StatusBadRequest )
33
41
return
34
42
}
35
43
36
- // Clean the path
37
- urlPath = filepath .Clean (urlPath )
38
-
39
44
// Open the file
40
45
file , err := h .swaggerFS .Open (urlPath )
41
46
if err != nil {
0 commit comments