16 public const CONSTRUCTOR_OPTIONS = [
29 private $responseFactory;
45 $this->options = $options;
46 $this->responseFactory = $responseFactory;
64 && !$this->user->isRegistered()
66 $origin = Origin::parseHeaderList( $request->
getHeader(
'Origin' ) );
68 if ( !$this->allowOrigin( $origin ) ) {
69 return 'rest-cross-origin-anon-write';
80 private function allowOrigin(
Origin $origin ): bool {
81 $allowed = array_merge( [ $this->getCanonicalDomain() ],
85 return $origin->
match( $allowed, $excluded );
91 private function getCanonicalDomain(): string {
114 $allowedOrigin =
'*';
116 if ( $this->options->get( MainConfigNames::RestAllowCrossOriginCookieAuth ) ) {
125 $response->
addHeader(
'Vary',
'Origin' );
128 if ( $request->hasHeader(
'Origin' ) ) {
129 $origin = Origin::parseHeaderList( $request->getHeader(
'Origin' ) );
130 if ( $this->allowOrigin( $origin ) ) {
134 if ( $request->getMethod() ===
'OPTIONS' || $this->user->isRegistered() ) {
149 if ( $allowedOrigin !==
'*' ) {
150 $response->setHeader(
'Access-Control-Allow-Credentials',
'true' );
153 $response->setHeader(
'Access-Control-Allow-Origin', $allowedOrigin );
165 $response = $this->responseFactory->createNoContent();
166 $response->
setHeader(
'Access-Control-Allow-Methods', $allowedMethods );
168 $allowedHeaders = $this->options->get( MainConfigNames::AllowedCorsHeaders );
169 $allowedHeaders = array_merge( $allowedHeaders, array_diff( [
178 ], $allowedHeaders ) );
179 $response->setHeader(
'Access-Control-Allow-Headers', $allowedHeaders );
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
A class containing constants representing the names of configuration variables.
const CrossSiteAJAXdomainExceptions
Name constant for the CrossSiteAJAXdomainExceptions setting, for use with Config::get()
const CanonicalServer
Name constant for the CanonicalServer setting, for use with Config::get()
const AllowCrossOrigin
Name constant for the AllowCrossOrigin setting, for use with Config::get()
const AllowedCorsHeaders
Name constant for the AllowedCorsHeaders setting, for use with Config::get()
const CrossSiteAJAXdomains
Name constant for the CrossSiteAJAXdomains setting, for use with Config::get()
const RestAllowCrossOriginCookieAuth
Name constant for the RestAllowCrossOriginCookieAuth setting, for use with Config::get()