|
MediaWiki master
|
Handle sending Content-Security-Policy headers. More...
Public Member Functions | |
| __construct (WebResponse $response, Config $mwConfig, HookContainer $hookContainer) | |
| addDefaultSrc ( $source) | |
| If possible you should use a more specific source type then default. | |
| addScriptSrc ( $source) | |
| So for example, if an extension added a special page that loaded something it might call $this->getOutput()->getCSP()->addScriptSrc( '*.example.com' );. | |
| addStyleSrc ( $source) | |
| So for example, if an extension added a special page that loaded external CSS it might call $this->getOutput()->getCSP()->addStyleSrc( '*.example.com' );. | |
| getDirectives () | |
| Get the CSP directives for the wiki. | |
| getNonce () | |
| Get the nonce if nonce is in use. | |
| sendHeaders () | |
| Send CSP headers based on wiki config. | |
Static Public Member Functions | |
| static | falsePositiveBrowser ( $ua) |
| Does this browser give false positive reports? | |
| static | getMediaHeader (string $filename) |
| Get the CSP header for a specific file. | |
| static | isNonceRequired (Config $config) |
| Should we set nonce attribute. | |
| static | sendRestrictiveHeader () |
| Output a very restrictive CSP header to disallow all active content. | |
Public Attributes | |
| const | FULL_MODE = 2 |
| const | REPORT_ONLY_MODE = 1 |
Handle sending Content-Security-Policy headers.
Definition at line 23 of file ContentSecurityPolicy.php.
| MediaWiki\Request\ContentSecurityPolicy::__construct | ( | WebResponse | $response, |
| Config | $mwConfig, | ||
| HookContainer | $hookContainer ) |
| WebResponse | $response | |
| Config | $mwConfig | |
| HookContainer | $hookContainer |
Definition at line 57 of file ContentSecurityPolicy.php.
| MediaWiki\Request\ContentSecurityPolicy::addDefaultSrc | ( | $source | ) |
If possible you should use a more specific source type then default.
So for example, if an extension added a special page that loaded something it might call $this->getOutput()->getCSP()->addDefaultSrc( '*.example.com' );
| string | $source | Source to add. e.g. blob:, *.example.com, https://example.com, example.com/foo |
Definition at line 552 of file ContentSecurityPolicy.php.
References $source.
| MediaWiki\Request\ContentSecurityPolicy::addScriptSrc | ( | $source | ) |
So for example, if an extension added a special page that loaded something it might call $this->getOutput()->getCSP()->addScriptSrc( '*.example.com' );.
| string | $source | Source to add. e.g. blob:, *.example.com, https://example.com, example.com/foo |
Definition at line 577 of file ContentSecurityPolicy.php.
References $source.
| MediaWiki\Request\ContentSecurityPolicy::addStyleSrc | ( | $source | ) |
So for example, if an extension added a special page that loaded external CSS it might call $this->getOutput()->getCSP()->addStyleSrc( '*.example.com' );.
| string | $source | Source to add. e.g. blob:, *.example.com, https://example.com, example.com/foo |
Definition at line 564 of file ContentSecurityPolicy.php.
References $source.
|
static |
Does this browser give false positive reports?
Some versions of firefox (40-42) incorrectly report a CSP violation for nonce sources, despite allowing them.
| string | $ua | User-agent header |
Definition at line 493 of file ContentSecurityPolicy.php.
| MediaWiki\Request\ContentSecurityPolicy::getDirectives | ( | ) |
Get the CSP directives for the wiki.
Definition at line 75 of file ContentSecurityPolicy.php.
References MediaWiki\MainConfigNames\CSPHeader, and MediaWiki\MainConfigNames\CSPReportOnlyHeader.
Referenced by MediaWiki\Request\ContentSecurityPolicy\sendHeaders().
|
static |
Get the CSP header for a specific file.
| string | $filename |
Definition at line 591 of file ContentSecurityPolicy.php.
References MediaWiki\MainConfigNames\CSPUploadEntryPoint, and MediaWiki\MediaWikiServices\getInstance().
| MediaWiki\Request\ContentSecurityPolicy::getNonce | ( | ) |
Get the nonce if nonce is in use.
Not currently supported or implemented.
Definition at line 538 of file ContentSecurityPolicy.php.
|
static |
Should we set nonce attribute.
| Config | $config |
Definition at line 503 of file ContentSecurityPolicy.php.
References MediaWiki\MainConfigNames\CSPHeader, MediaWiki\MainConfigNames\CSPReportOnlyHeader, and MediaWiki\Config\Config\get().
| MediaWiki\Request\ContentSecurityPolicy::sendHeaders | ( | ) |
Send CSP headers based on wiki config.
Main method that callers (OutputPage) are expected to use. As a general rule, you would never call this in an extension unless you have disabled OutputPage and are fully controlling the output.
Definition at line 97 of file ContentSecurityPolicy.php.
References MediaWiki\Request\ContentSecurityPolicy\getDirectives().
|
static |
Output a very restrictive CSP header to disallow all active content.
This is meant for endpoints that don't output normal wiki content and should never have any sort of javascript on them. For example, exceptions if output page cannot be used. In the future this might be used for things that output non-html mime types like api.php, load.php, etc.
Definition at line 615 of file ContentSecurityPolicy.php.
| const MediaWiki\Request\ContentSecurityPolicy::FULL_MODE = 2 |
Definition at line 25 of file ContentSecurityPolicy.php.
| const MediaWiki\Request\ContentSecurityPolicy::REPORT_ONLY_MODE = 1 |
Definition at line 24 of file ContentSecurityPolicy.php.