Skip to content

Conversation

@Christinarlong
Copy link
Contributor

@Christinarlong Christinarlong commented Nov 7, 2025

This PR adds two new "Block" types to the platform (currently just for the rendered template body)

  1. NotificationFormattingBlock
  2. NotificationTextBlock

NotificationBodyFormattingBlock - Currently is only used for "Section" blocks which are just to specify the enclosed Text blocks should be on a newline

NotificationBodyTextBlock - Specifies the enclosed text should be formatted in some way. Currently we have CODE, BOLD, PLAIN

For simplicity we only go 1 layer deep, meaning formatting blocks can only contain text blocks and text blocks can only contain text (so there isn't any recursive navigating).

relies on #102976

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 7, 2025
Copy link
Member

@leeandher leeandher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome 🔥 my only nit is that i prefer paragraph to section because <p> is the html equivalent, <section> is a bit different, but the code looks excellent!

texts.append(f"<strong>{block.text}</strong>")
elif block.type == NotificationBodyTextBlockType.CODE:
texts.append(f"<code>{block.text}</code>")
return mark_safe(" ".join(texts))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is mark_safe necessary here? I thought this was mainly for Django views.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w/o mark_safe the html tags will get escaped when inputted so they wont get rendered/used. mark_safe was suggested by le claude, lmk if there's a better way tho since I do not know of one :hide:

texts.append(f"**{block.text}**")
elif block.type == NotificationBodyTextBlockType.CODE:
texts.append(f"`{block.text}`")
return " ".join(texts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Markdown Formatting Vulnerable to User Input

The render_text_blocks method wraps user text with markdown formatting (** for bold, ` for code) but doesn't escape markdown special characters in the user text first. When the concatenated string is passed to create_text_block or create_code_block, escape_markdown_special_chars only escapes &, <, >, _ but not * or `. If user-supplied text like error_message contains these characters, it will break markdown rendering or cause unintended formatting injection.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided this a fine sacrifice, since the alternative is a lot of selective formatting. If it's a big problem I'll come back and do a patch

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 90.53254% with 16 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/sentry/notifications/platform/email/provider.py 73.46% 13 Missing ⚠️
.../sentry/notifications/platform/discord/provider.py 95.65% 1 Missing ⚠️
.../sentry/notifications/platform/msteams/provider.py 95.83% 1 Missing ⚠️
...rc/sentry/notifications/platform/slack/provider.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #102975      +/-   ##
===========================================
+ Coverage   78.93%    80.56%   +1.63%     
===========================================
  Files        9137      9139       +2     
  Lines      392766    394579    +1813     
  Branches    24966     24966              
===========================================
+ Hits       310027    317902    +7875     
+ Misses      82338     76276    -6062     
  Partials      401       401              

@Christinarlong Christinarlong merged commit d81c220 into master Nov 10, 2025
65 checks passed
@Christinarlong Christinarlong deleted the crl/add-notification-blocks branch November 10, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants