보안과 안전 모드

보안과 안전 모드 설정 지시어
지시어명 기본값 변경값 변경점
safe_mode "0" PHP_INI_SYSTEM PHP 6.0.0에서 제거.
safe_mode_gid "0" PHP_INI_SYSTEM PHP 4.1.0부터 존재. PHP 6.0.0에서 제거.
safe_mode_include_dir NULL PHP_INI_SYSTEM PHP 4.1.0부터 존재. PHP 6.0.0에서 제거.
safe_mode_exec_dir "" PHP_INI_SYSTEM PHP 6.0.0에서 제거.
safe_mode_allowed_env_vars "PHP_" PHP_INI_SYSTEM PHP 6.0.0에서 제거.
safe_mode_protected_env_vars "LD_LIBRARY_PATH" PHP_INI_SYSTEM PHP 6.0.0에서 제거.
open_basedir NULL PHP_INI_ALL PHP < 5.3.0에서 PHP_INI_SYSTEM
disable_functions "" php.ini PHP 4.0.1부터 존재.
disable_classes "" php.ini PHP 4.3.2부터 존재.
PHP_INI_* 모드에 대한 상세와 정의는 Where a configuration setting may be set를 참고하십시오.

위 설정 지시어에 대한 간단한 설명입니다.

safe_mode boolean

PHP의 안전 모드 활성화 여부. PHP가 --enable-safe-mode로 컴파일 되면 기본값 On, 아니면 Off.

safe_mode_gid boolean

기본값, 안전 모드는 파일이 열릴 때 UID 비교 검사를 수행한다. 이 설정을 GID 비교로 완화하려면, safe_mode_gid을 켜도록 한다. 파일 접근에 대해 UID (FALSE) 검사를 하는지, GID (TRUE) 검사를 하는지의 여부.

safe_mode_include_dir string

이 디렉토리와 하위디렉토리에서 파일을 include할 때에는 UID/GID 검사가 무시된다 (디렉토리는 include_path나 include되는 전체 경로가 되어야 한다).

PHP 4.2.0부터 이 지시어는 include_path 지시어와 같은 방식으로, 콜론(윈도우에서는 세미콜론)으로 구분하여 복수의 경로를 가질 수 있습니다. 설정 제한은 실질적으로 디렉토리명이 아닌 앞첨자(prefix)가 된다. 이말의 의미는 "safe_mode_include_dir = /dir/incl"는 "/dir/include"와 "/dir/incls"가 존재하기만 한다면 그 디렉토리도 접근이 허용된 다는 것이다. 특정 디렉토리만으로 접근을 제한하고자 하면, 슬래시로 끝내면 된다. 예를 들면: "safe_mode_include_dir = /dir/incl/" 이 지시어 값이 비어 있으면, PHP 4.2.3과 PHP 4.3.3부터 다른 UID/GID 값을 가지는 파일을 포함할 수 없습니다. 이 이전 버전에서는 모든 파일을 포함할 수 있었습니다.
safe_mode_exec_dir string

PHP가 안전 모드를 사용중이라면, system()과 그 외의 시스템 프로그램을 실행하는 함수는 이 디렉토리에 있지 않으면 프로그램 시작이 거부된다. 윈도우를 포함한 모든 환경에서 디렉토리 구분은 /를 이용해야 합니다.

safe_mode_allowed_env_vars string

특정 환경 변수를 설정하는것은 잠재적인 보안 구멍이 될수 있다. 이 지시어는 콤마-구분자 리스트의 앞첨자(prefix)를 포함한다. 안전 모드에서, 유저는 여기서 제공되는 앞첨자로 시작하는 이름을 갖는 환경변수만 변경할수 있을것이다. 기본값으로, 유저는 PHP_로 시작하는 환경 변수만 설정할수 있다. (e.g. PHP_FOO=BAR).

Note:

이 지시어가 비어있으면, PHP는 유저가 모든 환경 변수를 변경할수 없게 할것이다!

safe_mode_protected_env_vars string

이 지시어는 엔드 유저가 putenv()를 사용하여 변경할수 없는 콤마-구분자 리스트의 환경 변수를 포함한다. 이 변수들은 safe_mode_allowed_env_vars가 그들을 변경할수 있도록 설정되어있을지라도 보호될것이다.

