Skip to content

Commit 8758c5c

Browse files
committed
fix: escape msg in render restricted error html, backport #12889
1 parent a53feb5 commit 8758c5c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/vite/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"@rollup/plugin-node-resolve": "15.0.1",
8787
"@rollup/plugin-typescript": "^11.0.0",
8888
"@rollup/pluginutils": "^5.0.2",
89+
"@types/escape-html": "^1.0.0",
8990
"acorn": "^8.8.2",
9091
"acorn-walk": "^8.2.0",
9192
"cac": "^6.7.14",
@@ -100,6 +101,7 @@
100101
"dotenv": "^16.0.3",
101102
"dotenv-expand": "^9.0.0",
102103
"es-module-lexer": "^1.2.0",
104+
"escape-html": "^1.0.3",
103105
"estree-walker": "^3.0.3",
104106
"etag": "^1.8.1",
105107
"fast-glob": "^3.2.12",

packages/vite/src/node/server/middlewares/static.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { OutgoingHttpHeaders, ServerResponse } from 'node:http'
33
import type { Options } from 'sirv'
44
import sirv from 'sirv'
55
import type { Connect } from 'dep-types/connect'
6+
import escapeHtml from 'escape-html'
67
import type { ViteDevServer } from '../..'
78
import { FS_PREFIX } from '../../constants'
89
import {
@@ -230,7 +231,7 @@ function renderRestrictedErrorHTML(msg: string): string {
230231
return html`
231232
<body>
232233
<h1>403 Restricted</h1>
233-
<p>${msg.replace(/\n/g, '<br/>')}</p>
234+
<p>${escapeHtml(msg).replace(/\n/g, '<br/>')}</p>
234235
<style>
235236
body {
236237
padding: 1em 2em;

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)