Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(csrf): Add Csrf Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 28, 2019
1 parent abbef65 commit 9bddfa8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- **tracker:** No need to explicit serialize announce data

### Refactor
- **Tracker:** Better Tracker behaviour in multi tracker
- **View:** Rename folder `error` to `action`
- **action_success:** Simple The Action Template

Expand Down
6 changes: 6 additions & 0 deletions framework/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ public function getSessionId()
return $this->_sessionId;
}

public function setCsrfToken()
{
$csrf = StringHelper::getRandomString(16);
$this->set('csrf', $csrf);
return $csrf;
}
}
25 changes: 25 additions & 0 deletions framework/Validators/CsrfTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 7/28/2019
* Time: 3:37 PM
*/

namespace Rid\Validators;


trait CsrfTrait
{
public $csrf;

protected function validateCaptcha()
{
$csrfInput = $this->getData('csrf');
$csrfText = app()->session->pop('csrfText');
if (strcasecmp($csrfInput, $csrfText) != 0) {
$this->buildCallbackFailMsg('csrf', 'csrf verification failed.');
return;
}
}
}

0 comments on commit 9bddfa8

Please sign in to comment.