Skip to content

Commit ee6a598

Browse files
committed
search: do treat the search term as plain text
In order to avoid the search term for being mistaken for partial HTML (and thereby allowing the term to "break out" of the HTML element in which it should be contained), it needs to be URI-encoded. Reported by Zeeshan Waheed. This addresses https://github.com/git/git-scm.com/security/advisories/ GHSA-4g76-28mm-rc63. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 00d0f30 commit ee6a598

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

assets/js/application.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ var Search = {
232232
if(term != Search.currentSearch) {
233233
Search.currentSearch = term;
234234
const language = document.querySelector("html")?.getAttribute("lang");
235-
const allResultsURL = `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`;
235+
const allResultsURL = `${baseURLPrefix}search/results?search=${encodeURIComponent(term)}${language && `&language=${encodeURIComponent(language)}`}`;
236236
$("#search-results").html(`
237237
<header> Search Results </header>
238238
<table>
@@ -242,7 +242,7 @@ var Search = {
242242
<td class="matches">
243243
<ul>
244244
<li>
245-
<a class="highlight" id="show-results-label" href="${allResultsURL}">
245+
<a class="highlight" id="show-results-label">
246246
Searching for <span id="search-term">&nbsp;</span>...
247247
</a>
248248
</li>
@@ -273,6 +273,9 @@ var Search = {
273273
</table>
274274
`);
275275
$("#search-term").text(term);
276+
// Set the link target safely (no HTML parsing).
277+
$("#show-results-label").attr("href", allResultsURL);
278+
276279
this.initializeSearchIndex(async () => {
277280
const results = await Search.pagefind.debouncedSearch(term);
278281
if (results === null || results.results.length === 0) {
@@ -362,7 +365,7 @@ var Search = {
362365
const term = $('#search-text').val();
363366
if (!term) return;
364367
const language = document.querySelector("html")?.getAttribute("lang");
365-
url = `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`;
368+
url = `${baseURLPrefix}search/results?search=${encodeURIComponent(term)}${language && `&language=${encodeURIComponent(language)}`}`;
366369
}
367370
window.location.href = url;
368371
selectedIndex = 0;

0 commit comments

Comments
 (0)