Skip to content

Commit 2b3b8ed

Browse files
authored
Merge pull request #9100 from kenjis/docs-ContentSecurityPolicy
docs: update PHPDoc in ContentSecurityPolicy
2 parents 6617533 + 5ba2b78 commit 2b3b8ed

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,12 +5929,6 @@
59295929
'count' => 1,
59305930
'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php',
59315931
];
5932-
$ignoreErrors[] = [
5933-
// identifier: missingType.iterableValue
5934-
'message' => '#^Property CodeIgniter\\\\HTTP\\\\ContentSecurityPolicy\\:\\:\\$validSources type has no value type specified in iterable type array\\.$#',
5935-
'count' => 1,
5936-
'path' => __DIR__ . '/system/HTTP/ContentSecurityPolicy.php',
5937-
];
59385932
$ignoreErrors[] = [
59395933
// identifier: codeigniter.superglobalAccess
59405934
'message' => '#^Accessing offset \'HTTP_USER_AGENT\' directly on \\$_SERVER is discouraged\\.$#',

system/HTTP/ContentSecurityPolicy.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ContentSecurityPolicy
3131
/**
3232
* CSP directives
3333
*
34-
* @var array<string, string>
34+
* @var array<string, string> [name => property]
3535
*/
3636
protected array $directives = [
3737
'base-uri' => 'baseURI',
@@ -166,7 +166,8 @@ class ContentSecurityPolicy
166166
protected $sandbox = [];
167167

168168
/**
169-
* Used for security enforcement
169+
* A set of endpoints to which csp violation reports will be sent when
170+
* particular behaviors are prevented.
170171
*
171172
* @var string|null
172173
*/
@@ -189,7 +190,7 @@ class ContentSecurityPolicy
189190
/**
190191
* Used for security enforcement
191192
*
192-
* @var array
193+
* @var list<string>
193194
*/
194195
protected $validSources = [
195196
'self',
@@ -242,7 +243,7 @@ class ContentSecurityPolicy
242243

243244
/**
244245
* An array of header info since we have
245-
* to build ourself before passing to Response.
246+
* to build ourselves before passing to Response.
246247
*
247248
* @var array
248249
*/
@@ -594,6 +595,9 @@ public function addPluginType($mime, ?bool $explicitReporting = null)
594595
*
595596
* @see http://www.w3.org/TR/CSP/#directive-report-uri
596597
*
598+
* @param string $uri URL to send reports. Set `''` if you want to remove
599+
* this directive at runtime.
600+
*
597601
* @return $this
598602
*/
599603
public function setReportURI(string $uri)

tests/system/HTTP/ContentSecurityPolicyTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,19 @@ public function testReportURI(): void
379379
$this->assertStringContainsString('report-uri http://example.com/csptracker;', $result);
380380
}
381381

382+
#[PreserveGlobalState(false)]
383+
#[RunInSeparateProcess]
384+
public function testRemoveReportURI(): void
385+
{
386+
$this->prepare();
387+
$this->csp->reportOnly(false);
388+
$this->csp->setReportURI('');
389+
$this->work();
390+
391+
$result = $this->getHeaderEmitted('Content-Security-Policy');
392+
$this->assertStringNotContainsString('report-uri ', $result);
393+
}
394+
382395
#[PreserveGlobalState(false)]
383396
#[RunInSeparateProcess]
384397
public function testSandboxFlags(): void

0 commit comments

Comments
 (0)