For tracing and logging purposes, we want to be able to see/generate the
list of all of the requests that happen in the environment for a given
external incoming request. To that end, allow Mediawiki to accept the
request ID provided by the incoming request as its own.
Since this may be problematic for set-ups that don't have an entity in
front of MW that sanitises the headers on the way in, introduce a new
global variable, `$wgAllowExternalReqID`, that can disable this
behaviour. By default, the feature is disabled.
Bug: T201409
Change-Id: I605471fb8b5bbc290baeecc7d80d9d715cb240c9
=== Configuration changes for system administrators in 1.34 ===
==== New configuration ====
-* …
+* $wgAllowExternalReqID (T201409) - This configuration setting controls whether
+ Mediawiki accepts the request ID set by the incoming request via the
+ `X-Request-Id` header. If set to `true`, that value will be used throughout
+ the code as the request identificator. Otherwise, the sent header will be
+ ignored and the request ID will either be taken from Apache's mod_unique
+ module or will be generated by Mediawiki itself (depending on the set-up).
==== Changed configuration ====
* …
*/
$wgHTTPConnectTimeout = 5e0;
+/**
+ * Whether to respect/honour the request ID provided by the incoming request
+ * via the `X-Request-Id` header. Set to `true` if the entity sitting in front
+ * of Mediawiki sanitises external requests. Default: `false`.
+ */
+$wgAllowExternalReqID = false;
+
/** @} */ # End HTTP client }
/************************************************************************//**
public static function getRequestId() {
// This method is called from various error handlers and should be kept simple.
- if ( !self::$reqId ) {
- self::$reqId = $_SERVER['UNIQUE_ID'] ?? wfRandomString( 24 );
+ if ( self::$reqId ) {
+ return self::$reqId;
+ }
+
+ global $wgAllowExternalReqID;
+
+ self::$reqId = $_SERVER['UNIQUE_ID'] ?? wfRandomString( 24 );
+ if ( $wgAllowExternalReqID ) {
+ $id = RequestContext::getMain()->getRequest()->getHeader( 'X-Request-Id' );
+ if ( $id ) {
+ self::$reqId = $id;
+ }
}
return self::$reqId;