Jadikan Content Security Policy (CSP) Selalu Aktif, Tidak Boleh Auto-Disable Walau di Debug/Dev#977
Open
pandigresik wants to merge 1 commit intorilis-devfrom
Open
Jadikan Content Security Policy (CSP) Selalu Aktif, Tidak Boleh Auto-Disable Walau di Debug/Dev#977pandigresik wants to merge 1 commit intorilis-devfrom
pandigresik wants to merge 1 commit intorilis-devfrom
Conversation
…Disable Walau di Debug/Dev
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 #968
CSP Improvement Summary
Overview
Perbaikan Content Security Policy (CSP) agar tetap aktif dengan policy yang strict di semua mode environment, tanpa membedakan status
APP_DEBUG. Sebelumnya, CSP otomatis dimatikan di development/staging environment, yang membuka risiko keamanan dan membiasakan developer bekerja tanpa protection.Masalah Sebelumnya
Kondisi Awal
Dampak Negatif
Solusi yang Diterapkan
Pendekatan Baru
CSP tetap aktif dan strict di semua mode, tanpa membedakan
APP_DEBUG:Keuntungan:
Detail Perubahan File
1.
app/Policies/CustomCSPPolicy.phpPerubahan #1: Method
shouldBeApplied()- Hapus Logic Disable CSP Berdasarkan DebugLokasi: Baris 66-78
Sebelum:
Sesudah:
Alasan:
APP_DEBUGPerubahan #2: Null Safety untuk Route
Lokasi: Baris 22
Sebelum:
Sesudah:
Alasan:
Call to a member function getName() on null2.
tests/Feature/CspPolicyTest.php(File Baru)File baru untuk menguji behavior CSP di berbagai kondisi.
Konten:
Test Coverage:
Menjalankan Test:
php artisan test --filter CspPolicyTestCSP Header Behavior
Semua Mode (Production & Development)
Catatan: Policy SAMA untuk production dan development. Tidak ada
unsafe-inlinedi mode manapun.Migration Guide
Untuk Developer
Tidak ada action yang diperlukan. Perubahan ini backward compatible untuk code yang sudah menggunakan
csp_nonce().Untuk Environment Variable
Pastikan file
.envAnda memiliki konfigurasi berikut:Untuk Custom Routes
Jika ada route baru yang memerlukan CSP dimatikan, tambahkan ke exclude list:
Untuk Inline Script Baru
Jika Anda perlu menambahkan inline script, gunakan nonce:
Testing Checklist
Manual Testing
Semua Mode (Debug True/False)
Expected: CSP header ada, tanpa
unsafe-inline(strict mode)Excluded Route
Expected: Tidak ada CSP header
Inline Script dengan Nonce
Expected: Script menggunakan
nonceattributeAutomated Testing
Security Considerations
✅ Good Practices
Troubleshooting
Inline Script Diblokir di Development
Error di console:
Solusi:
Tambahkan
nonceattribute:Atau pindahkan script ke file eksternal dan load dengan
<script src="...">Script Eksternal Diblokir
Solusi: Tambahkan domain ke policy di
configure()method:References
Changelog
Version: 2026-03-09
Changed:
APP_DEBUGRoute::getCurrentRoute()Added:
tests/Feature/CspPolicyTest.phpSecurity:
unsafe-inlinedi mode manapun