Skip to content

Commit 1f8b615

Browse files
committed
Escape PR titles and usernames in dashboard HTML output
make sure all user content is escaped Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 1dd93bf commit 1f8b615

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

public/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@
110110
}
111111

112112
function prLink(repo, pr, text) {
113-
return `<a href="https://github.com/${metadata.org}/${repo}/pull/${pr}">${text}</a>`;
113+
const org = encodeURIComponent(metadata.org);
114+
const repoSeg = encodeURIComponent(repo);
115+
const prSeg = encodeURIComponent(String(pr));
116+
const safeText = DataTable.util.escapeHtml(String(text));
117+
return `<a href="https://github.com/${org}/${repoSeg}/pull/${prSeg}">${safeText}</a>`;
114118
}
115119

116120
function userLink(user, internal = true) {
@@ -124,8 +128,11 @@
124128
user = user.substring(1);
125129
}
126130

127-
const href = internal ? `?username=${user}` : `https://github.com/${user}`;
128-
return `<a class="${linkClass}" href="${href}">${user}</a>`;
131+
const href = internal
132+
? `?username=${encodeURIComponent(user)}`
133+
: `https://github.com/${encodeURIComponent(user)}`;
134+
const safeUser = DataTable.util.escapeHtml(user);
135+
return `<a class="${linkClass}" href="${href}">${safeUser}</a>`;
129136
}
130137
function sortUsernames(a, b) {
131138
const getPriority = (str) => (str.startsWith("-") ? -2 : str.startsWith("+") ? -1 : 0);
@@ -144,7 +151,8 @@
144151
render: (data, type, row) => {
145152
if (type == "display") {
146153
let docHref = metadata.doc_url.replaceAll('\${pr}', row[0]);
147-
docLink = `<a href="${docHref}" target="_blank" title="CI-built documentation">
154+
const safeDocHref = DataTable.util.escapeHtml(docHref);
155+
docLink = `<a href="${safeDocHref}" target="_blank" title="CI-built documentation">
148156
<i class="bi bi-file-earmark-text"></i>
149157
</a>`;
150158
return docLink + " " + prLink(row[13], data, data);
@@ -210,7 +218,7 @@
210218
className: "ellipsis narrow",
211219
responsivePriority: 5,
212220
},
213-
{ title: "Base", responsivePriority: 200 },
221+
{ title: "Base", responsivePriority: 200, render: DataTable.render.text() },
214222
{
215223
title: "Updated",
216224
render: (data, type, row) => (type == "display" ? timeSince(data) : data),

0 commit comments

Comments
 (0)