프로젝트
GitHub에서 보기
paragonie/anti-csrf
소개
기능이 풍부한 CSRF 방지 라이브러리
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalAnti-CSRF Library
Motivation
There aren't any good session-powered CSRF prevention libraries. By good we mean:
- CSRF tokens can be restricted to any or all of the following:
- A particular session
- A particular HTTP URI
- A particular IP address (optional)
- Multiple CSRF tokens can be stored
- CSRF tokens expire after one use
- An upper limit on the number of tokens stored with session data is enforced
- In our implementation, the oldest are removed first
Warning - Do not use in any project where all $_SESSION data is stored
client-side in a cookie. This will quickly run up the 4KB storage max for
an HTTP cookie.
Using it in Any Project
See autoload.php for an SPL autoloader.
Using it with Twig templates
First, add a filter like this one:
use \ParagonIE\AntiCSRF\AntiCSRF;
$twigEnv->addFunction(
new \Twig\TwigFunction(
'form_token',
function($lock_to = null) {
static $csrf;
if ($csrf === null) {
$csrf = new AntiCSRF;
}
return $csrf->insertToken($lock_to, false);
},
['is_safe' => ['html']]
)
);
Next, call the newly created form_token function from your templates.
<form action="/addUser.php" method="post">
{{ form_token("/addUser.php") }}
{# ... the rest of your form here ... #}
</form>
Validating a Request
$csrf = new \ParagonIE\AntiCSRF\AntiCSRF;
if (!empty($_POST)) {
if ($csrf->validateRequest()) {
// Valid
} else {
// Log a CSRF attack attempt
}
}
Support Contracts
If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises.
관련 프로젝트 살펴보기
불러오는 중…