security: prevent Jupyter token exposure in logs

- Add stripTokenFromURL() helper function to remove tokens from URLs
- Use it when logging service start URLs
- Use it when logging connectivity test URLs
- Prevents sensitive tokens from being written to log files
This commit is contained in:
Jeremie Fraeys 2026-02-18 16:11:50 -05:00
parent a64233d4f6
commit 6446379a40
No known key found for this signature in database
2 changed files with 14 additions and 2 deletions

View file

@ -340,7 +340,7 @@ func (nm *NetworkManager) TestConnectivity(_ context.Context, config *NetworkCon
}
}()
nm.logger.Info("connectivity test passed", "url", url)
nm.logger.Info("connectivity test passed", "url", stripTokenFromURL(url))
return nil
}

View file

@ -14,6 +14,18 @@ import (
"github.com/jfraeys/fetch_ml/internal/logging"
)
// stripTokenFromURL removes the token query parameter from a URL for safe logging
func stripTokenFromURL(url string) string {
idx := strings.Index(url, "?token=")
if idx == -1 {
idx = strings.Index(url, "&token=")
}
if idx != -1 {
return url[:idx]
}
return url
}
const (
serviceStatusRunning = "running"
defaultWorkspaceBase = "/data/active/workspaces"
@ -451,7 +463,7 @@ func (sm *ServiceManager) StartService(
sm.logger.Info("jupyter service started",
"service_id", serviceID,
"name", req.Name,
"url", url,
"url", stripTokenFromURL(url),
"workspace", req.Workspace)
return service, nil