Security.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace Config;
  3. use CodeIgniter\Config\BaseConfig;
  4. class Security extends BaseConfig
  5. {
  6. /**
  7. * --------------------------------------------------------------------------
  8. * CSRF Protection Method
  9. * --------------------------------------------------------------------------
  10. *
  11. * Protection Method for Cross Site Request Forgery protection.
  12. *
  13. * @var string 'cookie' or 'session'
  14. */
  15. // public string $csrfProtection = 'cookie';
  16. public string $csrfProtection = 'session';
  17. /**
  18. * --------------------------------------------------------------------------
  19. * CSRF Token Randomization
  20. * --------------------------------------------------------------------------
  21. *
  22. * Randomize the CSRF Token for added security.
  23. */
  24. // public bool $tokenRandomize = false;
  25. public bool $tokenRandomize = true;
  26. /**
  27. * --------------------------------------------------------------------------
  28. * CSRF Token Name
  29. * --------------------------------------------------------------------------
  30. *
  31. * Token name for Cross Site Request Forgery protection.
  32. */
  33. // public string $tokenName = 'csrf_test_name';
  34. public string $tokenName = 'csrf_token';
  35. /**
  36. * --------------------------------------------------------------------------
  37. * CSRF Header Name
  38. * --------------------------------------------------------------------------
  39. *
  40. * Header name for Cross Site Request Forgery protection.
  41. */
  42. public string $headerName = 'X-CSRF-TOKEN';
  43. /**
  44. * --------------------------------------------------------------------------
  45. * CSRF Cookie Name
  46. * --------------------------------------------------------------------------
  47. *
  48. * Cookie name for Cross Site Request Forgery protection.
  49. */
  50. public string $cookieName = 'csrf_cookie_name';
  51. /**
  52. * --------------------------------------------------------------------------
  53. * CSRF Expires
  54. * --------------------------------------------------------------------------
  55. *
  56. * Expiration time for Cross Site Request Forgery protection cookie.
  57. *
  58. * Defaults to two hours (in seconds).
  59. */
  60. public int $expires = 7200;
  61. /**
  62. * --------------------------------------------------------------------------
  63. * CSRF Regenerate
  64. * --------------------------------------------------------------------------
  65. *
  66. * Regenerate CSRF Token on every submission.
  67. */
  68. public bool $regenerate = true;
  69. /**
  70. * --------------------------------------------------------------------------
  71. * CSRF Redirect
  72. * --------------------------------------------------------------------------
  73. *
  74. * Redirect to previous page with error on failure.
  75. *
  76. * @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
  77. */
  78. public bool $redirect = (ENVIRONMENT === 'production');
  79. /**
  80. * --------------------------------------------------------------------------
  81. * CSRF SameSite
  82. * --------------------------------------------------------------------------
  83. *
  84. * Setting for CSRF SameSite cookie token.
  85. *
  86. * Allowed values are: None - Lax - Strict - ''.
  87. *
  88. * Defaults to `Lax` as recommended in this link:
  89. *
  90. * @see https://portswigger.net/web-security/csrf/samesite-cookies
  91. *
  92. * @deprecated `Config\Cookie` $samesite property is used.
  93. */
  94. public string $samesite = 'Lax';
  95. }