Potential fix for code scanning alert no. 8: Client-side cross-site scripting#185
Potential fix for code scanning alert no. 8: Client-side cross-site scripting#185
Conversation
… scripting Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Potential fix for https://github.com/erikraft/Drop/security/code-scanning/8
In general, the problem is that untrusted text (
message.senderName/message.senderId) is interpolated into a string and assigned tometa.innerHTML, which parses it as HTML. To fix this without changing functionality, we should avoid usinginnerHTMLfor untrusted data and instead build the DOM structure usingcreateElement+textContent/innerText(which do not interpret HTML). This preserves the same visual structure (<span>name</span><span>time</span>) while eliminating XSS.Concretely, in
public/scripts/ui.jsinside_appendMessageNode, replace the linewith code that creates two
<span>elements, sets their.innerText(or.textContent) to the sender label and time string, and appends them tometa. No new imports are needed, and no other parts of the code need to change, because the DOM structure will remain equivalent, just constructed safely.Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Summary by CodeRabbit