sfValidatorCSRFToken.class.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfValidatorCSRFToken checks that the token is valid.
  11. *
  12. * @package symfony
  13. * @subpackage validator
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfValidatorCSRFToken.class.php 7902 2008-03-15 13:17:33Z fabien $
  16. */
  17. class sfValidatorCSRFToken extends sfValidatorBase
  18. {
  19. /**
  20. * @see sfValidatorBase
  21. */
  22. protected function configure($options = array(), $messages = array())
  23. {
  24. $this->addRequiredOption('token');
  25. $this->setOption('required', true);
  26. $this->addMessage('csrf_attack', 'CSRF attack detected.');
  27. }
  28. /**
  29. * @see sfValidatorBase
  30. */
  31. protected function doClean($value)
  32. {
  33. if ($value != $this->getOption('token'))
  34. {
  35. throw new sfValidatorError($this, 'csrf_attack');
  36. }
  37. return $value;
  38. }
  39. }