common.php의 XSS함수 부분 질문드립니다. 정보
common.php의 XSS함수 부분 질문드립니다.본문
아래와 같이 common.php부분에 xss공격에 대한 함수가 선언되어 있는데요
$_GET = xss_clean($_GET); 으로 호출하던데..
$_GET은 배열이기 때문에 두번째 if문에 걸려서 값이 return 되는 것 아닌가요?
리턴된다면 함수 아래에 각종 필터링을 그냥 통과하는 것인데..
그렇다면 이 함수가 필요하지 않을것 같은데...
이부분에 대한 설명좀 부탁드립니다(__);
// XSS(Cross Site Scripting) 공격에 의한 데이터 검증 및 차단
//-----------------------------------------------------------------------------------------
function xss_clean($data)
{
// If its empty there is no point cleaning it :\
if(empty($data))
return $data;
// Recursive loop for arrays
if(is_array($data))
{
foreach($data as $key => $value)
{
$data[$key] = xss_clean($value);
}
return $data;
}
// http://svn.bitflux.ch/repos/public/popoon/trunk/classes/externalinput.php
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2006 Bitflux GmbH |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License"); |
// | you may not use this file except in compliance with the License. |
// | You may obtain a copy of the License at |
// | http://www.apache.org/licenses/LICENSE-2.0 |
// | Unless required by applicable law or agreed to in writing, software |
// | distributed under the License is distributed on an "AS IS" BASIS, |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
// | implied. See the License for the specific language governing |
// | permissions and limitations under the License. |
// +----------------------------------------------------------------------+
// | Author: Christian Stocker <*** 개인정보보호를 위한 이메일주소 노출방지 ***> |
// +----------------------------------------------------------------------+
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&amp;','&lt;','&gt;'), $data);
$data = preg_replace('/(*\w+)[\x00-\x20]+;/', '$1;', $data);
$data = preg_replace('/(*[0-9A-F]+);*/i', '$1;', $data);
if (function_exists("html_entity_decode"))
{
$data = html_entity_decode($data);
}
else
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
$data = strtr($data, $trans_tbl);
}
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#i', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#i', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#i', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#', '$1=$2nomozbinding...', $data);
// Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#i', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
do
{
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
}
while ($old_data !== $data);
return $data;
}
$_GET = xss_clean($_GET);
$_GET = xss_clean($_GET); 으로 호출하던데..
$_GET은 배열이기 때문에 두번째 if문에 걸려서 값이 return 되는 것 아닌가요?
리턴된다면 함수 아래에 각종 필터링을 그냥 통과하는 것인데..
그렇다면 이 함수가 필요하지 않을것 같은데...
이부분에 대한 설명좀 부탁드립니다(__);
// XSS(Cross Site Scripting) 공격에 의한 데이터 검증 및 차단
//-----------------------------------------------------------------------------------------
function xss_clean($data)
{
// If its empty there is no point cleaning it :\
if(empty($data))
return $data;
// Recursive loop for arrays
if(is_array($data))
{
foreach($data as $key => $value)
{
$data[$key] = xss_clean($value);
}
return $data;
}
// http://svn.bitflux.ch/repos/public/popoon/trunk/classes/externalinput.php
// +----------------------------------------------------------------------+
// | Copyright (c) 2001-2006 Bitflux GmbH |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License"); |
// | you may not use this file except in compliance with the License. |
// | You may obtain a copy of the License at |
// | http://www.apache.org/licenses/LICENSE-2.0 |
// | Unless required by applicable law or agreed to in writing, software |
// | distributed under the License is distributed on an "AS IS" BASIS, |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
// | implied. See the License for the specific language governing |
// | permissions and limitations under the License. |
// +----------------------------------------------------------------------+
// | Author: Christian Stocker <*** 개인정보보호를 위한 이메일주소 노출방지 ***> |
// +----------------------------------------------------------------------+
// Fix &entity\n;
$data = str_replace(array('&','<','>'), array('&amp;','&lt;','&gt;'), $data);
$data = preg_replace('/(*\w+)[\x00-\x20]+;/', '$1;', $data);
$data = preg_replace('/(*[0-9A-F]+);*/i', '$1;', $data);
if (function_exists("html_entity_decode"))
{
$data = html_entity_decode($data);
}
else
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
$data = strtr($data, $trans_tbl);
}
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#i', '$1>', $data);
// Remove javascript: and vbscript: protocols
$data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#i', '$1=$2nojavascript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#i', '$1=$2novbscript...', $data);
$data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#', '$1=$2nomozbinding...', $data);
// Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data);
$data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#i', '$1>', $data);
// Remove namespaced elements (we do not need them)
$data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data);
do
{
// Remove really unwanted tags
$old_data = $data;
$data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
}
while ($old_data !== $data);
return $data;
}
$_GET = xss_clean($_GET);
댓글 전체

empty()함수는 배열도 체크합니다. 그래서 그냥 return되지 않고 아래의 루프문을 수행하게 됩니다.
http://kr.php.net/manual/kr/function.empty.php
http://kr.php.net/manual/kr/function.empty.php
empty() 부분 질문이 아니라 그 아래 if(is_array)로 시작하는 부분 여쭙는거에요^^:
$_GET은 배열이니까 항상 is_array에서 true일테고 재귀호출 빠져나오면 바로아래
return $data로 인해 함수종료 되버리는데... 그 아래쪽에 있는 구문들은 실행되질 않지 않나 하는겁니다.
$_GET은 배열이니까 항상 is_array에서 true일테고 재귀호출 빠져나오면 바로아래
return $data로 인해 함수종료 되버리는데... 그 아래쪽에 있는 구문들은 실행되질 않지 않나 하는겁니다.

return 되기 전에 재귀호출이 되죠? 그렇게 배열이 아닐때까지 함수호출되서 아래문장들을 처리한 후에 다시 복귀하겠죠. 그래서 그냥 리턴되는게 아니라 할거 다 하고 값 반환하는겁니다.
아.. 제가 반만 봣네요.. 이런 ㅎㅎ;
먼지손님 감사드려요.. ~
먼지손님 감사드려요.. ~