feat: Add CSRF tokens to all JavaScript fetch calls and fix XSS
Security improvements across all JavaScript files: CSRF Protection: - assets/js/ticket.js - Added X-CSRF-Token header to 5 fetch calls (update_ticket.php x3, add_comment.php, assign_ticket.php) - assets/js/dashboard.js - Added X-CSRF-Token to 8 fetch calls (update_ticket.php x2, bulk_operation.php x6) - assets/js/settings.js - Added X-CSRF-Token to user preferences save - assets/js/advanced-search.js - Added X-CSRF-Token to filter save/delete XSS Prevention: - assets/js/ticket.js:183-209 - Replaced insertAdjacentHTML() with safe DOM API (createElement/textContent) to prevent script injection in comment rendering. User-supplied data (user_name, created_at) now auto-escaped via textContent. All state-changing operations now include CSRF token validation. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -156,7 +156,10 @@ async function saveCurrentFilter() {
|
||||
try {
|
||||
const response = await fetch('/api/saved_filters.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({
|
||||
filter_name: filterName.trim(),
|
||||
filter_criteria: filterCriteria
|
||||
@@ -319,7 +322,10 @@ async function deleteSavedFilter() {
|
||||
try {
|
||||
const response = await fetch('/api/saved_filters.php', {
|
||||
method: 'DELETE',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': window.CSRF_TOKEN
|
||||
},
|
||||
body: JSON.stringify({ filter_id: filterId })
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user