mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
f4240bb8c1
Workspace agent logs could still fail after the earlier invalid UTF-8 fix because NUL bytes are valid Go/protobuf strings but are rejected by Postgres text columns. The legacy HTTP log upload path also bypassed the old sanitization entirely, and both server insert paths computed logs_length from the unsanitized input. Add a shared log-output sanitizer in agentsdk, use it in the protobuf conversion path and both server-side insert paths, and compute OutputLength from the sanitized string so overflow accounting matches what is actually stored. This keeps the old invalid UTF-8 behavior while also handling embedded NUL bytes consistently across DRPC and HTTP log ingestion. Refs [#23292 ](https://github.com/coder/coder/issues/23292) Refs [#13433 ](https://github.com/coder/coder/issues/13433)
12 lines
357 B
Go
12 lines
357 B
Go
package agentsdk
|
|
|
|
import "strings"
|
|
|
|
// SanitizeLogOutput replaces invalid UTF-8 and NUL characters in log output.
|
|
// Invalid UTF-8 cannot be transported in protobuf string fields, and PostgreSQL
|
|
// rejects NUL bytes in text columns.
|
|
func SanitizeLogOutput(s string) string {
|
|
s = strings.ToValidUTF8(s, "❌")
|
|
return strings.ReplaceAll(s, "\x00", "❌")
|
|
}
|