참고: open_basedir, disable_functions, disable_classes, register_globals, display_errors, and log_errors.

safe_mode가 켜져 있으면, PHP는 현재 스크립트의 소유자(owner)가 파일 함수에 의해 제어되는 파일의 소유자(owner)나 그 디렉토리와 일치하는지 검사한다. 예를 들면:

-rw-rw-r--    1 rasmus   rasmus       33 Jul  1 19:20 script.php 
-rw-r--r--    1 root     root       1116 May 26 18:01 /etc/passwd
script.php를 실행:
<?php
 readfile
('/etc/passwd'); 
?>
안전 모드가 활성화되어 있으면 다음 에러가 보여진다.
Warning: SAFE MODE Restriction in effect. The script whose uid is 500 is not 
allowed to access /etc/passwd owned by uid 0 in /docroot/script.php on line 2

엄격한 UID 검사가 적절하지 않고, 완화된 GID 검사가 효율적인 환경일수 있다. 이런 경우는 safe_mode_gid 스위치 방식으로 지원된다. On으로 설정하면 완화된 GID 검사가 수행되고, Off (기본값)로 설정되면 UID 검사가 수행된다.

safe_mode 대신에, open_basedir 디렉토리를 설정하면, 모든 파일 제어가 특정 디렉토리 밑의 파일로만 제한됩니다. 예를 들면(아파치 httpd.conf 예):

<Directory /docroot>
  php_admin_value open_basedir /docroot 
</Directory>
open_basedir 설정으로 동일한 script.php를 실행하면 결과는 다음과 같다:
Warning: open_basedir restriction in effect. File is in wrong directory in 
/docroot/script.php on line 2 

또한 각각의 함수들을 비활성화시킬수 있다. disable_functions 지시어는 php.ini 파일 밖에서 사용될수 없다. 그래서 httpd.conf 파일의 per-virtualhost 나 per-directory 기반의 함수를 비활성화시킬수 없다. 이 지시어를 php.ini에 추가하면:

disable_functions = readfile,system
다음의 결과가 나온다:
Warning: readfile() has been disabled for security reasons in 
/docroot/script.php on line 2 

Warning

물론, 이러한 PHP 제한은 실행 중인 바이너리에선 유효하지 않습니다.

add a note add a note

User Contributed Notes 3 notes

up
6
rayro at gmx dot de
15 years ago
Theres a failure with open_basedir and per-host configuration
in apache as described in bug #42836: http://bugs.php.net/bug.php?id=42836

I got the same errors on my development windows system and apache 2.2.4 with php 5.3.beta1.

This error (or similar) is shown:
Warning: Unknown: open_basedir restriction in effect. File(...)
is not within the allowed path(s): (� �� �@5�,�)

Fix:
  - try slashes at the end of the folder name
  or
  - put "php_admin_value open_basedir ..." at first of all in the configuration
up
-2
Anonymous
6 years ago
bad/missing config values for the Plesk server running the whole thing. I just followed the directions here: https://vb.3dlat.com/

You can configure PHP to have a separate error log file for each VirtualHost definition. The trick is knowing exactly how to set it up, because you can’t touch the configuration directly without breaking Plesk. Every domain name on your (dv) has its own directory in /var/www/vhosts. A typical directory has the following top level directories:

cgi-bin/
conf/
error_docs/
httpdocs/
httpsdocs/
...and so on

You’ll want to create a vhost.conf file in the domain directory’s conf/ folder with the following lines:

php_value error_log /path/to/error_log
php_flag display_errors off
php_value error_reporting 6143
php_flag log_errors on

Change the first value to match your actual installation (I used /tmp/phperrors.log). After you’re done editing the vhost.conf file, test the configuration from the console with:

apachectl configtest
…or if you don’t have apachectl (as Plesk 8.6 doesn’t seem to)…

/etc/init.d/httpd configtest

And finally tell Plesk that you’ve made this change.

/usr/local/psa/admin/bin/websrvmng -a
up
-13
Anonymous
6 years ago
Whether to enable PHP's safe mode. If PHP is compiled with --enable-safe-mode then defaults to On, otherwise Off. http://www.wikibanat.com
To Top