Conversation
| var jam_peresepan = $(this).attr("data-jam_peresepan"); | ||
| var tipe = $(this).attr("data-tipe"); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ralan/cetaklabel/' + no_rawat +'/' + tipe +'/' + tgl_peresepan + '?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ralan/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that any data inserted into the HTML is properly escaped to prevent XSS attacks. Instead of using .html(), we can use .text() for text content and set attributes directly for other data. For the iframe src, we can construct the URL safely and set it using jQuery's .attr() method.
| @@ -214,3 +214,5 @@ | ||
| var tipe = $(this).attr("data-tipe"); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ralan/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| var iframeSrc = baseURL + '/apotek_ralan/cetaklabel/' + encodeURIComponent(kode_brng) + '/' + encodeURIComponent(no_rawat) + '/' + encodeURIComponent(tgl_peresepan) + '/' + encodeURIComponent(jam_peresepan) + '/' + encodeURIComponent(tipe) + '?t=' + encodeURIComponent(mlite.token); | ||
| $("#cetakEtiket").modal('show').find('.modal-body .cetak-kartu').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| $("#cetakEtiket").find('iframe').attr('src', iframeSrc); | ||
| }) | ||
| @@ -222,3 +224,5 @@ | ||
| var tipe = $(this).attr("data-tipe"); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:700px;height:900px;"><iframe src="' + baseURL + '/apotek_ralan/cetakeresep/' + no_rawat +'/' + tipe +'/' + tgl_peresepan + '/' + jam_peresepan + '?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| var iframeSrc = baseURL + '/apotek_ralan/cetakeresep/' + encodeURIComponent(no_rawat) + '/' + encodeURIComponent(tipe) + '/' + encodeURIComponent(tgl_peresepan) + '/' + encodeURIComponent(jam_peresepan) + '?t=' + encodeURIComponent(mlite.token); | ||
| $("#cetakEtiket").modal('show').find('.modal-body .cetak-kartu').html('<div style="text-align:center;margin:20px auto;width:700px;height:900px;"><iframe frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| $("#cetakEtiket").find('iframe').attr('src', iframeSrc); | ||
| }) |
| var tipe = $(this).attr("data-tipe"); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ranap/cetaklabel/' + no_rawat +'/' + tipe +'/' + tgl_peresepan + '?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| // alert(baseURL + '/apotek_ranap/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ranap/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that any user-controlled data is properly sanitized or escaped before being inserted into the HTML. Instead of using the .html() method, which can interpret the string as HTML, we should use the .text() method for text content or construct the DOM elements in a safer way.
In this case, we can create the iframe element using jQuery and set its attributes directly, which avoids the need to construct an HTML string and reduces the risk of XSS.
| @@ -215,3 +215,13 @@ | ||
| // alert(baseURL + '/apotek_ranap/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:500px;height:360px;"><iframe src="' + baseURL + '/apotek_ranap/cetaklabel/' + kode_brng +'/' + no_rawat +'/' + tgl_peresepan +'/' + jam_peresepan + '/' + tipe +'?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| var iframeSrc = baseURL + '/apotek_ranap/cetaklabel/' + encodeURIComponent(kode_brng) + '/' + encodeURIComponent(no_rawat) + '/' + encodeURIComponent(tgl_peresepan) + '/' + encodeURIComponent(jam_peresepan) + '/' + encodeURIComponent(tipe) + '?t=' + encodeURIComponent(mlite.token); | ||
| var iframe = $('<iframe>', { | ||
| src: iframeSrc, | ||
| frameborder: 'no', | ||
| width: '100%', | ||
| height: '100%' | ||
| }); | ||
| var div = $('<div>', { | ||
| style: 'text-align:center;margin:20px auto;width:500px;height:360px;' | ||
| }).append(iframe); | ||
| $("#cetakEtiket").modal('show').html(div); | ||
| }) | ||
| @@ -223,3 +233,13 @@ | ||
| var tipe = $(this).attr("data-tipe"); | ||
| $("#cetakEtiket").modal('show').html('<div style="text-align:center;margin:20px auto;width:700px;height:900px;"><iframe src="' + baseURL + '/apotek_ranap/cetakeresep/' + no_rawat +'/' + tipe +'/' + tgl_peresepan + '/' + jam_peresepan + '?t=' + mlite.token + '" frameborder="no" width="100%" height="100%"></iframe></div>'); | ||
| var iframeSrc = baseURL + '/apotek_ranap/cetakeresep/' + encodeURIComponent(no_rawat) + '/' + encodeURIComponent(tipe) + '/' + encodeURIComponent(tgl_peresepan) + '/' + encodeURIComponent(jam_peresepan) + '?t=' + encodeURIComponent(mlite.token); | ||
| var iframe = $('<iframe>', { | ||
| src: iframeSrc, | ||
| frameborder: 'no', | ||
| width: '100%', | ||
| height: '100%' | ||
| }); | ||
| var div = $('<div>', { | ||
| style: 'text-align:center;margin:20px auto;width:700px;height:900px;' | ||
| }).append(iframe); | ||
| $("#cetakEtiket").modal('show').html(div); | ||
| }) |
No description provided.