Looks like this issue was fixed in PHP 5.3 https://bugs.php.net/bug.php?id=39863
PHP, dosya sistemi ile ilgili işlemler için kod seviyesinde C işlevlerini kullandığından boş baytlı (\0) dizgeler beklenmedik davranışlara yol açabilir. Boş bayt, C'de dizgeleri sonlandırmak için kullanıldığından boş bayt içeren dizgelerin tamamı değil, boş bayta kadar olan bölüm işleme sokulur. Aşağıdaki örnekte bunun sebep olduğu bir sorun ele alınmıştır:
Örnek 1 - Boş baytlardan olumsuz etkilenen bir betik
<?php
$dosya = $_GET['dosya']; // "../../etc/passwd\0"
if (file_exists('/home/siteler/'.$dosya.'.php')) {
/* /home/siteler/../../etc/passwd mevcut olduğundan
file_exists işlevi TRUE döndürür */
include '/home/siteler/'.$dosya.'.php';
// /etc/passwd dosyası betiğe dahil edildi
}
?>
Bu bakımdan, bir dosya sistemi işleminde kullanılan her dizge daima denetlenmelidir. Aşağıda, önceki örneğin iyileştirilmişi verilmiştir:
Örnek 2 - Girdiyi doğru şekilde ele almak
<?php
$dosya = $_GET['dosya'];
// Kabul edilebilir değerlerin listesi
switch ($file) {
case 'main':
case 'foo':
case 'bar':
include '/home/siteler/include/'.$dosya.'.php';
break;
default:
include '/home/siteler/include/main.php';
}
?>
Looks like this issue was fixed in PHP 5.3 https://bugs.php.net/bug.php?id=39863
Since problems with null bytes do not stretch to regular string functions, this should be enough to ensure no GET parameter contains them any more:
<?php
function getVar($name)
{
$value = isset($_GET[$name]) ? $_GET[$name] : null;
if (is_string($value)) {
$value = str_replace("\0", '', $value);
}
}
?>
Modifying this to work with other superglobals should not be a problem, so I will leave it up to you.