{"id":21467391,"url":"https://github.com/elusivecodes/fyrecsrf","last_synced_at":"2025-07-15T05:31:20.066Z","repository":{"id":62508460,"uuid":"477257798","full_name":"elusivecodes/FyreCSRF","owner":"elusivecodes","description":"FyreCSRF is a free, open-source CSRF protection library for PHP.","archived":false,"fork":false,"pushed_at":"2024-10-17T14:17:01.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-20T06:44:47.165Z","etag":null,"topics":["csrf","php","protection","security"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.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":"2022-04-03T06:30:08.000Z","updated_at":"2024-10-17T14:16:49.000Z","dependencies_parsed_at":"2024-08-18T03:39:38.248Z","dependency_job_id":"e5bce5b9-39f0-4c77-b266-61edeb9c7060","html_url":"https://github.com/elusivecodes/FyreCSRF","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSRF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSRF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSRF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSRF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreCSRF/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017446,"owners_count":17560511,"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":["csrf","php","protection","security"],"created_at":"2024-11-23T08:17:50.426Z","updated_at":"2024-11-23T08:17:51.243Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreCSRF\r\n\r\n**FyreCSRF** is a free, open-source CSRF protection library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Middleware](#middleware)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/csrf\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Security\\CsrfProtection;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n```php\r\n$csrfProtection = new CsrfProtection($container, $config);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*Csrf*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n- `$options` is an array containing the configuration options.\r\n    - `cookie` is an array containing CSRF cookie options.\r\n        - `name` is a string representing the cookie name, and will default to \"*CsrfToken*\".\r\n        - `expires` is a number representing the cookie lifetime, and will default to *0*.\r\n        - `domain` is a string representing the cookie domain, and will default to \"\".\r\n        - `path` is a string representing the cookie path, and will default to \"*/*\".\r\n        - `secure` is a boolean indicating whether to set a secure cookie, and will default to *true*.\r\n        - `httpOnly` is a boolean indicating whether to the cookie should be HTTP only, and will default to *false*.\r\n        - `sameSite` is a string representing the cookie same site, and will default to \"*Lax*\".\r\n    - `salt` is a string representing the CSRF session key and will default to \"*_csrfToken*\".\r\n    - `field` is a string representing the CSRF token field name, and will default to \"*csrf_token*\".\r\n    - `header` is a string representing the CSRF token header name, and will default to \"*Csrf-Token*\".\r\n    - `skipCheck` is a *Closure* that accepts a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests) as the first argument.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Csrf', $options);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *CsrfProtection* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(CsrfProtection::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$csrfProtection = $container-\u003euse(CsrfProtection::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Before Response**\r\n\r\nUpdate the [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses) before sending to client.\r\n\r\n```php\r\n$response = $csrfProtection-\u003ebeforeResponse($request, $response);\r\n```\r\n\r\n**Check Token**\r\n\r\nCheck CSRF token.\r\n\r\n- `$request` is the [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n\r\n```php\r\n$csrfProtection-\u003echeckToken($request);\r\n```\r\n\r\n**Get Cookie Token**\r\n\r\nGet the CSRF cookie token.\r\n\r\n```php\r\n$cookieToken = $csrfProtection-\u003egetCookieToken();\r\n```\r\n\r\n**Get Field**\r\n\r\nGet the CSRF token field name.\r\n\r\n```php\r\n$field = $csrfProtection-\u003egetField();\r\n```\r\n\r\n**Get Form Token**\r\n\r\nGet the CSRF form token.\r\n\r\n```php\r\n$formToken = $csrfProtection-\u003egetFormToken();\r\n```\r\n\r\n**Get Header**\r\n\r\nGet the CSRF token header name.\r\n\r\n```php\r\n$header = $csrfProtection-\u003egetHeader();\r\n```\r\n\r\n\r\n## Middleware\r\n\r\n```php\r\nuse Fyre\\Security\\Middleware\\CsrfProtectionMiddleware;\r\n```\r\n\r\n- `$csrfProtection` is a *CsrfProtection*.\r\n\r\n```php\r\n$middleware = new CsrfProtectionMiddleware($csrfProtection);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$middleware = $container-\u003ebuild(CsrfProtectionMiddleware::class);\r\n```\r\n\r\n**Handle**\r\n\r\nHandle a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n\r\n- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n- `$next` is a *Closure*.\r\n\r\n```php\r\n$response = $middleware-\u003ehandle($request, $next);\r\n```\r\n\r\nThis method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecsrf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrecsrf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecsrf/lists"}