Repository navigation
Fix: Reflected XSS di halaman kategori potensi - #1784
Open
pandigresik wants to merge 1 commit into
Open
pandigresik wants to merge 1 commit into
pandigresik wants to merge 1 commit into
Conversation
Contributor
|
🔄 AI PR Review sedang antri di server...
|
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.
Pull Request: Fix: Reflected XSS di halaman kategori potensi
Description
Halaman publik kategori potensi (
GET /potensi/{slug}) menulis parameterslugdari URL langsung ke dalam blok<script>tanpa escape. Karakter kutip tunggal pada slug menutup string JavaScript dan menjalankan skrip di origin situs. PR ini memasukkanslugke JavaScript dengan@jsondan mengkodekan nilainya denganencodeURIComponentsaat dipakai di URL API.Changes made:
themes/opendk/default/resources/views/pages/potensi/index.blade.phpmenyimpan slug sebagaivar slug = @json($slug ?? '');, menggantikan{!! $slug ?? '' !!}di dalam string JavaScript.encodeURIComponent(slug)sehingga karakter seperti&,#,?, dan=tidak mengubah query string.tests/Feature/Frontend/PotensiPublicTest.phpmenambahkan test regresiescapes the category slug rendered inside the potensi page scriptyang mengirim payloadx'-alert(1)-'dan memastikan payload mentah tidak muncul di halaman.beforeEachpada file yang sama kini membuat atau memperbaruiNavMenubernamaPotensidengan URL/potensi. Dua test navigasi sebelumnya bergantung pada data seeder (#) yang tidak dikendalikan test.Reason for change:
@jsonmemakaiJSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, sehingga<,>,&,', dan"tidak bisa keluar dari string JavaScript.nama_kategorioleh traitSluggable, danTipePotensiRequesthanya memvalidasinama_kategori.Impact of change:
✅ Keamanan: Payload pada slug tidak lagi bisa menjalankan skrip di halaman publik.
✅ Admin tidak terdampak: Perubahan hanya di halaman publik dan tidak mengubah cara kategori dibuat.
✅ Test lebih stabil: Dua test navigasi tidak lagi bergantung pada nilai seeder yang berbeda antar database.
Related Issue
#1781
Closes #1781
Steps to Reproduce
Before fix (problem):
/potensi/x'-alert(1)-'(URL-encoded:/potensi/x%27-alert%281%29-%27)<script>memuatfilter[tipe.slug]=x'-alert(1)-'alert(1)dieksekusi di origin situsAfter fix (solution):
/potensi/x'-alert(1)-'var slug = "x'-alert(1)-'";encodeURIComponent(slug)di query stringTesting on related features:
/potensi(semua kategori) ✅ testdisplays all potensi pagelulus/potensi/{slug}dengan slug valid ✅ testdisplays potensi by category pagelulus/potensi/{kategori}/{id}✅ testdisplays potensi detail pagelulus/api/frontend/v1/website✅ dua test navigasi lulus setelah setup data dibeforeEachChecklist
Technical Details
Technical Explanation
Sebelum perubahan:
Sesudah perubahan:
Pemeriksaan yang sudah dilakukan:
json_encodedengan flag HEX menghasilkan&,<,', dan"untuk karakter berbahaya.@jsondi Laravel memakai encoding options defaultJSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT.Configuration changes
Tidak ada perubahan konfigurasi.
Dependencies added
No new dependencies
Testing
Manual Testing
/potensi/x'-alert(1)-'dan pastikan tidak ada dialog alert/potensi/{slug}untuk kategori yang ada dan pastikan daftar potensi tampil/potensi, kategori, dan detail lulusAutomated Testing
escapes the category slug rendered inside the potensi page script(regresi, sebelumnya gagal)displays all potensi page at /potensi successfullydisplays potensi by category page at /potensi/{slug} successfullydisplays potensi detail page at /potensi/{kategori}/{id} successfullyensures nav_menus table contains /potensi for Potensi menureturns /potensi in the website api navmenus dataHasil:
tests/Feature/Frontend/PotensiPublicTest.php6/6 lulus (dijalankan 4 kali berturut-turut).Screenshots / Video
simplescreenrecorder-2026-10-28_06.23.14.mp4
Breaking Changes
None
Migration Guide
Not required
References
@jsonAdditional notes:
87c87f5c("perbaikan xss") sudah berisi perubahan ini di branchfix/xss_reflected..env.testingdan.phpunit.cache/test-resultsdi working tree tidak termasuk dalam PR ini.🤖 Generated with Claude Code