[PHP-users 3855] Re: PHPのセキュリティモデルについて

Yasuo Ohgaki php-users@php.gr.jp
Mon, 26 Nov 2001 14:31:25 +0900


Ryuichiro Munechika wrote:

>  まいパパです
>  こんにちは^^
> 
>  昨日、関西のLinuxコミュニティ(lilo)で月例のセミナーの中で
> 初心者向けのPHPセミナーを行ったのですが、終わってからの懇親
> 会の席で、「PHPってJavaやRubyのようなセキュリティモデルって
> あるんですか?」と聞かれてしまいました。
> 
>  私は知らなかったので答えようがなかったのですが、実際はどう
> なんでしょうか?
> 
>  もし無ければ、今後実装されていく可能性はあるんでしょうかね?
> 


Javaの様なセキュリティーモデルはありませんが、安全に利用する為のの
オプションが用意されています。簡単にするために、CGI SAPI以外の場合
に限定します。

Safe Modeと言う機能が実装されていて、Open base dirを変更したりする
事ができます。Safe modeでは``(バッククオート)を使ったコマンドの実
行が出来なくなったり、ファイルのUIDとスクリプトが開こうとしている
ファイルのUIDが一致しないと開けないようになります。(4.1.0からはGID
も利用できる)

Apacheを使っている場合はVirtual Host単位にこれらの値も設定ができ、
ユーザーが勝手に設定値を変更出来なくする事もできます。ホスティング
サービスを提供する場合には必須の機能と思います。

ソースと一緒についてくるphp.iniの中に簡単な記述があります。

-- BEGIN (php.ini-recommended from 4.2.0-dev) --
;
; Safe Mode
;
safe_mode = Off

; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
safe_mode_gid = Off

; When safe_mode is on, UID/GID checks are bypassed when
; including files from this directory and its subdirectories.
; (directory must also be in include_path or full path must
; be used when including)
safe_mode_include_dir =

; When safe_mode is on, only executables located in the
safe_mode_exec_dir
; will be allowed to be executed via the exec family of functions.
safe_mode_exec_dir =

; open_basedir, if set, limits all file operations to the defined
directory
; and below.  This directive makes most sense if used in a
per-directory
; or per-virtualhost web server configuration file.
;
;open_basedir =

; Setting certain environment variables may be a potential
security breach.
; This directive contains a comma-delimited list of prefixes.  In
Safe Mode,
; the user may only alter environment variables whose names begin
with the
; prefixes supplied here.  By default, users will only be able to set
; environment variables that begin with PHP_ (e.g. PHP_FOO=BAR).
;
; Note:  If this directive is empty, PHP will let the user modify ANY
; environment variable!
safe_mode_allowed_env_vars = PHP_

; This directive contains a comma-delimited list of environment
variables that
; the end user won't be able to change using putenv().  These
variables will be
; protected even if safe_mode_allowed_env_vars is set to allow to
change them.
safe_mode_protected_env_vars = LD_LIBRARY_PATH

; This directive allows you to disable certain functions for
security reasons.
; It receives a comma-delimited list of function names.  This
directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
disable_functions =

-- END --

# マニュアルにも簡単な記述があったと思います。

--
Yasuo Ohgaki





__________________________________________________
Do You Yahoo!?
Yahoo! BB is Broadband by Yahoo!  http://bb.yahoo.co.jp/