{"id":13519167,"url":"https://github.com/paragonie/anti-csrf","last_synced_at":"2025-04-07T19:10:46.765Z","repository":{"id":27955032,"uuid":"31447912","full_name":"paragonie/anti-csrf","owner":"paragonie","description":"Full-Featured Anti-CSRF Library","archived":false,"fork":false,"pushed_at":"2024-09-11T07:56:14.000Z","size":119,"stargazers_count":302,"open_issues_count":16,"forks_count":53,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-31T18:15:42.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://paragonie.com/projects","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paragonie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-28T02:20:23.000Z","updated_at":"2025-03-06T08:11:42.000Z","dependencies_parsed_at":"2024-04-17T00:41:51.920Z","dependency_job_id":"30c4aef0-5cd9-48e4-b812-6c9e8e4770e9","html_url":"https://github.com/paragonie/anti-csrf","commit_stats":{"total_commits":88,"total_committers":17,"mean_commits":5.176470588235294,"dds":0.75,"last_synced_commit":"563a77946f424484c3e1a33fd7916a4faa01883f"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fanti-csrf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fanti-csrf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fanti-csrf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fanti-csrf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paragonie","download_url":"https://codeload.github.com/paragonie/anti-csrf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247713256,"owners_count":20983683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:01:54.906Z","updated_at":"2025-04-07T19:10:46.552Z","avatar_url":"https://github.com/paragonie.png","language":"PHP","funding_links":[],"categories":["PHP","\u003ca id=\"683b645c2162a1fce5f24ac2abfa1973\"\u003e\u003c/a\u003e漏洞\u0026\u0026漏洞管理\u0026\u0026漏洞发现/挖掘\u0026\u0026漏洞开发\u0026\u0026漏洞利用\u0026\u0026Fuzzing"],"sub_categories":["\u003ca id=\"79ed781159b7865dc49ffb5fe2211d87\"\u003e\u003c/a\u003eCSRF"],"readme":"# Anti-CSRF Library\n\n[![Build Status](https://github.com/paragonie/anti-csrf/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/anti-csrf/actions)\n[![Latest Stable Version](https://poser.pugx.org/paragonie/anti-csrf/v/stable)](https://packagist.org/packages/paragonie/anti-csrf)\n[![Latest Unstable Version](https://poser.pugx.org/paragonie/anti-csrf/v/unstable)](https://packagist.org/packages/paragonie/anti-csrf)\n[![License](https://poser.pugx.org/paragonie/anti-csrf/license)](https://packagist.org/packages/paragonie/anti-csrf)\n[![Downloads](https://img.shields.io/packagist/dt/paragonie/anti-csrf.svg)](https://packagist.org/packages/paragonie/anti-csrf)\n\n## Motivation\n\nThere aren't any good session-powered CSRF prevention libraries. By good we mean:\n\n* CSRF tokens can be restricted to any or all of the following:\n  * A particular session\n  * A particular HTTP URI\n  * A particular IP address (optional)\n* Multiple CSRF tokens can be stored\n* CSRF tokens expire after one use\n* An upper limit on the number of tokens stored with session data is enforced\n  * In our implementation, the oldest are removed first\n\n**Warning** - Do not use in any project where all `$_SESSION` data is stored \nclient-side in a cookie. This will quickly run up the 4KB storage max for \nan HTTP cookie.\n\n## Using it in Any Project\n\nSee `autoload.php` for an SPL autoloader.\n\n## Using it with Twig templates\n\nFirst, add a filter like this one:\n\n```php\nuse \\ParagonIE\\AntiCSRF\\AntiCSRF;\n$twigEnv-\u003eaddFunction(\n    new \\Twig\\TwigFunction(\n        'form_token',\n        function($lock_to = null) {\n            static $csrf;\n            if ($csrf === null) {\n                $csrf = new AntiCSRF;\n            }\n            return $csrf-\u003einsertToken($lock_to, false);\n        },\n        ['is_safe' =\u003e ['html']]\n    )\n);\n```\n\nNext, call the newly created form_token function from your templates.\n\n```twig\n\u003cform action=\"/addUser.php\" method=\"post\"\u003e\n    {{ form_token(\"/addUser.php\") }}\n\n    {# ... the rest of your form here ... #}\n\u003c/form\u003e\n```\n\n## Validating a Request\n\n```php\n    $csrf = new \\ParagonIE\\AntiCSRF\\AntiCSRF;\n    if (!empty($_POST)) {\n        if ($csrf-\u003evalidateRequest()) {\n            // Valid\n        } else {\n            // Log a CSRF attack attempt\n        }\n    }\n```\n\n## Support Contracts\n\nIf your company uses this library in their products or services, you may be\ninterested in [purchasing a support contract from Paragon Initiative Enterprises](https://paragonie.com/enterprise).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fanti-csrf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparagonie%2Fanti-csrf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fanti-csrf/lists"}