-
Notifications
You must be signed in to change notification settings - Fork 13
feat: tambahkan parameter identitas openkab #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rilis-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,18 @@ import $ from 'jquery'; | |
| import '../vendor/bootstrap-5.3.2/js/bootstrap.bundle.min'; | ||
| import 'chart.js/dist/Chart.min'; | ||
| import 'select2/dist/js/select2.full.min'; | ||
| import { filter } from 'lodash'; | ||
|
|
||
| window.$ = $; | ||
| window.jQuery = $; | ||
| window.bootstrap = bootstrap; | ||
| $.ajaxSetup({ | ||
| beforeSend: function (xhr, settings) { | ||
| const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] ⚡ Performance: jQuery Selector Tanpa Cache di AJAX beforeSend Masalah: Selector Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');Dampak:
Fix: // Cache selector di luar ajaxSetup (hanya query 1x saat page load)
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content') || '';
$.ajaxSetup({
beforeSend: function(xhr, settings) {
// Gunakan cached value
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}
}
});There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] 📝 Code Quality: Missing Null/Undefined Check Kategori: JS Quality Masalah: Kode langsung menggunakan Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;Fix: $.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
// Guard clause: skip jika meta tag tidak ada
if (!identitasOpenkab) {
console.warn('Meta tag identitas-openkab tidak ditemukan, AJAX request tanpa kode_kabupaten');
return;
}
const params = `kode_kabupaten=${identitasOpenkab}&filter[kode_kabupaten]=${identitasOpenkab}`;
settings.url += settings.url.indexOf('?') === -1 ? `?${params}` : `&${params}`;
}
});There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] 🐛 Bug: Undefined Injection ke URL AJAX Kode: Skenario:
Dampak:
Fix: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content') || '';
if (!identitasOpenkab) {
console.error('Meta tag identitas-openkab tidak ditemukan');
return; // atau throw error untuk mencegah request dengan data invalid
} |
||
| if (settings.url.indexOf('?') === -1) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] 📝 Code Quality: Hardcoded Configuration Kategori: JS Quality Masalah: Parameter names ( Kode: if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}Fix: // Definisikan config di top-level atau import dari config file
const AJAX_PARAMS_CONFIG = {
metaTagName: 'identitas-openkab',
paramNames: ['kode_kabupaten', 'filter[kode_kabupaten]']
};
$.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $(`meta[name="${AJAX_PARAMS_CONFIG.metaTagName}"]`).attr('content');
if (!identitasOpenkab) {
console.warn(`Meta tag ${AJAX_PARAMS_CONFIG.metaTagName} tidak ditemukan`);
return;
}
const params = AJAX_PARAMS_CONFIG.paramNames
.map(name => `${name}=${identitasOpenkab}`)
.join('&');
settings.url += settings.url.indexOf('?') === -1 ? `?${params}` : `&${params}`;
}
}); |
||
| settings.url += '?kode_kabupaten=' + identitasOpenkab+'&filter[kode_kabupaten]=' + identitasOpenkab; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] 🔒 Security: URL Parameter Injection via Unencoded Meta Tag Value Masalah: Nilai Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}Risiko:
PoC (Chrome Console): // Jalankan di Chrome DevTools Console (F12 → Console)
// Pastikan sudah login ke aplikasi di tab yang sama
// Step 1: Manipulasi meta tag untuk inject parameter berbahaya
$('meta[name="identitas-openkab"]').attr('content', '1234&admin=true&role=superadmin');
// Step 2: Trigger AJAX request (contoh ke endpoint apapun)
const testUrl = '/api/test-endpoint';
const resp = await fetch(testUrl, {
method: 'GET',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
// Step 3: Periksa URL yang sebenarnya dikirim
console.log('URL yang dikirim:', resp.url);
// Expected output: /api/test-endpoint?kode_kabupaten=1234&admin=true&role=superadmin&filter[kode_kabupaten]=1234&admin=true&role=superadmin
// Step 4: Verifikasi parameter diterima backend
const data = await resp.text();
console.log('Response:', data);
// Alternatif: Test dengan jQuery AJAX
$.get('/api/desa', function(data) {
console.log('jQuery AJAX berhasil dengan parameter terinjeksi');
});
// Periksa Network tab untuk melihat URL finalFix: $.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
// Validasi format kode kabupaten (hanya angka, 4-6 digit)
if (!identitasOpenkab || !/^\d{4,6}$/.test(identitasOpenkab)) {
console.error('Invalid kode_kabupaten format');
return; // Abort jika tidak valid
}
// Encode value sebelum ditambahkan ke URL
const encodedValue = encodeURIComponent(identitasOpenkab);
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + encodedValue + '&filter[kode_kabupaten]=' + encodedValue;
} else {
settings.url += '&kode_kabupaten=' + encodedValue + '&filter[kode_kabupaten]=' + encodedValue;
}
}
}); |
||
| } else { | ||
| settings.url += '&kode_kabupaten=' + identitasOpenkab+'&filter[kode_kabupaten]=' + identitasOpenkab; | ||
| } | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,17 @@ | |
| <script nonce="{{ csp_nonce() }}"> | ||
| var selectedMenuObj = null; | ||
|
|
||
| $.ajaxSetup({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] 📝 Code Quality: Code Duplication - DRY Violation Kategori: Architecture Masalah: Sama dengan temuan di Kode: $.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}
}
});Fix: |
||
| beforeSend: function(xhr, settings) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] 🐛 Bug: Undefined Injection ke URL AJAX (Duplikasi) Kode: Skenario:
Dampak:
Fix: $(function () {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content') || '';
if (!identitasOpenkab) {
console.error('Meta tag identitas-openkab tidak ditemukan di admin panel');
// Tampilkan alert ke user atau redirect ke error page
return;
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}
}
});
// ... rest of code
}); |
||
| const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] ⚡ Performance: jQuery Selector Tanpa Cache di AJAX beforeSend (Duplikasi) Masalah: Sama seperti Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');Dampak:
Fix: // Cache selector di luar ajaxSetup
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content') || '';
$.ajaxSetup({
beforeSend: function(xhr, settings) {
// Gunakan cached value
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}
}
});Rekomendasi Tambahan: Pertimbangkan untuk membuat satu file shared JavaScript untuk logic ini agar tidak duplikasi kode antara web.js dan javascript.blade.php. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [HIGH] 📝 Code Quality: Missing Null/Undefined Check Kategori: JS Quality Masalah: Sama dengan temuan di Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;Fix: $.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (!identitasOpenkab) {
console.warn('Meta tag identitas-openkab tidak ditemukan, AJAX request tanpa kode_kabupaten');
return;
}
const params = `kode_kabupaten=${identitasOpenkab}&filter[kode_kabupaten]=${identitasOpenkab}`;
settings.url += settings.url.indexOf('?') === -1 ? `?${params}` : `&${params}`;
}
}); |
||
| if (settings.url.indexOf('?') === -1) { | ||
| settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL] 🔒 Security: URL Parameter Injection via Unencoded Meta Tag Value (Duplicate) Masalah: Identik dengan isu di Kode: const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
} else {
settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab;
}Risiko:
PoC (Chrome Console): // Jalankan di Chrome DevTools Console (F12 → Console)
// Pastikan sudah login sebagai admin di panel /presisi
// Step 1: Manipulasi meta tag untuk inject parameter privilege escalation
$('meta[name="identitas-openkab"]').attr('content', '1234&bypass_auth=1&role_id=1');
// Step 2: Trigger AJAX request ke endpoint admin (contoh DataTables)
const adminEndpoint = '/presisi/api/users'; // Sesuaikan dengan endpoint yang ada
const resp = await fetch(adminEndpoint, {
method: 'GET',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'application/json'
}
});
// Step 3: Periksa URL yang sebenarnya dikirim
console.log('Admin URL yang dikirim:', resp.url);
// Expected: /presisi/api/users?kode_kabupaten=1234&bypass_auth=1&role_id=1&filter[kode_kabupaten]=1234&bypass_auth=1&role_id=1
// Step 4: Cek apakah parameter terinjeksi diterima backend
const data = await resp.json();
console.log('Admin Response:', data);
// Alternatif: Test dengan DataTables AJAX yang umum di AdminLTE
$('#example-table').DataTable().ajax.reload();
// Periksa Network tab untuk melihat parameter yang terinjeksiFix: $.ajaxSetup({
beforeSend: function(xhr, settings) {
const identitasOpenkab = $('meta[name="identitas-openkab"]').attr('content');
// Validasi format kode kabupaten (hanya angka, 4-6 digit)
if (!identitasOpenkab || !/^\d{4,6}$/.test(identitasOpenkab)) {
console.error('Invalid kode_kabupaten format');
return; // Abort jika tidak valid
}
// Encode value sebelum ditambahkan ke URL
const encodedValue = encodeURIComponent(identitasOpenkab);
if (settings.url.indexOf('?') === -1) {
settings.url += '?kode_kabupaten=' + encodedValue + '&filter[kode_kabupaten]=' + encodedValue;
} else {
settings.url += '&kode_kabupaten=' + encodedValue + '&filter[kode_kabupaten]=' + encodedValue;
}
}
});Rekomendasi Tambahan:
|
||
| } else { | ||
| settings.url += '&kode_kabupaten=' + identitasOpenkab + '&filter[kode_kabupaten]=' + identitasOpenkab; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| $('.item-menu').each(function(i, obj) { | ||
| if ($(obj).attr('href') === window.location.pathname) { | ||
| selectedMenuObj = obj; | ||
|
|
@@ -50,4 +61,4 @@ | |
| } | ||
| } | ||
| }); | ||
| </script> | ||
| </script> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGH] 📝 Code Quality: Code Duplication - DRY Violation
Kategori: Architecture
Masalah: Logic
$.ajaxSetup()untuk inject parameterkode_kabupatendiduplikasi persis di 2 tempat berbeda:resources/js/web.js(L10-19) - untuk public webresources/views/layouts/presisi/partials/javascript.blade.php(L30-39) - untuk admin panelDuplikasi ini melanggar prinsip DRY (Don't Repeat Yourself) dan menyulitkan maintenance. Jika ada bug atau perlu perubahan logic, harus diubah di 2 tempat.
Kode:
Fix:
Ekstrak ke shared utility module yang bisa digunakan di kedua context: