Skip to content

Commit 3aa2127

Browse files
authored
fix: escape msg in render restricted error html (#12889)
1 parent 8c5f1d8 commit 3aa2127

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-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-typescript": "^11.0.0",
8787
"@rollup/pluginutils": "^5.0.2",
8888
"@types/pnpapi": "^0.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 {
@@ -236,7 +237,7 @@ function renderRestrictedErrorHTML(msg: string): string {
236237
return html`
237238
<body>
238239
<h1>403 Restricted</h1>
239-
<p>${msg.replace(/\n/g, '<br/>')}</p>
240+
<p>${escapeHtml(msg).replace(/\n/g, '<br/>')}</p>
240241
<style>
241242
body {
242243
padding: 1em 2em;

pnpm-lock.yaml

Lines changed: 10 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)