Skip to content

Commit

Permalink
chore: sanitizing content to avoid accidentally rendering html
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Apr 23, 2024
1 parent 34ad6dc commit 391e96e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ export class GithubCommentModule implements Module {
function buildIncentiveRow(commentScore: GithubCommentScore) {
// Properly escape carriage returns for HTML rendering
const formatting = stringify(commentScore.score?.formatting?.content).replace(/[\n\r]/g, "
");
// Makes sure any HTML injected in the templated is not rendered itself
const sanitizedContent = commentScore.content.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
return `
<tr>
<td>
<h6>
<a href="${commentScore.url}" target="_blank" rel="noopener">${commentScore.content.replace(/(.{64})..+/, "$1&hellip;")}</a>
<a href="${commentScore.url}" target="_blank" rel="noopener">${sanitizedContent.replace(/(.{64})..+/, "$1&hellip;")}</a>
</h6>
</td>
<td>
Expand Down

0 comments on commit 391e96e

Please sign in to comment.