Skip to content

Commit 1761d5e

Browse files
committed
Bugfix - Escape HTML in error messages
1 parent f26ff7f commit 1761d5e

File tree

1 file changed

+11
-2
lines changed
  • packages/theme/src/cli/utilities/theme-environment/hot-reload

1 file changed

+11
-2
lines changed

packages/theme/src/cli/utilities/theme-environment/hot-reload/error-page.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ interface Error {
55

66
const POLARIS_STYLESHEET_URL = 'https://unpkg.com/@shopify/[email protected]/build/esm/styles.css'
77

8+
function escapeHtml(unsafe: string) {
9+
return unsafe
10+
.replace(/&/g, '&')
11+
.replace(/</g, '&lt;')
12+
.replace(/>/g, '&gt;')
13+
.replace(/"/g, '&quot;')
14+
.replace(/'/g, '&#039;')
15+
}
16+
817
export function getErrorPage(options: {title: string; header: string; errors: Error[]}) {
918
const html = String.raw
1019
return html`<!DOCTYPE html>
@@ -64,9 +73,9 @@ export function getErrorPage(options: {title: string; header: string; errors: Er
6473
.map(
6574
(error) => `
6675
<div>
67-
<span class="Polaris-Text--root Polaris-Text--headingSm">${error.message}</span>
76+
<span class="Polaris-Text--root Polaris-Text--headingSm">${escapeHtml(error.message)}</span>
6877
<ul class="Polaris-List">
69-
<li class="Polaris-List__Item">${error.code}</li>
78+
<li class="Polaris-List__Item">${escapeHtml(error.code)}</li>
7079
</ul>
7180
</div>`,
7281
)

0 commit comments

Comments
 (0)