test_csrf.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. //define("NOLOGIN",1); // This means this output page does not require to be logged.
  3. //if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1');
  4. //if (!defined('NOREQUIREDB')) define('NOREQUIREDB', '1');
  5. if (!defined('NOREQUIRESOC')) {
  6. define('NOREQUIRESOC', '1');
  7. }
  8. //if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
  9. if (!defined('NOSTYLECHECK')) {
  10. define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
  11. }
  12. //if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  13. //if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  14. //if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
  15. if (!defined("NOLOGIN")) {
  16. define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
  17. }
  18. // Load Dolibarr environment
  19. require '../../main.inc.php';
  20. // Security
  21. if ($dolibarr_main_prod) {
  22. accessforbidden();
  23. }
  24. /*
  25. * View
  26. */
  27. header("Content-type: text/html; charset=UTF8");
  28. // Security options
  29. header("X-Content-Type-Options: nosniff"); // With the nosniff option, if the server says the content is text/html, the browser will render it as text/html (note that most browsers now force this option to on)
  30. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  31. ?>
  32. This is a form to test if a CSRF exists into a Dolibarr page.<br>
  33. <br>
  34. - Change url to send request to into this file (URL to a hard coded page on a server B)<br>
  35. - Open this form into a virtual server A.<br>
  36. - Send the request to the virtual server B by clicking submit.<br>
  37. - Check that Anticsrf protection is triggered.<br>
  38. <br>
  39. <?php
  40. $urltosendrequest = "http://127.0.0.1/dolibarr/htdocs/user/group/card.php";
  41. print 'urltosendrequest = '.$urltosendrequest.'<br><br>';
  42. ?>
  43. Test post
  44. <form method="POST" action="<?php echo $urltosendrequest; ?>" target="_blank">
  45. <!-- <input type="hidden" name="token" value="123456789"> -->
  46. <input type="text" name="action" value="add">
  47. <input type="text" name="nom" value="New group test">
  48. <input type="submit" name="submit" value="Submit">
  49. </form>
  50. Test logout
  51. <html>
  52. <body>
  53. <script>history.pushState('', '', '/')</script>
  54. <form action="http://localhostgit/dolibarr_dev/htdocs/user/logout.php">
  55. <input type="submit" value="Submit request" />
  56. </form>
  57. <script>
  58. document.forms[0].submit();
  59. </script>
  60. </body>
  61. </html>