Ignore:
Timestamp:
03/15/10 14:41:49 (14 years ago)
Author:
pedroerp
Message:

Ticket #609 - Adaptando os processos do workflow para utilizar o nova factory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/workflow/branches/609/lib/security/Security.php

    r2222 r2249  
    1616 * executing process code. 
    1717 * 
    18  * @package Factory 
     18 * @package Security 
    1919 * @license http://www.gnu.org/copyleft/gpl.html GPL 
    2020 * @author Pedro Eugênio Rocha - pedro.eugenio.rocha@gmail.com 
     
    4343         * Returns the current security mode. 
    4444         * @access public 
    45          * @return boolean 
     45         * @return boolea 
     46         * @static 
    4647         */ 
    4748        public static function isEnabled() { 
     
    5859        public static function enable() { 
    5960 
    60                 if (self::_isAllowed()) 
     61                if (self::isSafeDir()) 
    6162                        self::$_protection = true; 
    6263                else 
    63                         throw new Exception('You are not allowed to change security mode.'); 
     64                        throw new Exception('You are not allowed to change the security mode.'); 
    6465                return true; 
    6566        } 
     
    7374        public static function disable() { 
    7475 
    75                 if (self::_isAllowed()) 
     76                if (self::isSafeDir()) 
    7677                        self::$_protection = false; 
    7778                else 
    78                         throw new Exception('You are not allowed to change security mode.'); 
     79                        throw new Exception('You are not allowed to change the security mode.'); 
    7980                return true; 
     81        } 
     82 
     83 
     84        /** 
     85         * Implements the security validation. 
     86         * This function tell us if a fileName is on a safe directory. 
     87         * For safe dir we mean that no process code exists under it. 
     88         * The 'depth' parameter specifies the deepness of the file that 
     89         * we are validate. Default value is to validate the imediate 
     90         * previous function. 
     91         * 
     92         * @access public 
     93         * @return boolean 
     94         * @static 
     95         */ 
     96        public static function isSafeDir($depth = 1) { 
     97 
     98                /* our backtrace based policy */ 
     99                $backtrace = debug_backtrace(); 
     100                $originFile = $backtrace[$depth]['file']; 
     101 
     102                if (empty($originFile)) 
     103                        return false; 
     104 
     105                /* if $fileName is a file under our server root, then it's safe. */ 
     106                if (substr_compare($originFile, EGW_SERVER_ROOT, 0, strlen(EGW_SERVER_ROOT)) == 0) 
     107                        return true; 
     108                return false; 
    80109        } 
    81110 
     
    93122                $backtrace = debug_backtrace(); 
    94123 
    95                 /* TODO - These are not definitive validations */ 
     124 
    96125                /* $backtrace[1] specifies the imediate antecessor function */ 
    97                 $basedir = dirname($backtrace[1]['file']); 
     126                $originFile = basename($backtrace[1]['file']); 
    98127 
    99                 if ($basedir == dirname(__FILE__)) 
     128 
     129                /** 
     130                 * TODO - TODO - TODO - TODO 
     131                 * We all know that compare file names is a awful thing.. 
     132                 * what makes it even worse is the fact that the file name 
     133                 * could contain double slashes (e.g. //) caused by wrong 
     134                 * concatenations. So we cannot compare the whole file path. 
     135                 * Moreover, if the process has a file named $allowedFile, 
     136                 * our security will eventually fail.. 
     137                 * 
     138                 * Anyway, we should think in a better way to validate this... 
     139                 */ 
     140                if (basename($originFile) == basename($allowedFile)) 
    100141                        return true; 
    101142                return false; 
    102143        } 
    103144} 
    104  
    105145?> 
Note: See TracChangeset for help on using the changeset viewer.