Skip to content

Commit

Permalink
fix: ensure error messages are escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Nov 25, 2024
1 parent d338d46 commit d44435f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-swans-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: ensure error messages are escaped
3 changes: 2 additions & 1 deletion packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { compact } from '../../../utils/array.js';
import { not_found } from '../utils.js';
import { SCHEME } from '../../../utils/url.js';
import { check_feature } from '../../../utils/features.js';
import { escape_html } from '../../../utils/escape.js';

const cwd = process.cwd();

Expand Down Expand Up @@ -508,7 +509,7 @@ export async function dev(vite, vite_config, svelte_config) {
const error_template = ({ status, message }) => {
return error_page
.replace(/%sveltekit\.status%/g, String(status))
.replace(/%sveltekit\.error\.message%/g, message);
.replace(/%sveltekit\.error\.message%/g, escape_html(message));
};

res.writeHead(500, {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { negotiate } from '../../utils/http.js';
import { HttpError } from '../control.js';
import { fix_stack_trace } from '../shared-server.js';
import { ENDPOINT_METHODS } from '../../constants.js';
import { escape_html } from '../../utils/escape.js';

/** @param {any} body */
export function is_pojo(body) {
Expand Down Expand Up @@ -50,7 +51,7 @@ export function allowed_methods(mod) {
* @param {string} message
*/
export function static_error_page(options, status, message) {
let page = options.templates.error({ status, message });
let page = options.templates.error({ status, message: escape_html(message) });

if (DEV) {
// inject Vite HMR client, for easier debugging
Expand Down

0 comments on commit d44435f

Please sign in to comment.