Skip to content

Commit b604758

Browse files
committed
fix(realtime): clean TTS temp path before read (gosec G304)
emitSpeech reads the WAV file the TTS backend wrote. The read moved here from realtime.go, so code-scanning flagged it as a new G304 alert even though the path is backend-controlled (a temp file), not user input. Wrap it in filepath.Clean — a real path normalization that also clears the alert, keeping with the repo's no-#nosec convention. Assisted-by: Claude:claude-opus-4-8 gosec, golangci-lint Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent a368c97 commit b604758

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

core/http/endpoints/openai/realtime_speech.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"fmt"
77
"os"
8+
"path/filepath"
89

910
"github.com/mudler/LocalAI/core/http/endpoints/openai/types"
1011
laudio "github.com/mudler/LocalAI/pkg/audio"
@@ -84,7 +85,9 @@ func emitSpeech(ctx context.Context, t Transport, session *Session, responseID,
8485
}
8586
defer func() { _ = os.Remove(audioFilePath) }()
8687

87-
audioBytes, err := os.ReadFile(audioFilePath)
88+
// filepath.Clean normalizes the backend-produced temp path before reading
89+
// (also keeps gosec G304 quiet — the path is backend-controlled, not user input).
90+
audioBytes, err := os.ReadFile(filepath.Clean(audioFilePath))
8891
if err != nil {
8992
return nil, fmt.Errorf("read tts audio: %w", err)
9093
}

0 commit comments

Comments
 (0)