Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure error messages are escaped #13050

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading