Potential fix for code scanning alert no. 3: DOM text reinterpreted as HTML#24
Conversation
…s HTML Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates questionnaire validation message rendering to avoid injecting user/DOM-influenced strings as HTML, addressing code scanning alert #3 (DOM text reinterpreted as HTML / potential XSS).
Changes:
- Replaced
.html(...)with.text(...)for.dTipvalidation message writes. - Preserved “clear message” behavior by using
.text("")instead of.html("").
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot 你需要查看实际的问卷列表,来查看当前是否有问卷中有 HTML 结构,因为问卷可能利用了这个方法展示自定义 HTML 内容。 |
已检查全部 9 个问卷 JSON 文件及模板代码,结论如下:
部分问卷 JSON 中确实存在 HTML 内容:
但这些内容是通过 PHP 模板的 因此,将 |
Potential fix for https://github.com/nm-Team/WebSite/security/code-scanning/3
Use text insertion instead of HTML insertion for user/DOM-influenced strings.
Best fix in this snippet:
.html(...)with.text(...)for all.dTipmessage writes that are plain text..text("")instead of.html("").Specifically in
src/js/questionnaire.js, update the.dTipwrites at:No new imports or helper methods are needed. This preserves functionality (showing validation messages) while preventing HTML interpretation/XSS.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.