Skip to content

Commit

Permalink
Add notification template without escaping (#18171)
Browse files Browse the repository at this point in the history
* plaintext template

* remove HTML output format config

* CL

* revert plaintext; render title as HTML in FE

* revert Intellij formatting changes
  • Loading branch information
patrickmann authored Mar 7, 2024
1 parent c12d919 commit 6c7d2c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/pr-18171.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type = "f"
message = "Fix unintended HTML-escaping in system notification messages."

issues = ["Graylog2/graylog-plugin-enterprise#6525"]
pulls = ["18171"]

Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,22 @@ void missingTemplates() {
});
}
}

@Test
void htmlEscapingWithSubstitutionTest() {
notification = new NotificationImpl()
.addNode("node")
.addType(Notification.Type.GENERIC)
.addDetail("title", "Test: <123>")
.addDetail("description", "Test: <abc>")
.addTimestamp(DateTime.now(DateTimeZone.UTC));
when(notificationService.getByTypeAndKey(any(), any())).thenReturn(Optional.of(notification));

SystemNotificationRenderService.RenderResponse renderResponse =
renderService.render(notification.getType(), null, SystemNotificationRenderService.Format.HTML, null);

// HTML-escaping applied
assertThat(renderResponse.title).contains("Test: &lt;123&gt;");
assertThat(renderResponse.description).contains("Test: &lt;abc&gt");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ const Notification = ({ notification }: Props) => {
<StyledAlert bsStyle="danger"
title={(
<>
{message.title}{' '}

<div dangerouslySetInnerHTML={{__html: _sanitizeDescription(message?.title)}} />
<NotificationTimestamp>
(triggered <RelativeTime dateTime={notification.timestamp} />)
</NotificationTimestamp>
Expand Down

0 comments on commit 6c7d2c4

Please sign in to comment.