mirror of
https://github.com/stashapp/stash.git
synced 2026-05-07 12:00:24 +02:00
Fix WebSocket UTF-8 error for non-UTF-8 file paths in subscriptions (#6810)
* Fix WebSocket UTF-8 error for non-UTF-8 file paths in subscriptions Sanitize log messages and job fields (description, subtasks, error) before sending over WebSocket. File paths with non-UTF-8 characters caused the browser to close the connection with "Could not decode a text frame as UTF-8." Invalid bytes are replaced with U+FFFD. Only the API response layer is affected — underlying stored data is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Replace direct ToValidUTF8 calls to new sanitiseWebsocketString function --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
parent
9b5c0b0e48
commit
f920bd8b8e
2 changed files with 23 additions and 4 deletions
|
|
@ -33,15 +33,26 @@ func (r *queryResolver) FindJob(ctx context.Context, input FindJobInput) (*Job,
|
|||
}
|
||||
|
||||
func jobToJobModel(j job.Job) *Job {
|
||||
subTasks := make([]string, len(j.Details))
|
||||
for i, t := range j.Details {
|
||||
subTasks[i] = sanitiseWebsocketString(t)
|
||||
}
|
||||
|
||||
var jobError *string
|
||||
if j.Error != nil {
|
||||
s := sanitiseWebsocketString(*j.Error)
|
||||
jobError = &s
|
||||
}
|
||||
|
||||
ret := &Job{
|
||||
ID: strconv.Itoa(j.ID),
|
||||
Status: JobStatus(j.Status),
|
||||
Description: j.Description,
|
||||
SubTasks: j.Details,
|
||||
Description: sanitiseWebsocketString(j.Description),
|
||||
SubTasks: subTasks,
|
||||
StartTime: j.StartTime,
|
||||
EndTime: j.EndTime,
|
||||
AddTime: j.AddTime,
|
||||
Error: j.Error,
|
||||
Error: jobError,
|
||||
}
|
||||
|
||||
if j.Progress != -1 {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,19 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/stashapp/stash/internal/log"
|
||||
"github.com/stashapp/stash/internal/manager"
|
||||
)
|
||||
|
||||
// sanitiseWebsocketString is used to ensure that any strings sent over the websocket are valid UTF-8.
|
||||
// Any invalid UTF-8 sequences will be replaced with the Unicode replacement character (U+FFFD).
|
||||
// Invalid UTF-8 sequences can cause the websocket connection to be closed.
|
||||
func sanitiseWebsocketString(s string) string {
|
||||
return strings.ToValidUTF8(s, "\uFFFD")
|
||||
}
|
||||
|
||||
func getLogLevel(logType string) LogLevel {
|
||||
switch logType {
|
||||
case "progress":
|
||||
|
|
@ -33,7 +41,7 @@ func logEntriesFromLogItems(logItems []log.LogItem) []*LogEntry {
|
|||
ret[i] = &LogEntry{
|
||||
Time: entry.Time,
|
||||
Level: getLogLevel(entry.Type),
|
||||
Message: entry.Message,
|
||||
Message: sanitiseWebsocketString(entry.Message),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue