cmd/age: reject invalid UTF-8 terminal output

Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
Filippo Valsorda
2026-08-29 19:30:10 +02:00
parent 3604609d98
commit de96c8e8e1
+2 -1
View File
@@ -19,6 +19,7 @@ import (
"slices"
"strings"
"unicode"
"unicode/utf8"
"filippo.io/age"
"filippo.io/age/agessh"
@@ -295,7 +296,7 @@ func main() {
// Buffer the output to check it's printable.
out = buf
defer func() {
if bytes.ContainsFunc(buf.Bytes(), func(r rune) bool {
if !utf8.Valid(buf.Bytes()) || bytes.ContainsFunc(buf.Bytes(), func(r rune) bool {
return r != '\n' && r != '\r' && r != '\t' && unicode.IsControl(r)
}) {
errorWithHint("refusing to output binary to the terminal",