Skip to content

Commit 28401c1

Browse files
Potential fix for code scanning alert no. 132: Log entries created from user input
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent cd47e5f commit 28401c1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/ollama/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ func (h *Handler) unloadModel(ctx context.Context, w http.ResponseWriter, modelN
448448
return
449449
}
450450

451-
h.log.Infof("unloadModel: sending POST /engines/unload with body: %s", string(reqBody))
451+
// Sanitize the user-provided request body before logging to avoid log injection
452+
safeReqBody := strings.ReplaceAll(string(reqBody), "\n", "")
453+
safeReqBody = strings.ReplaceAll(safeReqBody, "\r", "")
454+
h.log.Infof("unloadModel: sending POST /engines/unload with body: %s", safeReqBody)
452455

453456
// Create a new request to the scheduler
454457
newReq, err := http.NewRequestWithContext(ctx, "POST", "/engines/unload", strings.NewReader(string(reqBody)))

0 commit comments

Comments
 (0)