-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
base: main
Are you sure you want to change the base?
dev: Add email preview tool #10381
Conversation
65687f3
to
2034a3a
Compare
2034a3a
to
70c385c
Compare
|
||
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
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 10 days ago
To fix the problem, we need to ensure that any user-controlled data is properly sanitized or escaped before being included in the HTML response. This can be achieved by using a library like he
(HTML entities) to escape the content before sending it in the response.
- Install the
he
library to handle HTML escaping. - Use the
he
library to escapeattributes.body
anderror.message
before including them in the HTML response.
-
Copy modified line R11 -
Copy modified line R186 -
Copy modified lines R197-R198
@@ -10,2 +10,3 @@ | ||
import { stripHTML } from '../../server/lib/sanitize-html'; | ||
import he from 'he'; | ||
import MOCKS from '../../test/mocks/data'; | ||
@@ -184,3 +185,3 @@ | ||
const attributes = getTemplateAttributes(renderResult.html); | ||
res.send(attributes.body); | ||
res.send(he.escape(attributes.body)); | ||
} catch (error) { | ||
@@ -195,4 +196,4 @@ | ||
<h1>Error while rendering template</h1> | ||
<p>${error.message}. Details:</p> | ||
<pre style="background-color: #f8f9fa; padding: 10px; overflow: auto; max-width: 100%;">${error.stack}</pre> | ||
<p>${he.escape(error.message)}. Details:</p> | ||
<pre style="background-color: #f8f9fa; padding: 10px; overflow: auto; max-width: 100%;">${he.escape(error.stack)}</pre> | ||
</body> |
-
Copy modified lines R137-R138
@@ -136,3 +136,4 @@ | ||
"winston": "3.17.0", | ||
"zod": "3.23.8" | ||
"zod": "3.23.8", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
try { | ||
const renderResult = renderEmail(templateName); | ||
const attributes = getTemplateAttributes(renderResult.html); | ||
res.send(attributes.subject); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Exception text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 10 days ago
To fix the problem, we need to ensure that any user input included in the response is properly sanitized to prevent XSS attacks. This can be achieved by using a library like escape-html
to escape any potentially dangerous characters in the error message before sending it to the client.
-
Copy modified line R187 -
Copy modified lines R197-R198
@@ -186,2 +186,3 @@ | ||
} catch (error) { | ||
const escapeHtml = require('escape-html'); | ||
res.status(400).send(` | ||
@@ -195,4 +196,4 @@ | ||
<h1>Error while rendering template</h1> | ||
<p>${error.message}. Details:</p> | ||
<pre style="background-color: #f8f9fa; padding: 10px; overflow: auto; max-width: 100%;">${error.stack}</pre> | ||
<p>${escapeHtml(error.message)}. Details:</p> | ||
<pre style="background-color: #f8f9fa; padding: 10px; overflow: auto; max-width: 100%;">${escapeHtml(error.stack)}</pre> | ||
</body> |
-
Copy modified lines R137-R138
@@ -136,3 +136,4 @@ | ||
"winston": "3.17.0", | ||
"zod": "3.23.8" | ||
"zod": "3.23.8", | ||
"escape-html": "^1.0.3" | ||
}, |
Package | Version | Security advisories |
escape-html (npm) | 1.0.3 | None |
A minimalist tool to work on email templates styles and content. Start it with:
List emails
Preview template