PDA

View Full Version : مشکل پس ازفراخوانی ازدیتابیس



tamafi6
یک شنبه 17 اسفند 1393, 14:26 عصر
باسلام اگربه لینک زیرنگاه نمایید دربخش بلوک نمونه کدها که درتگ pre قرارگرفته شده کدینگ تگ هابعدازفرواخوانی ازدیتابیس به صورت همان کارکترنمایش داده میشود

http://pacifist.xzn.ir/page/?url=docs/

البته تابع اون درست نوشته شده ولی مشکل اصلی اون رانمیتونم پیداکنم دوستان آیا راه حلی به فکرتون میادممنون

نمونه تابع


function cleanXSS($val) { if ($val != "") { global $XSS_cache; if (!empty($XSS_cache) && array_key_exists($val, $XSS_cache)) return $XSS_cache[$val]; $source = html_entity_decode($val, ENT_QUOTES, 'UTF-8'); $source = preg_replace('/&#(\d+);/me','chr(\\1)', $source); $source = preg_replace('/&#x([a-f0-9]+);/mei','chr(0x\\1)', $source); while($source != filterTags($source)) { $source = filterTags($source); } $source = nl2br($source); $XSS_cache[$val] = $source; return $source; } return $val;}

bagherok
دوشنبه 18 اسفند 1393, 22:33 عصر
منظورت اینه

echo html_entity_decode('<li><button>Nav Item3</button></li&gt');

tamafi6
دوشنبه 18 اسفند 1393, 23:41 عصر
منظورت اینه

echo html_entity_decode('<li><button>Nav Item3</button></li&gt');

درسته دوست عزیز کارکترها قانونا بایدبه شکل تگ نمایش داده بشوند ولی بعداز فراخوانی از دیتابیس با این مشکل روبرو میشوند .

bagherok
دوشنبه 18 اسفند 1393, 23:48 عصر
خب این تابع شماست


function cleanXSS($val){
if ($val != ""){
global $XSS_cache;
if (!empty($XSS_cache) && array_key_exists($val, $XSS_cache)){
return $XSS_cache[$val];
}
$source = html_entity_decode($val, ENT_QUOTES, 'UTF-8');
$source = preg_replace('/&#(\d+);/me','chr(\\1)', $source);
$source = preg_replace('/&#x([a-f0-9]+);/mei','chr(0x\\1)',$source);
while($source != filterTags($source)) {
$source = filterTags($source);
}
$source = nl2br($source);
$XSS_cache[$val] = $source;
return $source;
}
return $val;
}

داده ها به چه صورتی تو دیتابیس ذخیره شدند.

خروجی خام از دیتابیس رو اینجا بذارید
و تابع filterTags

tamafi6
سه شنبه 19 اسفند 1393, 00:01 صبح
این تابع
هر مشکلی هست این داخله ولی من فکرم به جایی قد نمیده


function filterTags($source) { global $tagBlacklist; $preTag = NULL; $postTag = $source; $tagOpen_start = strpos($source, '<'); while($tagOpen_start !== FALSE) { $preTag .= substr($postTag, 0, $tagOpen_start); $postTag = substr($postTag, $tagOpen_start); $fromTagOpen = substr($postTag, 1); $tagOpen_end = strpos($fromTagOpen, '>'); if ($tagOpen_end === false) break; $tagOpen_nested = strpos($fromTagOpen, '<'); if (($tagOpen_nested !== false) && ($tagOpen_nested < $tagOpen_end)) { $preTag .= substr($postTag, 0, ($tagOpen_nested+1)); $postTag = substr($postTag, ($tagOpen_nested+1)); $tagOpen_start = strpos($postTag, '<'); continue; } $tagOpen_nested = (strpos($fromTagOpen, '<') + $tagOpen_start + 1); $currentTag = substr($fromTagOpen, 0, $tagOpen_end); $tagLength = strlen($currentTag); if (!$tagOpen_end) { $preTag .= $postTag; $tagOpen_start = strpos($postTag, '<'); } $tagLeft = $currentTag; $attrSet = array(); $currentSpace = strpos($tagLeft, ' '); if (substr($currentTag, 0, 1) == '/') { $isCloseTag = TRUE; list($tagName) = explode(' ', $currentTag); $tagName = substr($tagName, 1); } else { $isCloseTag = FALSE; list($tagName) = explode(' ', $currentTag); } if ((!preg_match('/^[a-z][a-z0-9]*$/i',$tagName)) || (!$tagName) || ((in_array(strtolower($tagName), $tagBlacklist)))) { $postTag = substr($postTag, ($tagLength + 2)); $tagOpen_start = strpos($postTag, '<'); continue; } while ($currentSpace !== FALSE) { $fromSpace = substr($tagLeft, ($currentSpace+1)); $nextSpace = strpos($fromSpace, ' '); $openQuotes = strpos($fromSpace, '"'); $closeQuotes = strpos(substr($fromSpace, ($openQuotes+1)), '"') + $openQuotes + 1; if (strpos($fromSpace, '=') !== FALSE) { if (($openQuotes !== FALSE) && (strpos(substr($fromSpace, ($openQuotes+1)), '"') !== FALSE)) $attr = substr($fromSpace, 0, ($closeQuotes+1)); else $attr = substr($fromSpace, 0, $nextSpace); } else $attr = substr($fromSpace, 0, $nextSpace); if (!$attr) $attr = $fromSpace; $attrSet[] = $attr; $tagLeft = substr($fromSpace, strlen($attr)); $currentSpace = strpos($tagLeft, ' '); } $postTag = substr($postTag, ($tagLength + 2)); $tagOpen_start = strpos($postTag, '<'); } $preTag .= $postTag; return $preTag;}
داده ها به همون شکلی که ذخیره میشوند نمایش داده میشوندولی فقط مشکل مربوط به نمایش کارکتر ها هست

باید اینجا باشه مشکل تازه دیدمش
$tagOpen_start
فالش نوشتم