Skip to content

Agent Mesh

security: harden console cookies and sambox interceptor path

Antonio Ojea713dc72b655a
diff --git a/internal/console/server.go b/internal/console/server.go
index b1d5030a..4ca37e11 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -284,10 +284,13 @@ func (s *Server) Handler() http.Handler {
func (s *Server) HandleLogout(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
- Name: "sam_session",
- Value: "",
- Path: s.cfg.BasePath + "/",
- MaxAge: -1,
+ Name: "sam_session",
+ Value: "",
+ Path: s.cfg.BasePath + "/",
+ MaxAge: -1,
+ HttpOnly: true,
+ Secure: s.secureCookies(r),
+ SameSite: http.SameSiteLaxMode,
})
http.Redirect(w, r, s.cfg.BasePath+"/", http.StatusFound)
}
@@ -356,8 +359,8 @@ func (s *Server) HandleCallback(w http.ResponseWriter, r *http.Request) {
return
}
- http.SetCookie(w, &http.Cookie{Name: "sam_oidc_state", Value: "", Path: s.cfg.BasePath + "/", MaxAge: -1})
- http.SetCookie(w, &http.Cookie{Name: "sam_oidc_verifier", Value: "", Path: s.cfg.BasePath + "/", MaxAge: -1})
+ http.SetCookie(w, &http.Cookie{Name: "sam_oidc_state", Value: "", Path: s.cfg.BasePath + "/", MaxAge: -1, HttpOnly: true, Secure: s.secureCookies(r), SameSite: http.SameSiteLaxMode})
+ http.SetCookie(w, &http.Cookie{Name: "sam_oidc_verifier", Value: "", Path: s.cfg.BasePath + "/", MaxAge: -1, HttpOnly: true, Secure: s.secureCookies(r), SameSite: http.SameSiteLaxMode})
code := r.URL.Query().Get("code")
if code == "" {
diff --git a/internal/sambox/gateway.go b/internal/sambox/gateway.go
index 2b9ebc65..6688d366 100644
--- a/internal/sambox/gateway.go
+++ b/internal/sambox/gateway.go
@@ -397,7 +397,8 @@ func (g *Gateway) handleHTTPConnection(conn *bufferedConn, tlsListener *channelL
filename = "libinterceptor.so"
}
- filePath := filepath.Join(g.InterceptorsDir, filename)
+ // isValidIdentifier already forbids path separators; Base is defense in depth.
+ filePath := filepath.Join(g.InterceptorsDir, filepath.Base(filename))
fileData, err := os.ReadFile(filePath)
if err != nil && filename != "libinterceptor.so" {
filePath = filepath.Join(g.InterceptorsDir, "libinterceptor.so")