Guest User

Untitled

a guest
Feb 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. /**
  3. * method to test string for XSS
  4. * @name PXHLR.preventXSS
  5. * @type Function
  6. * @member PXHLR
  7. * @returns String that doesn't allow XSS Cross Site Scripting attack
  8. */
  9. PXHLR.preventXSS = function (str) {
  10. var paramStr = str;
  11. paramStr = paramStr.replace(/[<>]/g, '').replace(/</g, "<").replace(/>/g, ">");
  12. paramStr = paramStr.replace(/[\"\'][\s]*javascript:(.*)[\"\']/gi, "\"\"");
  13. paramStr = paramStr.replace(/script(.*)/gi, "");
  14. paramStr = paramStr.replace(/eval\((.*)\)/gi, "");
  15. return paramStr;
  16. };
  17.  
  18. /**
  19. * method to get url params
  20. * @name PXHLR.getParam
  21. * @type Function
  22. * @member PXHLR
  23. * @requires PXHLR.preventXSS
  24. * @returns String as the value of the requested URL parameter
  25. */
  26. PXHLR.getParam = function(param) {
  27. var p = {
  28. vars : [],
  29. hashes : window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'),
  30. i : 0
  31. };
  32. for(p.i; p.i < p.hashes.length; p.i++) {
  33. p.hash = p.hashes[p.i].split('=');
  34. p.vars.push(p.hash[0]);
  35. p.vars[p.hash[0]] = p.hash[1];
  36. }
  37. p.value = p.vars[param];
  38. if (!p.value) {
  39. return '';
  40. } else {
  41. return PXHLR.preventXSS(p.value);
  42. }
  43. };
  44.  
  45. /* example use
  46. // set logging on with url param
  47. if (PXHLR.getParam('log') === '') {
  48. window.log = function() { return false; };
  49. }
  50. */
Add Comment
Please, Sign In to add comment