Skip to content

Comments

Potential fix for code scanning alert no. 23: Exception text reinterpreted as HTML#44

Open
Tanker187 wants to merge 1 commit intomainfrom
alert-autofix-23
Open

Potential fix for code scanning alert no. 23: Exception text reinterpreted as HTML#44
Tanker187 wants to merge 1 commit intomainfrom
alert-autofix-23

Conversation

@Tanker187
Copy link
Owner

Potential fix for https://github.com/Tanker187/vite/security/code-scanning/23

In general, to fix this issue you should avoid sending raw exception messages or stack traces directly to an HTML response. Instead, either (1) send a generic, constant error message to the client and log detailed information on the server, or (2) if detailed information must be shown, ensure it is properly escaped and sent as text, not HTML.

The best fix here, without changing existing functionality too much, is to stop sending e.stack back to the browser and instead send a generic error message (e.g. "Internal Server Error") while keeping the detailed error logged server-side. This preserves current logging behavior (console.log(e.stack)) and therefore debuggability, but removes the XSS vector. Concretely, in playground/ssr-pug/server.js, in the catch block of the app.use('*all', ...) handler, replace res.status(500).end(e.stack) with res.status(500).end('Internal Server Error') (or similar static text). No extra imports or helpers are needed.

Change details:

  • File: playground/ssr-pug/server.js
  • Region: the catch (e) { ... } block around lines 59–63.
  • Modification: remove use of e.stack in the HTTP response and return a constant error message instead.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…reted as HTML

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Repository owner locked and limited conversation to collaborators Feb 11, 2026
@Tanker187 Tanker187 self-assigned this Feb 11, 2026
@Tanker187 Tanker187 marked this pull request as ready for review February 11, 2026 15:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant