Raw Malicious Content Stored in Database Due to Missing Changeset Validation
Describe the bug
Stored malicious HTML/JS payloads (e.g. ) are accepted and saved in player/game names without any validation or sanitization.
Phoenix auto-escapes output so no XSS executes now, but raw dangerous content stays in the database.
Expected behavior
Player and game names should be validated/sanitized on save reject or strip HTML/JS tags and other unsafe characters.
Screenshot
Desktop (please complete the following information):
- OS: Windows / macOS / Linux
- Browser: Chrome / Firefox / Edge
- Version: Latest
Additional context
- No content validation in changesets (only length/required checks).
- Raw HTML/JS stored in DB → big risk if someone later uses raw() in templates, adds exports (CSV/JSON), emails, or admin views.
- Current Phoenix escaping protects against immediate XSS, but this is a future-proofing / data integrity issue.
@sydseter , if we expand in near future should we fix this?
I've investigated this issue. The root cause is that both Player.changeset/2 and Game.changeset/2 in the Ecto schemas only validate presence and length of the name field, but do not reject HTML/JS content like <script>alert('XSS')</script>.
Fix: Add validate_format/4 to both changesets to reject names containing < or > characters. This prevents raw HTML/JS from being stored in the database while keeping the validation minimal and consistent with the existing changeset pattern.
The regex ~r/\A[^<>]*\z/ ensures the entire name string contains no angle brackets. Names like <script>alert('xss')</script> or <img src=x onerror=alert(1)> will be rejected with a clear error message.
Opening a PR shortly.
Lets only allow characters based on this regexp:
"^[\u0600-\u06FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF\uFDF2\uFDF3\uFDF4\uFDFD\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uFF66-\uFF9Fー々〆〤\u3400-\u4DBF\uF900-\uFAFF\u0900-\u097F\u0621-\u064A\u0660-\u0669\u4E00-\u9FFF\u0E00-\u0E7F«»฿ฯ๏๚๛\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69FЮ́ю́Я́я́\u0370-\u03FF\u1F00-\u1FFFA-Za-zÀ-ÖØ-öø-ÿĀ-ž0-9._\--ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوي ًٌٍَُِّْٰﷲﷴﷺﷻ ٠١٢٣٤٥٦٧٨٩ \s]+$"
This issue is for newcomers, I'm un-assigning myself from #2555 and #2557 right now. Both are super beginner-friendly (small changeset fixes), so perfect for someone new to jump in and learn Ecto/Phoenix security/best practices.
I'll still be around to review/help if anyone picks them up, but won't claim them myself, if anyone needs help ping me up
@sydseter, can you assign this to me?
@Suresh-Krishna-P You are assigned.
The task here should be to implement input validation. I have supplied the regexp above.
There is no need to clean the content from the db.
Unasigning due to inactivity. Feel free to open a pull-request.
It still lacks name-format validation in both player.ex and game.ex
hii @sydseter, can i take this issue?
@Adarshkumar0509 Sure. Thank you for your time!
Update :- I just started working on this sorry for delay.