0
eval 함수를 실행하면 json 응답이 객체로 변환되지 않고 코드가 중단됩니다. prototype.js와 JSON2.js를 사용하여 파싱을 시도했지만 일부는 여기서 잘못 설명하고 있습니까?내 평가가 json 문자열을 객체로 변환하지 않는 이유
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Inventory Management</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script src="call.js" type="text/javascript"></script>
<script src="prototype.js" type="text/javascript"></script>
</head>
<body>
<div>
<p id="resp" >new</p>
<script type="text/javascript">
var xhr;
var results=getPlants(xhr,results);
var plants;
function getPlants(xhr,results){
try {
xhr=new XMLHttpRequest();
}catch(microsoft){
try{
xhr=new ActiveXObject("Msxml2.XMLHTTP");
}catch(othermicrosoft){
try{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}catch(failed){
xhr=false;
alert("ajax not supported");
}
}
}
xhr.onreadystatechange= function() {
if(xhr.readyState==4 && xhr.status==200) {
results = xhr.responseText;
}
}
xhr.open("GET","db_interactions.php",true);
xhr.send(null);
alert("sent");
return results;
}
plants = eval('('+results+')');
document.write(typeof(plants));
</script>
</div>
</body>
</html>
응답이 신뢰할 수있는 출처에서오고, getPlants 정의 외부에서 결과를 인쇄 할 때 적절한 데이터를 반환합니다. 알아 내고자하는 모든 것은 내가 eval 함수를 어떻게 사용하고 있는지 잘못되었습니다. 데이터를 올바르게 역 직렬화시키지 않고 필자가 사용했던 데이터를 직렬화하십시오. –
"신뢰할 수있는"소스가 XSS를 유발하는 다른 곳의 취약점을 가지고 있는지 여부를 알 수 없습니다. 항상 공격면을 최소화하십시오. 게다가 JSON 구문 분석기는'eval'보다 빠를 가능성이 높습니다 (Safari의 eval은 JSON.parse보다 JSON을 구문 분석하는 데 36 % 더 시간이 걸립니다). – kennytm