Spaces:
Running
Running
Block unknown /api/* and dotfile scanner probes at Go layer
Browse files- Dockerfile +1 -0
- main.go +5 -0
Dockerfile
CHANGED
|
@@ -18,6 +18,7 @@ ENV PYTHONUNBUFFERED=1 \
|
|
| 18 |
PIP_NO_CACHE_DIR=1 \
|
| 19 |
NODE_ENV=production \
|
| 20 |
LISTEN_ADDR=:7860 \
|
|
|
|
| 21 |
FRONTEND_URL=http://127.0.0.1:3000 \
|
| 22 |
TEMP_DIR=/tmp/hf-upload
|
| 23 |
|
|
|
|
| 18 |
PIP_NO_CACHE_DIR=1 \
|
| 19 |
NODE_ENV=production \
|
| 20 |
LISTEN_ADDR=:7860 \
|
| 21 |
+
BACKEND_URL=http://127.0.0.1:7860 \
|
| 22 |
FRONTEND_URL=http://127.0.0.1:3000 \
|
| 23 |
TEMP_DIR=/tmp/hf-upload
|
| 24 |
|
main.go
CHANGED
|
@@ -302,6 +302,11 @@ func currentUser(r *http.Request) UserAccount {
|
|
| 302 |
}
|
| 303 |
|
| 304 |
func (a *App) indexUI(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
if feURL := os.Getenv("FRONTEND_URL"); feURL != "" {
|
| 306 |
if target, err := url.Parse(feURL); err == nil {
|
| 307 |
proxy := httputil.NewSingleHostReverseProxy(target)
|
|
|
|
| 302 |
}
|
| 303 |
|
| 304 |
func (a *App) indexUI(w http.ResponseWriter, r *http.Request) {
|
| 305 |
+
// Block unknown /api/* routes or scanner requests (/.env, /.git, etc.) from being proxied to Next.js
|
| 306 |
+
if strings.HasPrefix(r.URL.Path, "/api/") || r.URL.Path == "/api" || strings.Contains(r.URL.Path, "/.") {
|
| 307 |
+
writeJSON(w, http.StatusNotFound, APIError{Error: "not_found", Detail: "Endpoint không tồn tại"})
|
| 308 |
+
return
|
| 309 |
+
}
|
| 310 |
if feURL := os.Getenv("FRONTEND_URL"); feURL != "" {
|
| 311 |
if target, err := url.Parse(feURL); err == nil {
|
| 312 |
proxy := httputil.NewSingleHostReverseProxy(target)
|