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 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测