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

dev: Add email preview tool #10381

Merged
merged 1 commit into from
Dec 31, 2024
Merged

dev: Add email preview tool #10381

merged 1 commit into from
Dec 31, 2024

Conversation

Betree
Copy link
Member

@Betree Betree commented Oct 15, 2024

A minimalist tool to work on email templates styles and content. Start it with:

npm run mail:preview

List emails

Screenshot from 2024-10-15 09-31-58

Preview template

Screenshot from 2024-10-15 09-31-54

@Betree Betree self-assigned this Oct 15, 2024
@Betree Betree force-pushed the dev/email-preview branch 2 times, most recently from 65687f3 to 2034a3a Compare December 6, 2024 10:09
@Betree Betree marked this pull request as ready for review December 6, 2024 10:21
@Betree Betree force-pushed the dev/email-preview branch from 2034a3a to 70c385c Compare December 6, 2024 10:36

const renderResult = renderEmail(templateName);
const attributes = getTemplateAttributes(renderResult.html);
res.send(attributes.body);

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 2 months ago

To fix the problem, we need to ensure that the attributes.body is properly sanitized before being sent in the response. This can be achieved by using a library like sanitize-html to strip any potentially dangerous HTML content from the attributes.body.

  1. Import the sanitize-html library.
  2. Use the sanitize-html function to sanitize attributes.body before sending it in the response.
Suggested changeset 1
scripts/dev/dev-email-preview.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/dev/dev-email-preview.ts b/scripts/dev/dev-email-preview.ts
--- a/scripts/dev/dev-email-preview.ts
+++ b/scripts/dev/dev-email-preview.ts
@@ -9,3 +9,3 @@
 import templates, { isValidTemplate, recompileAllTemplates } from '../../server/lib/emailTemplates';
-import { stripHTML } from '../../server/lib/sanitize-html';
+import { stripHTML, sanitizeHTML } from '../../server/lib/sanitize-html';
 import MOCKS from '../../test/mocks/data';
@@ -185,3 +185,3 @@
     const attributes = getTemplateAttributes(renderResult.html);
-    res.send(attributes.body);
+    res.send(sanitizeHTML(attributes.body));
   } catch (error) {
EOF
@@ -9,3 +9,3 @@
import templates, { isValidTemplate, recompileAllTemplates } from '../../server/lib/emailTemplates';
import { stripHTML } from '../../server/lib/sanitize-html';
import { stripHTML, sanitizeHTML } from '../../server/lib/sanitize-html';
import MOCKS from '../../test/mocks/data';
@@ -185,3 +185,3 @@
const attributes = getTemplateAttributes(renderResult.html);
res.send(attributes.body);
res.send(sanitizeHTML(attributes.body));
} catch (error) {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@Betree Betree force-pushed the dev/email-preview branch 2 times, most recently from fe5dbac to f6bad0b Compare December 31, 2024 08:54
@Betree Betree merged commit ca99c91 into main Dec 31, 2024
20 checks passed
@Betree Betree deleted the dev/email-preview branch December 31, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant