File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -15,10 +15,16 @@ Improve a documentation page
1515 <script >
1616 document .addEventListener (' DOMContentLoaded' , () => {
1717 const params = new URLSearchParams (window .location .search );
18- document .body .innerHTML = document .body .innerHTML
19- .replace (/ PAGETITLE/ g , params .get (' pagetitle' ))
20- .replace (/ PAGEURL/ g , params .get (' pageurl' ))
21- .replace (/ PAGESOURCE/ g , params .get (' pagesource' ));
18+ const walker = document .createTreeWalker (document .body , NodeFilter .SHOW_TEXT , null );
19+
20+ // Replace .textContent to be safe. innerHTML will execute XSS code.
21+ while (walker .nextNode ()) {
22+ const textNode = walker .currentNode ;
23+ textNode .textContent = textNode .textContent
24+ .replace (/ PAGETITLE/ g , params .get (' pagetitle' ))
25+ .replace (/ PAGEURL/ g , params .get (' pageurl' ))
26+ .replace (/ PAGESOURCE/ g , params .get (' pagesource' ));
27+ }
2228 });
2329 </script >
2430
You can’t perform that action at this time.
0 commit comments