mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
fix: removed direct access to static folders
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -74,6 +75,12 @@ func GetLogout(w http.ResponseWriter, r *http.Request) {
|
|||||||
func StaticFileServerWithContentType(fsys http.FileSystem) http.Handler {
|
func StaticFileServerWithContentType(fsys http.FileSystem) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
|
filePath := filepath.Join("api/static", r.URL.Path)
|
||||||
|
fileInfo, err := os.Stat(filePath)
|
||||||
|
if err == nil && fileInfo.IsDir() {
|
||||||
|
http.Error(w, "Folder direct access is disabled.", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
if ext := filepath.Ext(path); ext != "" {
|
if ext := filepath.Ext(path); ext != "" {
|
||||||
if ct, ok := contentTypes[ext]; ok {
|
if ct, ok := contentTypes[ext]; ok {
|
||||||
w.Header().Set("Cache-Control", "public, max-age=31536000")
|
w.Header().Set("Cache-Control", "public, max-age=31536000")
|
||||||
|
|||||||
Reference in New Issue
Block a user