summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Main <smain@google.com>2009-10-28 09:50:06 -0700
committerScott Main <smain@google.com>2009-10-28 14:42:40 -0700
commit3534daddeefefbd42ea0a3819348327e5d85315c (patch)
tree923677f09e9473383570b86310103b7aeb1c6066
parentd14f1bd7e4ba28489bdc472aa736aee5a587cb98 (diff)
downloadframeworks_base-3534daddeefefbd42ea0a3819348327e5d85315c.zip
frameworks_base-3534daddeefefbd42ea0a3819348327e5d85315c.tar.gz
frameworks_base-3534daddeefefbd42ea0a3819348327e5d85315c.tar.bz2
docs: fix XSS vulnerability in search
add a function that uses replace() to replace all instances of '<' and '>' with the HTML entities and use this wherever the query text is added onto the page.
-rw-r--r--docs/html/search.jd14
1 files changed, 11 insertions, 3 deletions
diff --git a/docs/html/search.jd b/docs/html/search.jd
index 8032b22..d0e7478 100644
--- a/docs/html/search.jd
+++ b/docs/html/search.jd
@@ -70,8 +70,8 @@ page.title=Search Results
searchControl.setSearchStartingCallback(this, function(control, searcher, query) {
// save the tab index from the hash
tabIndex = location.hash.split("&t=")[1];
-
- $("#searchTitle").html("search results for <em>" + query + "</em>");
+
+ $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
$.history.add('q=' + query + '&t=' + tabIndex);
openTab();
});
@@ -96,7 +96,8 @@ page.title=Search Results
$(window).history(function(e, hash) {
var query = decodeURI(getQuery(hash));
searchControl.execute(query);
- $("#searchTitle").html("search results for <em>" + query + "</em>");
+
+ $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
});
// forcefully regain key-up event control (previously jacked by search api)
@@ -131,6 +132,13 @@ page.title=Search Results
return queryParts[1];
}
+ /* returns the given string with all HTML brackets converted to entities
+ TODO: move this to the site's JS library */
+ function escapeHTML(string) {
+ return string.replace(/</g,"&lt;")
+ .replace(/>/g,"&gt;");
+ }
+
</script>
<div id="mainBodyFixed" style="width:auto; margin:20px">