Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
This Symfony bundle provides helper to configure [Content-Security-Policy](https://developer.mozilla.org/fr/docs/Web/HTTP/CSP) headers.

It is compatible with :
* PHP 7.4
* Symfony 5.4
* PHP 7.4 | 8
* Symfony 5.4 | 6 | 7

## Installation

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
],
"require": {
"php": ">=7.4",
"symfony/framework-bundle": "^5.4 |^6.0",
"symfony/framework-bundle": "^5.4 | ^6.0 | ^7.0",
"symfony/polyfill-php80": "^1.0",
"symfony/http-foundation": "^5.4 |^6.0",
"symfony/http-kernel": "^5.4 |^6.0",
"symfony/twig-bundle": "^5.4 |^6.0"
"symfony/http-foundation": "^5.4 | ^6.0 | ^7.0",
"symfony/http-kernel": "^5.4 | ^6.0 | ^7.0",
"symfony/twig-bundle": "^5.4 | ^6.0 | ^7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.1",
Expand Down
4 changes: 2 additions & 2 deletions src/CSP.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function isEnabled(): bool
return $this->enabled;
}

public function addGroup(CSPPolicy $policy, string $groupName = null): void
public function addGroup(CSPPolicy $policy, ?string $groupName = null): void
{
$this->policies[$groupName ?? $this->defaultGroup] = $policy;
}

public function addDirective(string $directive, string $value, string $groupName = null): void
public function addDirective(string $directive, string $value, ?string $groupName = null): void
{
$this->policies[$groupName ?? $this->defaultGroup]->addPolicy($directive, $value);
}
Expand Down
6 changes: 1 addition & 5 deletions src/DependencyInjection/CSPExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
class CSPExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand All @@ -38,9 +35,8 @@ public function load(array $configs, ContainerBuilder $container): void
if ($config['default_group'] === null) {
if (\count($config['groups']) > 1) {
throw new \InvalidArgumentException('You must set default group when multiple groups are defined');
} else {
$defaultGroup = \array_key_first($config['groups']);
}
$defaultGroup = \array_key_first($config['groups']);
} else {
$defaultGroup = $config['default_group'];
}
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*
* @psalm-suppress UndefinedMethod
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('csp');
$rootNode = $treeBuilder->getRootNode();
Expand Down
6 changes: 3 additions & 3 deletions src/Twig/CSPExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getFunctions()
];
}

public function nonce(string $directive, string $groupName = null, string $nonce = null): string
public function nonce(string $directive, ?string $groupName = null, ?string $nonce = null): string
{
if ($nonce === null) {
$nonce = \base64_encode($this->generator->generate(8));
Expand All @@ -41,12 +41,12 @@ public function nonce(string $directive, string $groupName = null, string $nonce
return 'nonce="' . $nonce . '"';
}

public function scriptNonce(string $groupName = null, string $nonce = null): string
public function scriptNonce(?string $groupName = null, ?string $nonce = null): string
{
return $this->nonce(CSPDirective::SCRIPT_SRC, $groupName, $nonce);
}

public function styleNonce(string $groupName = null, string $nonce = null): string
public function styleNonce(?string $groupName = null, ?string $nonce = null): string
{
return $this->nonce(CSPDirective::STYLE_SRC, $groupName, $nonce);
}
Expand Down