Merge "(bug 39180) Set x-frame-options='DENY' for api"
authorDemon <chadh@wikimedia.org>
Fri, 31 Aug 2012 14:47:28 +0000 (14:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 31 Aug 2012 14:47:28 +0000 (14:47 +0000)
includes/DefaultSettings.php
includes/api/ApiFormatBase.php

index a24081d..bc04f08 100644 (file)
@@ -2628,6 +2628,18 @@ $wgBreakFrames = false;
  */
 $wgEditPageFrameOptions = 'DENY';
 
+/**
+ * Disallow framing of API pages directly, by setting the X-Frame-Options
+ * header. Since the API returns CSRF tokens, allowing the results to be
+ * framed can compromise your user's account security.
+ * Options are:
+ *   - 'DENY': Do not allow framing. This is recommended for most wikis.
+ *   - 'SAMEORIGIN': Allow framing by pages on the same domain.
+ *   - false: Allow all framing.
+ */
+
+$wgApiFrameOptions = 'DENY';
+
 /**
  * Disable output compression (enabled by default if zlib is available)
  */
index a8d69f5..54c90a6 100644 (file)
@@ -143,6 +143,12 @@ abstract class ApiFormatBase extends ApiBase {
 
                $this->getMain()->getRequest()->response()->header( "Content-Type: $mime; charset=utf-8" );
 
+               //Set X-Frame-Options API results (bug 39180)
+               global $wgApiFrameOptions;
+               if ( $wgApiFrameOptions ) {
+                       $this->getMain()->getRequest()->response()->header( "X-Frame-Options: $wgApiFrameOptions" );
+               }
+
                if ( $isHtml ) {
 ?>
 <!DOCTYPE HTML>