mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
fix(notify): keep untrusted Telegram fields on one line
Slack flattens titles, types and assets with OneLine so a newline in an untrusted field cannot forge another line (TestSlackKeepsUntrustedFieldsOnOneLine). Telegram did not: a finding named "a\n2. Critical · fake entry" added a forged entry to a digest, and a newline in the vulnerability class or an asset added a forged line to a single notification. Flatten the digest line and the Type and Assets fields the same way.
This commit is contained in:
1 parent
2f065a958e
commit
cda87d8dfc
2 files changed
+29
-3
No files matched your search
@@ -522,3 +522,24 @@ func TestPermanentErrorUnwrap(t *testing.T) {
|
||||
type permanentSentinel struct{}
|
||||
|
||||
func (*permanentSentinel) Error() string { return "sentinel" }
|
||||
|
||||
func TestTelegramKeepsUntrustedFieldsOnOneLine(t *testing.T) {
|
||||
single := Message{Items: []Item{{
|
||||
Severity: "high",
|
||||
Name: "title",
|
||||
VulnClass: "c\nFake: x",
|
||||
Assets: []string{"h\nq"},
|
||||
}}}
|
||||
text, _ := telegramHTML(single)
|
||||
for _, forged := range []string{"\nFake", "\nq"} {
|
||||
if strings.Contains(text, forged) {
|
||||
t.Errorf("untrusted newline forged a line %q in %q", forged, text)
|
||||
}
|
||||
}
|
||||
digest := batchMsg(1)
|
||||
digest.Items[0].Name = "a\n2. Critical · fake entry"
|
||||
text, _ = telegramHTML(digest)
|
||||
if strings.Contains(text, "\n2. Critical") {
|
||||
t.Errorf("untrusted newline forged a digest entry in %q", text)
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -149,9 +149,9 @@ func telegramHTML(m Message) (string, int) {
|
||||
telegramEscape(StatusLabel(it.FromStatus)), telegramEscape(StatusLabel(it.ToStatus))))
|
||||
}
|
||||
if it.VulnClass != "" && it.VulnClass != it.Title() {
|
||||
b.WriteString("\n<b>Type</b>: " + telegramEscape(it.VulnClass))
|
||||
b.WriteString("\n<b>Type</b>: " + telegramEscape(OneLine(it.VulnClass, 0)))
|
||||
}
|
||||
if a := assetLine(it.Assets, lim.AssetsShown); a != "" {
|
||||
if a := OneLine(assetLine(it.Assets, lim.AssetsShown), 0); a != "" {
|
||||
b.WriteString("\n<b>Assets</b>: " + telegramEscape(a))
|
||||
}
|
||||
if s := OneLine(it.Summary, lim.SummaryRunes); s != "" {
|
||||
@@ -168,8 +168,13 @@ func telegramHTML(m Message) (string, int) {
|
||||
const telegramReservedRunes = 160
|
||||
|
||||
// telegramBatchLine renders one entry of a digest (unescaped; the caller escapes
|
||||
// it uniformly).
|
||||
// it uniformly). It is flattened to one line, so a newline in an untrusted
|
||||
// title or asset cannot forge another digest entry.
|
||||
func telegramBatchLine(it Item, idx int, lim Limits) string {
|
||||
return OneLine(telegramBatchLineRaw(it, idx, lim), 0)
|
||||
}
|
||||
|
||||
func telegramBatchLineRaw(it Item, idx int, lim Limits) string {
|
||||
if a := assetLine(it.Assets, lim.AssetsShown); a != "" {
|
||||
return fmt.Sprintf("%d. %s · %s — %s", idx, SeverityLabel(it.Severity), it.Title(), a)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user