[security]KVE-2026-0787 alert() JavaScript 이스케이프 누락 Stored XSS 수정
bbs/alert.php, bbs/alert_close.php 가 alert("$msg") 형태로 메시지를
JS 문자열 컨텍스트에 직접 삽입하던 부분을 수정. lib/common.lib.php 에
PHP 5.2 호환 폴백을 갖춘 get_js_safe_string() 헬퍼를 추가하고,
호출부에는 function_exists 가드를 걸어 부분 패치 환경에서도 안전하게
폴백되도록 함.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7119b4f612
commit
3de722d3df
3 files changed
+36
-2
No files matched your search
+1
-1
@@ -48,7 +48,7 @@ if($error) {
|
||||
?>
|
||||
|
||||
<script>
|
||||
alert("<?php echo $msg; ?>");
|
||||
alert(<?php echo function_exists('get_js_safe_string') ? get_js_safe_string($msg) : '""'; ?>);
|
||||
<?php if ($url) { ?>
|
||||
document.location.replace("<?php echo str_replace('&', '&', $url); ?>");
|
||||
<?php } else { ?>
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ if($error) {
|
||||
?>
|
||||
|
||||
<script>
|
||||
alert("<?php echo $msg; ?>");
|
||||
alert(<?php echo function_exists('get_js_safe_string') ? get_js_safe_string($msg) : '""'; ?>);
|
||||
try {
|
||||
window.close();
|
||||
} catch(error) {
|
||||
|
||||
@@ -179,6 +179,40 @@ function get_cookie($cookie_name)
|
||||
}
|
||||
|
||||
|
||||
// JavaScript 문자열 컨텍스트에 삽입할 값을 안전하게 이스케이프하여 따옴표를 포함한 JS 리터럴로 반환
|
||||
// PHP 5.3+ 에서는 json_encode 의 JSON_HEX_* 플래그를 사용하고, 5.2 환경에서는 직접 치환으로 폴백
|
||||
if (!function_exists('get_js_safe_string')) {
|
||||
function get_js_safe_string($s)
|
||||
{
|
||||
$s = (string)$s;
|
||||
if (defined('JSON_HEX_TAG')) {
|
||||
$flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT;
|
||||
if (defined('JSON_UNESCAPED_UNICODE')) {
|
||||
$flags |= JSON_UNESCAPED_UNICODE;
|
||||
}
|
||||
$encoded = @json_encode($s, $flags);
|
||||
if ($encoded !== false && $encoded !== null) {
|
||||
return $encoded;
|
||||
}
|
||||
}
|
||||
return '"' . strtr($s, array(
|
||||
'\\' => '\\\\',
|
||||
'"' => '\\"',
|
||||
"'" => '\\u0027',
|
||||
'/' => '\\/',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
"\t" => '\\t',
|
||||
'<' => '\\u003C',
|
||||
'>' => '\\u003E',
|
||||
'&' => '\\u0026',
|
||||
"\xE2\x80\xA8" => '\\u2028',
|
||||
"\xE2\x80\xA9" => '\\u2029',
|
||||
)) . '"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 경고메세지를 경고창으로
|
||||
function alert($msg='', $url='', $error=true, $post=false)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user