44 $logname = $reportOnly ?
'csp-report-only' :
'csp';
45 $this->log = LoggerFactory::getInstance( $logname );
46 $userAgent = $this->
getRequest()->getHeader(
'user-agent' );
55 'csp-report' => $report,
56 'method' => __METHOD__,
57 'user' => $this->
getUser()->getName(),
58 'user-agent' => $userAgent,
71 if ( in_array(
'false-positive',
$flags ) ) {
73 $this->log->debug( $logLine,
$context );
76 $this->log->warning( $logLine,
$context );
89 $falsePositives = $this->
getConfig()->get(
'CSPFalsePositiveUrls' );
100 ( isset( $report[
'blocked-uri'] ) &&
101 isset( $falsePositives[$report[
'blocked-uri']] ) )
102 || ( isset( $report[
'source-file'] ) &&
103 isset( $falsePositives[$report[
'source-file']] ) )
106 $flags[] =
'false-positive';
116 $contentType =
$req->getHeader(
'content-type' );
117 if ( $contentType !==
'application/json'
118 && $contentType !==
'application/csp-report'
120 $this->
error(
'wrongformat', __METHOD__ );
122 if (
$req->getHeader(
'content-length' ) > self::MAX_POST_SIZE ) {
123 $this->
error(
'toobig', __METHOD__ );
133 $postBody = $this->
getRequest()->getRawInput();
134 if ( strlen( $postBody ) > self::MAX_POST_SIZE ) {
136 $this->
error(
'toobig', __METHOD__ );
138 $status = FormatJson::parse( $postBody, FormatJson::FORCE_ASSOC );
146 if ( !isset( $report[
'csp-report'] ) ) {
147 $this->
error(
'missingkey', __METHOD__ );
149 return $report[
'csp-report'];
162 $flagText =
'[' . implode(
$flags,
', ' ) .
']';
165 $blockedFile = isset( $report[
'blocked-uri'] ) ? $report[
'blocked-uri'] :
'n/a';
166 $page = isset( $report[
'document-uri'] ) ? $report[
'document-uri'] :
'n/a';
167 $line = isset( $report[
'line-number'] ) ?
':' . $report[
'line-number'] :
'';
168 $warningText = $flagText .
169 ' Received CSP report: <' . $blockedFile .
170 '> blocked from being loaded on <' .
$page .
'>' .
$line;
182 $this->log->info(
'Error reading CSP report: ' .
$code, [
184 'user-agent' => $this->
getRequest()->getHeader(
'user-agent' )
187 $this->
dieUsage(
"Error processing CSP report: $code",
'cspreport-' .
$code, 500 );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_REQUIRED
(boolean) Is the parameter required?
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
getErrorFromStatus( $status, &$extraData=null)
Get error (as code, string) from a Status object.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getResult()
Get the result object.
getModuleName()
Get the name of the module being executed by this instance.
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Api module to receive and log CSP violation reports.
getReport()
Get the report from post body and turn into associative array.
error( $code, $method)
Stop processing the request, and output/log an error.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Logs a content-security-policy violation report from web browser.
getFlags( $report)
Get extra notes about the report.
shouldCheckMaxLag()
Doesn't touch db, so max lag should be rather irrelavent.
isReadMode()
Even if you don't have read rights, we still want your report.
logReport( $flags, $logLine, $context)
Log CSP report, with a different severity depending on $flags.
const MAX_POST_SIZE
These reports should be small.
mustBePosted()
Indicates whether this module must be called with a POST request.
isWriteMode()
Indicates whether this module requires write mode.
isInternal()
Mark as internal.
generateLogLine( $flags, $report)
Get text of log line.
verifyPostBodyOk()
Output an api error if post body is obviously not OK.
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only $req
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
it s the revision text itself In either if gzip is the revision text is gzipped $flags
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
processing should stop and the error should be shown to the user * false
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php