Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion orbit-app/src/components/CommentsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
});
};

// FIX: Helper function to escape HTML special characters
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\"/g, "&quot;")

Check notice on line 39 in orbit-app/src/components/CommentsSection.jsx

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

orbit-app/src/components/CommentsSection.jsx#L39

Unnecessary escape character: \".
.replace(/'/g, "&#039;");
}

return (
<div>
<h2>Comments</h2>
Expand All @@ -44,11 +54,13 @@

<div className="comments-list">
{commentsList.map((cmt, index) => (
<div key={index} dangerouslySetInnerHTML={{ __html: cmt.comment }} />
// FIX: Render comment as plain text, escaping HTML
<div key={index}>{escapeHtml(cmt.comment)}</div>
))}
</div>
</div>
);
}
// FIX EXPLANATION: This fix removes the use of 'dangerouslySetInnerHTML' and instead escapes HTML special characters in user comments before rendering. This prevents any injected HTML or JavaScript from being interpreted by the browser, fully mitigating XSS. For production, consider using a robust library like 'dompurify' for sanitization if HTML formatting is required.

export default CommentsSection;