@@ -305,6 +305,21 @@ <h5 class="modal-title">Edit OS Image</h5>
305305 }
306306
307307 // Aktualisiert die entsprechende Tabellenzeile
308+ // Helper function to escape HTML special characters
309+ function escapeHtml ( str ) {
310+ if ( typeof str !== 'string' ) {
311+ if ( str === undefined || str === null ) return '' ;
312+ str = String ( str ) ;
313+ }
314+ return str
315+ . replace ( / & / g, '&' )
316+ . replace ( / < / g, '<' )
317+ . replace ( / > / g, '>' )
318+ . replace ( / " / g, '"' )
319+ . replace ( / ' / g, ''' )
320+ . replace ( / ` / g, '`' ) ;
321+ }
322+
308323 function updateTableRow ( image ) {
309324 let row = document . querySelector ( `tr[data-id="${ image . id } "]` ) ;
310325 if ( row ) {
@@ -342,24 +357,24 @@ <h5 class="modal-title">Edit OS Image</h5>
342357 // Erstelle die Zellen – hier ein Beispiel
343358 row . innerHTML = `
344359 <td>
345- <img src="${ image . icon . startsWith ( 'http' ) ? image . icon : `/images/icons/${ image . icon } ` } " alt="icon" width="40" height="40" loading="lazy">
360+ <img src="${ image . icon . startsWith ( 'http' ) ? escapeHtml ( image . icon ) : `/images/icons/${ escapeHtml ( image . icon ) } ` } " alt="icon" width="40" height="40" loading="lazy">
346361 </td>
347- <td>${ image . name } </td>
348- <td>${ image . description } </td>
349- <td>${ image . category ?. name || 'No Category' } </td>
362+ <td>${ escapeHtml ( image . name ) } </td>
363+ <td>${ escapeHtml ( image . description ) } </td>
364+ <td>${ image . category && image . category . name ? escapeHtml ( image . category . name ) : 'No Category' } </td>
350365 <td class="text-center">
351366 <div class="form-check form-switch">
352- <input class="form-check-input status-toggle" type="checkbox" role="switch" ${ image . isEnabled ? 'checked' : '' } data-id="${ image . id } " onclick="event.stopPropagation(); updateStatus(this);">
367+ <input class="form-check-input status-toggle" type="checkbox" role="switch" ${ image . isEnabled ? 'checked' : '' } data-id="${ escapeHtml ( image . id ) } " onclick="event.stopPropagation(); updateStatus(this);">
353368 </div>
354369 </td>
355370 <td class="text-center">
356371 <span class="badge ${ image . isAvailable ? 'bg-success' : 'bg-secondary' } ">${ image . isAvailable ? 'Yes' : 'No' } </span>
357372 </td>
358- <td class="text-center">${ image . redirectsCount } </td>
373+ <td class="text-center">${ escapeHtml ( image . redirectsCount ) } </td>
359374 <td class="text-center">
360375 <form action="/admin/images/delete" method="post" class="d-inline" onsubmit="return confirm('Are you sure you want to delete?');">
361- <input type="hidden" name="id" value="${ image . id } ">
362- <input type="hidden" name="_csrf" value="${ document . querySelector ( 'input[name="_csrf"]' ) . value } ">
376+ <input type="hidden" name="id" value="${ escapeHtml ( image . id ) } ">
377+ <input type="hidden" name="_csrf" value="${ escapeHtml ( document . querySelector ( 'input[name="_csrf"]' ) . value ) } ">
363378 <button type="submit" class="btn btn-sm btn-danger">
364379 <i class="bi bi-trash"></i>
365380 </button>
0 commit comments