Add helper function to sanitize user input strings

For any strings that require sanitization (i.e., strip
HTML/JavaScript), wrap the string around cloudStack.sanitize, or _s
for short. This currently will remove embedded HTML tags, which are
the main security issues present.

Example:

var str = '<script>Hello</script>My String';

_s(str) = '&lt;script&gt;Hello&lt;/script&gt;My String'
This commit is contained in:
bfederle 2012-03-14 10:53:44 -07:00
parent 31eef1d183
commit 2e1726cb5f
1 changed files with 14 additions and 0 deletions

View File

@ -54,4 +54,18 @@
return localized ? localized : str;
};
/**
* Sanitize user input -- shortcut _s
*
* Strip unwanted characters from user-based input
*/
cloudStack.sanitize = window._s = function(str) {
var sanitized = str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
return sanitized;
};
})(jQuery, cloudStack);