Skip to content

Commit f7524c2

Browse files
committed
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'
1 parent 3591185 commit f7524c2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎ui/scripts/ui/utils.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,18 @@
5454

5555
return localized ? localized : str;
5656
};
57+
58+
/**
59+
* Sanitize user input -- shortcut _s
60+
*
61+
* Strip unwanted characters from user-based input
62+
*/
63+
cloudStack.sanitize = window._s = function(str) {
64+
var sanitized = str
65+
.replace(/&/g, "&amp;")
66+
.replace(/</g, "&lt;")
67+
.replace(/>/g, "&gt;");
68+
69+
return sanitized;
70+
};
5771
})(jQuery, cloudStack);

0 commit comments

Comments
 (0)