1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php
/**
* Test Class for upload_tmp_dir
*
* @package PhpSecInfo
* @author Ed Finkler <coj@funkatron.com>
*/
/**
* require the PhpSecInfo_Test_Core class
*/
require_once(PHPSECINFO_BASE_DIR . '/Test/Test_Core.php');
/**
* Test Class for upload_tmp_dir
*
* @package PhpSecInfo
*/
class PhpSecInfo_Test_Core_Upload_Tmp_Dir extends PhpSecInfo_Test_Core
{
/**
* This should be a <b>unique</b>, human-readable identifier for this test
*
* @var string
*/
var $test_name = "upload_tmp_dir";
var $recommended_value = "A non-world readable/writable directory";
function _retrieveCurrentValue()
{
$this->current_value = ini_get('upload_tmp_dir');
if (empty($this->current_value)) {
if (function_exists("sys_get_temp_dir")) {
$this->current_value = sys_get_temp_dir();
} else {
$this->current_value = $this->sys_get_temp_dir();
}
}
}
/**
* We are disabling this function on Windows OSes right now until
* we can be certain of the proper way to check world-readability
*
* @return bool
*/
function isTestable()
{
if ($this->osIsWindows()) {
return FALSE;
} else {
return TRUE;
}
}
/**
* Check if upload_tmp_dir matches PHPSECINFO_TEST_COMMON_TMPDIR, or is word-writable
*
* This is still unix-specific, and it's possible that for now
* this test should be disabled under Windows builds.
*
* @see PHPSECINFO_TEST_COMMON_TMPDIR
*/
function _execTest()
{
$perms = @fileperms($this->current_value);
if ($perms === false) {
return PHPSECINFO_TEST_RESULT_WARN;
} else if ($this->current_value
&& !preg_match("|" . PHPSECINFO_TEST_COMMON_TMPDIR . "/?|", $this->current_value)
&& !($perms & 0x0004)
&& !($perms & 0x0002)
) {
return PHPSECINFO_TEST_RESULT_OK;
}
// rewrite current_value to display perms
$this->current_value .= " (" . substr(sprintf('%o', $perms), -4) . ")";
return PHPSECINFO_TEST_RESULT_NOTICE;
}
/**
* Set the messages specific to this test
*
*/
function _setMessages()
{
parent::_setMessages();
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_NOTRUN, 'en', 'Test not run -- currently disabled on Windows OSes');
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_OK, 'en', 'upload_tmp_dir is enabled, which is the
recommended setting. Make sure your upload_tmp_dir path is not world-readable');
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_WARN, 'en', 'unable to retrieve file permissions on upload_tmp_dir');
$this->setMessageForResult(PHPSECINFO_TEST_RESULT_NOTICE, 'en', 'upload_tmp_dir is disabled, or is set to a
common world-writable directory. This typically allows other users on this server
to access temporary copies of files uploaded via your PHP scripts. You should set
upload_tmp_dir to a non-world-readable directory');
}
}
|