Skip to content

Commit 648c9ae

Browse files
pietroalbiniehuss
authored andcommitted
fix xss in the search page
Thanks to Kamil Vavra for responsibly disclosing the vulnerability according to Rust's Security Policy.
1 parent eaa6914 commit 648c9ae

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/theme/searcher/searcher.js

+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ window.search = window.search || {};
145145
url.push("");
146146
}
147147

148+
// encodeURIComponent escapes all chars that could allow an XSS except
149+
// for '. Due to that we also manually replace ' with its url-encoded
150+
// representation (%27).
151+
var searchterms = encodeURIComponent(searchterms.join(" ")).replace(/\'/g, "%27");
152+
148153
return '<a href="' + path_to_root + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
149154
+ '" aria-details="teaser_' + teaser_count + '">' + result.doc.breadcrumbs + '</a>'
150155
+ '<span class="teaser" id="teaser_' + teaser_count + '" aria-label="Search Result Teaser">'

0 commit comments

Comments
 (0)