Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(root): html sanitization #7921

Conversation

djabarovgeorge
Copy link
Contributor

@djabarovgeorge djabarovgeorge commented Mar 13, 2025

What changed? Why was the change needed?

to support the bypass view, i replicated the in-app view so the editor facade looks similar. now we have a header "email template editor" and a border wrapping the subject and body.

image

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

linear bot commented Mar 13, 2025

Copy link

netlify bot commented Mar 13, 2025

Deploy Preview for dashboard-v2-novu-staging canceled.

Name Link
🔨 Latest commit 8d163ae
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/67dbd9ee8ccfd6000878fb29

Copy link

pkg-pr-new bot commented Mar 14, 2025

Open in Stackblitz

@novu/client

npm i https://pkg.pr.new/novuhq/novu/@novu/client@7921

@novu/framework

npm i https://pkg.pr.new/novuhq/novu/@novu/framework@7921

@novu/headless

npm i https://pkg.pr.new/novuhq/novu/@novu/headless@7921

@novu/node

npm i https://pkg.pr.new/novuhq/novu/@novu/node@7921

@novu/notification-center

npm i https://pkg.pr.new/novuhq/novu/@novu/notification-center@7921

@novu/providers

npm i https://pkg.pr.new/novuhq/novu/@novu/providers@7921

novu

npm i https://pkg.pr.new/novuhq/novu@7921

@novu/shared

npm i https://pkg.pr.new/novuhq/novu/@novu/shared@7921

commit: 5c92e2f

@@ -37,13 +37,15 @@ export class EmailOutputRendererUsecase {
const parsedMaily = await this.parseMailyContentByLiquid(transformedMaily, renderCommand.fullPayloadForRender);
const strippedMaily = this.removeTrailingEmptyLines(parsedMaily);
const renderedHtml = await mailyRender(strippedMaily);
// todo: the assumption was wrong, we can remove this as mailyRender already sanitizes the html
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like renderedHtml is already sanitized. we could keep the sanitization as a safeguard.

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment in the code says something different. If mail/renderer already sanitizes let's remove it completely. There is no need for double sanitization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct but then i though about it in more safe way to guard yourself in case the mainly logix changes.

disableOutputSanitization:
(staticStep.controlVariables?.disableOutputSanitization as boolean | undefined) ?? false,
// TODO: add providers
disableOutputSanitization: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are removing the responsibility of sanitization from the Framework to Novu

@@ -9,6 +9,15 @@ export class InAppOutputRendererUsecase {
execute(renderCommand: RenderCommand): InAppRenderOutput {
const { skip, disableOutputSanitization, ...outputControls } = renderCommand.controlValues ?? {};

return outputControls as any;
if (disableOutputSanitization) {
return outputControls as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in case the user toggled the bypass option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now we will sanitize only the possible "HTML" content while keeping the old flow desition contentType === 'editor'

@@ -384,6 +380,14 @@ export class Client {
};
}

private shouldSanitize({ stepType, options }: { stepType: StepType; options: ChannelStepOption | undefined }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the moment, we implemented more precise sanitization, applying it only to email and in-app. because for other channels, there's no reason to sanitize, which reduces computation and complexity for framework users.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-picky one: You can keep it simple for now and do (stepType: string, disableOutputSanitization: boolean); to avoid the extra types and such.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in that case, we will have another compilation error.
i believe this one is the issue.

@djabarovgeorge djabarovgeorge marked this pull request as ready for review March 17, 2025 10:08
…or-email-subject-2' of github.com:novuhq/novu into NV-5376-special-characters-are-not-sanitized-properly-for-email-subject-2
@djabarovgeorge djabarovgeorge merged commit 01908ff into next Mar 20, 2025
27 checks passed
@djabarovgeorge djabarovgeorge deleted the NV-5376-special-characters-are-not-sanitized-properly-for-email-subject-2 branch March 20, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants