{"id":21467380,"url":"https://github.com/elusivecodes/fyrecsp","last_synced_at":"2025-07-15T05:31:23.065Z","repository":{"id":62508417,"uuid":"477247089","full_name":"elusivecodes/FyreCSP","owner":"elusivecodes","description":"FyreCSP is a free, open-source content security policy library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-20T14:04:21.000Z","size":182,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-20T15:18:45.055Z","etag":null,"topics":["content-security-policy","csp","php"],"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-03T05:28:38.000Z","updated_at":"2024-11-20T14:03:59.000Z","dependencies_parsed_at":"2022-11-02T10:16:26.490Z","dependency_job_id":"c59645ca-5716-440c-ad79-67b9ef936d26","html_url":"https://github.com/elusivecodes/FyreCSP","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.3076923076923077,"last_synced_commit":"93aa4f97e3808b2deb35f9e175f943bb04717261"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCSP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreCSP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017441,"owners_count":17560509,"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":["content-security-policy","csp","php"],"created_at":"2024-11-23T08:17:49.025Z","updated_at":"2024-11-23T08:17:49.666Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreCSP\r\n\r\n**FyreCSP** is a free, open-source content security policy 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- [Policies](#policies)\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/csp\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Security\\ContentSecurityPolicy;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$config` is a [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n```php\r\n$csp = new ContentSecurityPolicy($config);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*Csp*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `default` is an array containing the policy directives, and will default to `[]`.\r\n    - `report` is an array containing the report-only directives, and will default to *null*.\r\n    - `reportTo` is an array containing the Report-To header value, and will default to *[]*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Csp', $options);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *ContentSecurityPolicy* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(ContentSecurityPolicy::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$csp = $container-\u003euse(ContentSecurityPolicy::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Add Headers**\r\n\r\nAdd CSP headers to a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).\r\n\r\n- `$response` is a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).\r\n\r\n```php\r\n$newResponse = $csp-\u003eaddHeaders($response);\r\n```\r\n\r\n**Clear**\r\n\r\nClear all policies.\r\n\r\n```php\r\n$csp-\u003eclear();\r\n```\r\n\r\n**Create Policy**\r\n\r\nCreate a [*Policy*](#policies).\r\n\r\n- `$key` is a string representing the policy key, and should be one of either `ContentSecurityPolicy::DEFAULT` or `ContentSecurityPolicy::REPORT`.\r\n- `$directives` is an array containing the directives to add, and will default to *[]*.\r\n\r\n```php\r\n$csp-\u003ecreatePolicy($key, $directives);\r\n```\r\n\r\n**Get Policy**\r\n\r\nGet a [*Policy*](#policies).\r\n\r\n- `$key` is a string representing the policy key, and should be one of either `ContentSecurityPolicy::DEFAULT` or `ContentSecurityPolicy::REPORT`.\r\n\r\n```php\r\n$policy = $csp-\u003egetPolicy($key);\r\n```\r\n\r\n**Get Policies**\r\n\r\nGet all policies.\r\n\r\n```php\r\n$policies = $csp-\u003egetPolicies();\r\n```\r\n\r\n**Get Report To**\r\n\r\nGet the Report-To values.\r\n\r\n```php\r\n$reportTo = $csp-\u003egetReportTo();\r\n```\r\n\r\n**Has Policy**\r\n\r\nDetermine whether a policy exists.\r\n\r\n- `$key` is a string representing the policy key, and should be one of either `ContentSecurityPolicy::DEFAULT` or `ContentSecurityPolicy::REPORT`.\r\n\r\n```php\r\n$hasPolicy = $csp-\u003ehasPolicy($key);\r\n```\r\n\r\n**Set Policy**\r\n\r\nSet a policy.\r\n\r\n- `$key` is a string representing the policy key, and should be one of either `ContentSecurityPolicy::DEFAULT` or `ContentSecurityPolicy::REPORT`.\r\n- `$policy` is a [*Policy*](#policies).\r\n\r\n```php\r\n$csp-\u003esetPolicy($key, $policy);\r\n```\r\n\r\n**Set Report To**\r\n\r\nSet the Report-To values.\r\n\r\n- `$reportTo` is an array containing the [Report-To](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to) values.\r\n\r\n```php\r\n$csp-\u003esetReportTo($reportTo);\r\n```\r\n\r\n\r\n## Policies\r\n\r\n**Add Directive**\r\n\r\nAdd options to a directive.\r\n\r\n- `$directive` is a string representing the directive.\r\n- `$value` is a string, or an array of strings containing the values to add. For directives that don't require values, you can set this to *true* or *false* indicating whether to include the directive.\r\n\r\n```php\r\n$newPolicy = $policy-\u003eaddDirective($directive, $value);\r\n```\r\n\r\n**Get Directive**\r\n\r\nGet the options for a directive.\r\n\r\n- `$directive` is a string representing the directive.\r\n\r\n```php\r\n$options = $policy-\u003egetDirective($directive);\r\n```\r\n\r\n**Get Header**\r\n\r\nGet the header string.\r\n\r\n```php\r\n$header = $policy-\u003egetHeader();\r\n```\r\n\r\n**Has Directive**\r\n\r\nDetermine whether a directive exists.\r\n\r\n- `$directive` is a string representing the directive.\r\n\r\n```php\r\n$hasDirective = $policy-\u003ehasDirective($directive);\r\n```\r\n\r\n**Remove Directive**\r\n\r\nRemove a directive.\r\n\r\n- `$directive` is a string representing the directive.\r\n\r\n```php\r\n$newPolicy = $policy-\u003eremoveDirective($directive);\r\n```\r\n\r\n\r\n## Middleware\r\n\r\n```php\r\nuse Fyre\\Security\\Middleware\\CspMiddleware;\r\n```\r\n\r\n- `$csp` is a *ContentSecurityPolicy*.\r\n\r\n```php\r\n$middleware = new CspMiddleware($csp);\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(CspMiddleware::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%2Ffyrecsp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrecsp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecsp/lists"}