Dotclear


Ignore:
Timestamp:
07/21/16 14:07:55 (9 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add adminPageHTTPHeaders behavior : give third party code opportunity to modify, add or reset some HTTP headers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.dc.page.php

    r3278 r3279  
    9090 
    9191          # Display 
    92           header('Content-Type: text/html; charset=UTF-8'); 
    93  
    94           // Prevents Clickjacking as far as possible 
     92          $headers = new arrayobject(array()); 
     93 
     94          # Content-Type 
     95          $headers['content-type'] = 'Content-Type: text/html; charset=UTF-8'; 
     96 
     97          # Prevents Clickjacking as far as possible 
    9598          if (isset($options['x-frame-allow'])) { 
    96                self::setXFrameOptions($options['x-frame-allow']); 
     99               self::setXFrameOptions($headers,$options['x-frame-allow']); 
    97100          } else { 
    98                self::setXFrameOptions(); 
     101               self::setXFrameOptions($headers); 
    99102          } 
    100103 
    101104          # Content-Security-Policy (report only up to now) 
    102           header( 
     105          $headers['csp'] = 
    103106               "Content-Security-Policy: ". 
    104107                    "default-src 'self' ; ". 
     
    106109                    "style-src 'self' 'unsafe-inline' ; ". 
    107110                    "img-src 'self' data: media.dotaddict.org". 
    108                     (version_compare(phpversion(),'5.4','>=') ? " ; report-uri ".DC_ADMIN_URL."csp_report.php" : '') 
    109                ); 
     111                    (version_compare(phpversion(),'5.4','>=') ? " ; report-uri ".DC_ADMIN_URL."csp_report.php" : ''); 
     112 
     113          # --BEHAVIOR-- adminPageHTTPHeaders 
     114          $core->callBehavior('adminPageHTTPHeaders',$headers); 
     115          foreach ($headers as $key => $value) { 
     116               header($value); 
     117          } 
    110118 
    111119          echo 
     
    10231031     } 
    10241032 
    1025      public static function setXFrameOptions($origin = null) 
     1033     public static function setXFrameOptions($headers,$origin = null) 
    10261034     { 
    10271035          if (self::$xframe_loaded) { 
     
    10301038          if ($origin !== null) { 
    10311039               $url = parse_url($origin); 
    1032                header(sprintf('X-Frame-Options: %s',is_array($url) ? 
     1040               $headers['x-frame-options'] = sprintf('X-Frame-Options: %s',is_array($url) ? 
    10331041                    ("ALLOW-FROM ".(isset($url['scheme']) ? $url['scheme'].':' : '' ).'//'.$url['host']) : 
    1034                     'SAMEORIGIN')); 
     1042                    'SAMEORIGIN'); 
    10351043          } else { 
    1036                header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+ 
     1044               $headers['x-frame-options'] = 'X-Frame-Options: SAMEORIGIN'; // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+ 
    10371045          } 
    10381046          self::$xframe_loaded = true; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map