security: escape exception messages in default HTML error response#1385
security: escape exception messages in default HTML error response#1385renich wants to merge 2 commits into
Conversation
The default HTML error response directly embedded the exception message without escaping it, leading to a Reflected Cross-Site Scripting (XSS) vulnerability. This commit properly requires the `html` standard library module and utilizes `HTML.escape` to neutralize the exception message before embedding it in the HTML template. It also properly handles the `String?` type of `@ex.message` in Crystal. Co-authored-by: renich <225115+renich@users.noreply.github.com>
|
This is a legitimate fix and we'll accept it — thank you. ✅ I confirmed the vulnerability is real: One thing needed before merge:
No need to remove |
Add a regression spec in error_spec.cr verifying that exception messages are properly escaped when text/html is requested in production mode. Co-developed-by: Gemini AI <renich+gemini@woralelandia.com> Signed-off-by: Rénich Bon Ćirić <renich@woralelandia.com>
|
I have updated the PR to address your feedback. Following your suggestion, I have added a regression spec in All specs compile and pass. (Note: This contribution was co-developed with Gemini AI. Rénich has directed, reviewed, tested, and takes full responsibility for this code.) |
Escapes raw HTML exception messages in the default error controller to prevent reflected XSS.
Co-developed-by: Gemini AI renich+gemini@woralelandia.com
Signed-off-by: Rénich Bon Ćirić renich@woralelandia.com