Skip to content

Commit

Permalink
fixed XSS - escape user display names
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Oct 11, 2023
1 parent 6c67eef commit aa2bf46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion post_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PostComponent {

let h = document.createElement('h2');

h.innerHTML = `${this.authorName} ` +
h.innerHTML = `${escapeHTML(this.authorName)} ` +
`<a class="handle" href="${this.linkToAuthor}" target="_blank">@${this.post.author.handle}</a> ` +
`<span class="separator">&bull;</span> ` +
`<a class="time" href="${this.linkToPost}" target="_blank" title="${isoTime}">${formattedTime}</a> `;
Expand Down
6 changes: 6 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class AtURI {
}
}

function escapeHTML(html) {
return html.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g,'&gt;');
}

function getLocation() {
return location.origin + location.pathname;
}
Expand Down

0 comments on commit aa2bf46

Please sign in to comment.