An open-source, faster Devin alternative
TypeScript
fix: validate session belongs to sandbox before allowing access (IDOR)
motatoes6f3a56cc3d02
diff --git a/internal/api/agent_session.go b/internal/api/agent_session.goindex e5019905..bb97f60b 100644--- a/internal/api/agent_session.go+++ b/internal/api/agent_session.go@@ -127,6 +127,7 @@ func (s *Server) sendAgentPrompt(c echo.Context) error {return c.JSON(http.StatusServiceUnavailable, errSandboxNotAvailable)}+ id := c.Param("id")sessionID := c.Param("sid")var req types.AgentPromptRequest@@ -142,6 +143,10 @@ func (s *Server) sendAgentPrompt(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if session.StdinWriter == nil {return c.JSON(http.StatusInternalServerError, map[string]string{"error": "session stdin not available"})}@@ -161,6 +166,7 @@ func (s *Server) interruptAgent(c echo.Context) error {return c.JSON(http.StatusServiceUnavailable, errSandboxNotAvailable)}+ id := c.Param("id")sessionID := c.Param("sid")session, err := s.execSessionManager.GetSession(sessionID)@@ -168,6 +174,10 @@ func (s *Server) interruptAgent(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if session.StdinWriter == nil {return c.JSON(http.StatusInternalServerError, map[string]string{"error": "session stdin not available"})}diff --git a/internal/api/exec_session.go b/internal/api/exec_session.goindex 8dd8a6a7..889f44d5 100644--- a/internal/api/exec_session.go+++ b/internal/api/exec_session.go@@ -94,6 +94,10 @@ func (s *Server) execSessionWebSocket(c echo.Context) error {})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if s.router != nil {s.router.Touch(id)}diff --git a/internal/api/pty.go b/internal/api/pty.goindex b7ecd096..fadc6dda 100644--- a/internal/api/pty.go+++ b/internal/api/pty.go@@ -82,6 +82,10 @@ func (s *Server) ptyWebSocket(c echo.Context) error {})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil)if err != nil {return errdiff --git a/internal/worker/handlers.go b/internal/worker/handlers.goindex 523f4596..322e5516 100644--- a/internal/worker/handlers.go+++ b/internal/worker/handlers.go@@ -134,6 +134,10 @@ func (s *HTTPServer) execSessionWebSocket(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if s.router != nil {s.router.Touch(id)}@@ -454,6 +458,10 @@ func (s *HTTPServer) ptyWebSocket(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+// Touch to reset rolling timeout when PTY connectsif s.router != nil {s.router.Touch(id)@@ -672,6 +680,7 @@ func (s *HTTPServer) sendAgentPrompt(c echo.Context) error {return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "exec sessions not available"})}+ id := c.Param("id")sessionID := c.Param("sid")var req types.AgentPromptRequest@@ -687,6 +696,10 @@ func (s *HTTPServer) sendAgentPrompt(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if session.StdinWriter == nil {return c.JSON(http.StatusInternalServerError, map[string]string{"error": "session stdin not available"})}@@ -706,6 +719,7 @@ func (s *HTTPServer) interruptAgent(c echo.Context) error {return c.JSON(http.StatusServiceUnavailable, map[string]string{"error": "exec sessions not available"})}+ id := c.Param("id")sessionID := c.Param("sid")session, err := s.execSessionManager.GetSession(sessionID)@@ -713,6 +727,10 @@ func (s *HTTPServer) interruptAgent(c echo.Context) error {return c.JSON(http.StatusNotFound, map[string]string{"error": err.Error()})}+ if session.SandboxID != id {+ return c.JSON(http.StatusNotFound, map[string]string{"error": "session not found"})+ }+if session.StdinWriter == nil {return c.JSON(http.StatusInternalServerError, map[string]string{"error": "session stdin not available"})}