[SECURITY] Prevent IDOR (Insecure Direct Object Reference) pada Endpoint Berbasis ID#978
Open
pandigresik wants to merge 2 commits intorilis-devfrom
Open
[SECURITY] Prevent IDOR (Insecure Direct Object Reference) pada Endpoint Berbasis ID#978pandigresik wants to merge 2 commits intorilis-devfrom
pandigresik wants to merge 2 commits intorilis-devfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Perbaikan issue #966
IDOR Prevention & Authorization Improvement Summary
Overview
Perbaikan keamanan untuk mencegah IDOR (Insecure Direct Object Reference) vulnerability, di mana user dapat mengakses, memodifikasi, atau menghapus data user lain hanya dengan menebak atau enumerasi ID.
Masalah Sebelumnya
Kondisi Awal
Aplikasi tidak memiliki object-level authorization. Controller hanya mengandalkan permission-based middleware tanpa memverifikasi apakah user yang login berhak mengakses resource dengan ID tertentu.
Contoh Kerentanan
Dampak Keamanan
Solusi yang Diterapkan
1. Laravel Policy Implementation
Menggunakan Laravel Policy untuk object-level authorization:
2. Authorization Check di Controller
Menambahkan
$this->authorize()di setiap method yang mengakses resource by ID:File yang Dibuat/Dimodifikasi
1. Policy Classes (Baru)
app/Policies/UserPolicy.phpAuthorization untuk User model:
viewAny()- Lihat daftar userview()- Lihat detail usercreate()- Buat user baruupdate()- Update userdelete()- Hapus userstatus()- Ubah status userRules:
app/Policies/TeamPolicy.phpAuthorization untuk Team/Group model:
Rules:
app/Policies/ArticlePolicy.phpAuthorization untuk Article model:
Rules:
website-article-readwebsite-article-editwebsite-article-deletewebsite-article-create2. Controller Updates
app/Http/Controllers/UserController.phpapp/Http/Controllers/GroupController.phpapp/Http/Controllers/CMS/ArticleController.php3. AuthServiceProvider Update
app/Providers/AuthServiceProvider.php4. Test Coverage (Baru)
tests/Feature/IdorPreventionTest.php7 test cases untuk IDOR prevention:
Test Results:
Authorization Flow
Testing Checklist
Manual Testing
IDOR Test - Different Kabupaten
Expected: 403 Forbidden
IDOR Test - Same Kabupaten
Expected: 200 OK
IDOR Test - Admin Access
Expected: 200 OK
IDOR Test - Self Access
Expected: 200 OK
Automated Testing
Security Considerations
✅ Good Practices Implemented
Controller Coverage: Masih ada controller lain yang perlu authorization
SuplemenControllerPointControllerBantuanControllerPendudukControllerKeluargaControllerAPI Endpoints: API v1 juga perlu authorization check
Eager Loading: Pastikan relasi juga di-check (misal: user.team)
Migration Guide
Untuk Developer
Jika membuat controller baru:
Jika membuat policy baru:
Daftarkan di
AuthServiceProvider:Next Steps (Recommended)
Priority 1 - Critical Resources
PendudukController- Data penduduk sangat sensitifKeluargaController- Data keluargaBantuanController- Data bantuan sosialSuplemenController- Data suplemenPriority 2 - API Endpoints
Api/PermisionControllerApi/TeamControllerApi/IdentitasControllerPriority 3 - CMS Resources
CMS/CategoryControllerCMS/PageControllerCMS/SlideControllerCMS/DownloadControllerReferences
Changelog
Version: 2026-03-09
Added:
UserPolicy- Authorization untuk User modelTeamPolicy- Authorization untuk Team modelArticlePolicy- Authorization untuk Article modelIdorPreventionTest- Test coverage untuk IDOR preventionChanged:
UserController- Authorization check di edit, profile, update, destroy, statusGroupController- Authorization check di editArticleController- Authorization check di show, edit, update, destroyAuthServiceProvider- Registered policiesSecurity: