Skip to content

Commit b48ac2a

Browse files
authored
fix: escape msg in render restricted error html, backport (#12889) (#12892)
1 parent 77ee19b commit b48ac2a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/vite/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@rollup/plugin-node-resolve": "14.1.0",
7979
"@rollup/plugin-typescript": "^8.5.0",
8080
"@rollup/pluginutils": "^4.2.1",
81+
"@types/escape-html": "^1.0.0",
8182
"acorn": "^8.8.1",
8283
"acorn-walk": "^8.2.0",
8384
"cac": "^6.7.14",
@@ -92,6 +93,7 @@
9293
"dotenv": "^14.3.2",
9394
"dotenv-expand": "^5.1.0",
9495
"es-module-lexer": "^1.1.0",
96+
"escape-html": "^1.0.3",
9597
"estree-walker": "^3.0.1",
9698
"etag": "^1.8.1",
9799
"fast-glob": "^3.2.12",

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

+2-1
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 {
@@ -208,7 +209,7 @@ function renderRestrictedErrorHTML(msg: string): string {
208209
return html`
209210
<body>
210211
<h1>403 Restricted</h1>
211-
<p>${msg.replace(/\n/g, '<br/>')}</p>
212+
<p>${escapeHtml(msg).replace(/\n/g, '<br/>')}</p>
212213
<style>
213214
body {
214215
padding: 1em 2em;

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)