I have a small social networking site built in CodeIgniter. Any registered user can send messages to others by visiting their profile.
Today I noticed that one user sent bulk messages to 200 users. How he was able to do that?
Suggestions to make the code secure are welcome.
I have a textarea and a send button on the profile page.
jQuery code on profile page (View)
$("#send").click(function(event){
var msg=$("#quick_message").val();
var uid=$(this).attr('uid');
if(msg.length > 0) {
$("#msg_status").html('<span id="loading_content"></span>');
$.post("<?=base_url()?>message/send_message", {"ids":uid,"msg":msg}, function(data){
$("#msg_status").html('<span class="errorsuc">Message sent.</span>');
$("#quick_message").val('');
});
} else {
$("#msg_status").html('<span class="errormsg">Write something to send message.</span>');
}
});
Here is my controller
// send message
function send_message()
{
if (!$this->users->is_logged_in()) {
redirect('signin');
}
$user_id=$this->session->userdata('user_id');
$ids=trim($this->input->post('ids'));
$msg=trim($this->input->post('msg'));
$msg=htmlspecialchars($msg);
$msg=$this->replaceTolink($msg);
$msg=$this->replaceTowinks($msg);
$pieces=explode(",", $ids);
foreach ($pieces as &$user_id2) {
$this->db->insert('messages', array('user_id1' => $user_id,'user_id2' => $user_id2,'message' => $msg));
}
return true;
}
What I need to improve in my code and how to protect the code to send bulk messages?