IBackend.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Security\Bruteforce\Backend;
  8. /**
  9. * Interface IBackend defines a storage backend for the bruteforce data. It
  10. * should be noted that writing and reading brute force data is an expensive
  11. * operation and one should thus make sure to only use sufficient fast backends.
  12. */
  13. interface IBackend {
  14. /**
  15. * Gets the number of attempts for the specified subnet (and further filters)
  16. *
  17. * @param string $ipSubnet
  18. * @param int $maxAgeTimestamp
  19. * @param ?string $action Optional action to further limit attempts
  20. * @param ?array $metadata Optional metadata stored to further limit attempts (Only considered when $action is set)
  21. * @return int
  22. * @since 28.0.0
  23. */
  24. public function getAttempts(
  25. string $ipSubnet,
  26. int $maxAgeTimestamp,
  27. ?string $action = null,
  28. ?array $metadata = null,
  29. ): int;
  30. /**
  31. * Reset the attempts for the specified subnet (and further filters)
  32. *
  33. * @param string $ipSubnet
  34. * @param ?string $action Optional action to further limit attempts
  35. * @param ?array $metadata Optional metadata stored to further limit attempts(Only considered when $action is set)
  36. * @since 28.0.0
  37. */
  38. public function resetAttempts(
  39. string $ipSubnet,
  40. ?string $action = null,
  41. ?array $metadata = null,
  42. ): void;
  43. /**
  44. * Register a failed attempt to bruteforce a security control
  45. *
  46. * @param string $ip
  47. * @param string $ipSubnet
  48. * @param int $timestamp
  49. * @param string $action
  50. * @param array $metadata Optional metadata stored to further limit attempts when getting
  51. * @since 28.0.0
  52. */
  53. public function registerAttempt(
  54. string $ip,
  55. string $ipSubnet,
  56. int $timestamp,
  57. string $action,
  58. array $metadata = [],
  59. ): void;
  60. }