Skip to content

Commit 14f450b

Browse files
committed
XSS Prevention
1 parent 1a640b9 commit 14f450b

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ Sign-in your first user and login
8888
#### Maintainers
8989

9090
- [Ganesh Kandu](https://github.com/GaneshKandu)
91-
- [Linkedin](https://www.linkedin.com/in/ganesh-kandu-42b14373/)
91+
- [Linkedin](https://www.linkedin.com/in/ganeshkandu/)

app/Http/Controllers/KchatController.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ function kchat(Request $request){
7474
$data['messages'] = array_reverse($data['messages']);
7575
}
7676

77+
foreach($data['messages'] as $i => $v){
78+
$data['messages'][$i]->first_name = htmlentities($data['messages'][$i]->first_name);
79+
$data['messages'][$i]->last_name = htmlentities($data['messages'][$i]->last_name);
80+
$data['messages'][$i]->message = htmlentities($data['messages'][$i]->message);
81+
}
82+
7783
if(count($data['messages'])){
7884

7985
if(end($data['messages'])->id > session()->get('message_id')){
@@ -106,13 +112,22 @@ function kchat(Request $request){
106112
}
107113

108114
$data['chats'] = $tmp->get()->toArray();
115+
116+
foreach($data['chats'] as $i => $v){
117+
$data['chats'][$i]->conversation_name = htmlentities($data['chats'][$i]->conversation_name);
118+
$data['chats'][$i]->first_name = htmlentities($data['chats'][$i]->first_name);
119+
$data['chats'][$i]->last_name = htmlentities($data['chats'][$i]->last_name);
120+
$data['chats'][$i]->message = htmlentities($data['chats'][$i]->message);
121+
}
109122

110123
if(count($data['chats'])){
111124
if(end($data['chats'])->mid > session()->get('chat_id')){
112125
session()->put('chat_id', end($data['chats'])->mid);
113126
}
114127
}
115-
128+
129+
//print_r($data);
130+
116131
return json_encode($data);
117132
}
118133

public/js/kchat.msg.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ $(document).ready (function(){
190190
LoadMessage = true;
191191
},
192192
error: function(result){
193-
193+
LoadMessage = true;
194194
}
195195
});
196196
}
@@ -242,38 +242,33 @@ $(document).ready (function(){
242242

243243
});
244244

245-
search_convo = true;
246-
247245
$("#convo_like").keyup(function() {
248246

249247
Search = {};
250248

251249
Search['_token'] = $('meta[name="csrf_token"]').attr('content');
252250
Search['convo_like'] = $(this).val();
253251

254-
if(search_convo){
255-
search_convo = false;
256-
$.ajax({
257-
type: "POST",
258-
url: '/getConvo',
259-
data: Search,
260-
success: function(results){
261-
search_convo = true;
262-
results = $.parseJSON(results);
263-
html = '';
264-
results.forEach(function(element){
265-
html += `<tr>
266-
<td><a href="/messages/?chat=${element.id}" ><img src="${element.photo}" class="rounded-circle my-n1" alt="[Photo]" width="32" height="32"></a></td>
267-
<td><a href="/messages/?chat=${element.id}" >${element.conversation_name}</a></td>
268-
</tr>`
269-
});
270-
$('#ConvoList').html(html);
271-
},
272-
error: function(result){
273-
274-
}
275-
});
276-
}
252+
$.ajax({
253+
type: "POST",
254+
url: '/getConvo',
255+
data: Search,
256+
success: function(results){
257+
search_convo = true;
258+
results = $.parseJSON(results);
259+
html = '';
260+
results.forEach(function(element){
261+
html += `<tr>
262+
<td><a href="/messages/?chat=${element.id}" ><img src="${element.photo}" class="rounded-circle my-n1" alt="[Photo]" width="32" height="32"></a></td>
263+
<td><a href="/messages/?chat=${element.id}" >${element.conversation_name}</a></td>
264+
</tr>`
265+
});
266+
$('#ConvoList').html(html);
267+
},
268+
error: function(result){
269+
270+
}
271+
});
277272

278273
});
279274

0 commit comments

Comments
 (0)