Skip to content

Commit f2639f0

Browse files
committed
fix(error-response-plugin): percentage-encode path to limit XSS
1 parent e7ae009 commit f2639f0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/plugins/default/error-response-plugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ export const errorResponsePlugin: Plugin = (proxyServer, options) => {
2525
res.writeHead(statusCode);
2626
}
2727

28+
const encodedPath = req.url
29+
.replace(/%/g, '%25')
30+
.replace(/&/g, '%26')
31+
.replace(/</g, '%3C')
32+
.replace(/>/g, '%3E')
33+
.replace(/"/g, '%22')
34+
.replace(/'/g, '%27');
35+
2836
const host = req.headers && req.headers.host;
29-
res.end(`Error occurred while trying to proxy: ${host}${req.url}`);
37+
res.end(`Error occurred while trying to proxy: ${host}${encodedPath}`);
3038
} else if (isSocketLike(res)) {
3139
res.destroy();
3240
}

0 commit comments

Comments
 (0)