security_lib.php 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. define('HACKERS_ORG_XML', 'http://ha.ckers.org/xssAttacks.xml');
  3. /**
  4. * used in configurations controller + debug helper
  5. */
  6. class SecurityLib {
  7. /**
  8. * get dangerous strings to test with
  9. *
  10. * @return array
  11. * @static
  12. **/
  13. function xssStrings($cache = true) {
  14. if ($cache) {
  15. $texts = Cache::read('security_lib_texts');
  16. }
  17. if (empty($texts)) {
  18. $texts = array();
  19. $contents = $this->parse(HACKERS_ORG_XML);
  20. foreach ($contents as $content) {
  21. $texts[] = $content['code'];
  22. }
  23. if (empty($texts)) {
  24. trigger_error('ha.ckers.org FAILED - XML not available', E_WARNING);
  25. return array();
  26. }
  27. if ($cache) {
  28. Cache::write('security_lib_texts', $texts);
  29. }
  30. }
  31. return $texts;
  32. }
  33. /**
  34. * parse xml
  35. * 2010-02-07 ms
  36. */
  37. function parse($file) {
  38. App::import('Core', 'Xml');
  39. $xml = new Xml($file);
  40. $res = $xml->toArray();
  41. if (!empty($res['Xss']['Attack'])) {
  42. return (array)$res['Xss']['Attack'];
  43. }
  44. return array();
  45. }
  46. }
  47. ?>