douyun1950 2014-03-25 00:32
浏览 37
已采纳

Codeigniter Ajax风险与Get

What are the security implications of using GET method in Ajax and what methods I should adopt to counter threats in the following example?

In a very simple implement, I've a Ajax-codeigniter code like following... There are no form submissions and database connections.. I just want to get output of a php function (targetfucntion in the code) to webpage (at targetDiv Div in HTML) Anybody can see that webpage, no login needed...

I have read GET is bit insecure as opposed to POST. I tried to use POST method, but it had some issues. So couldn't go with that. So I'm using GET method. Should I take any precautions like input sanitation etc.. Please help me with this! Thank you!

Controller

class Thecontroller extends CI_Controller
{
    function __construct()
    {
            parent::__construct();
            $this->load->helper('url');
    }

   function idea_generator() {
       $this->load->view('myviewfile');
   }

   function targetfunction() {
echo somefunction();
   }
}

?>

View File - "myviewfile"

<html>
<head>
<title>Title</title>
<script language="javascript">
var XMLHttpRequestObject = false;

if(window.XMLHttpRequest) {
 XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
 XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource,divID)
{
 if(XMLHttpRequestObject) {
   var obj = document.getElementById(divID);
   XMLHttpRequestObject.open("GET",dataSource);

   XMLHttpRequestObject.onreadystatechange = function()
   {
   if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
   {
       obj.innerHTML = XMLHttpRequestObject.responseText;
   }
   }

   XMLHttpRequestObject.send(null);

  }


}

</script>
</head>
<body>
<h1>My Cool App</h1>
<input type="button" value ="Submit!!" onclick="getData('targetfunction','targetDiv')">
<div id="targetDiv">
<p>The fetched message will appear here </p>
</div>
</body>

</html>
  • 写回答

1条回答 默认 最新

  • dongyu5104 2014-03-25 00:39
    关注

    If there is no form submission and CodeIgniter does not accept any input via $this->input->get() or $_GET (parameters after the URL, i.e. ?var1=value&var2=value2) in the targetfunction() method, then there are no security holes that I can think of.

    Also, CodeIgniter sanitizes some strange characters in GET requests by default also.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染