Files
opensourcepos/app/Language/vi/Attributes.php
jekkos bafe3ddf1b Fix stored XSS vulnerability in Attribute Definitions (GHSA-rvfg-ww4r-rwqf) (#4429)
* Fix stored XSS vulnerability in Attribute Definitions

GHSA-rvfg-ww4r-rwqf: Stored XSS via Attribute Definition Name

Security Impact:
- Authenticated users with attribute management permission can inject XSS payloads
- Payloads execute when viewing/editing attributes in admin panel
- Can steal session cookies, perform CSRF attacks, or compromise admin operations

Root Cause:
1. Input: Attributes.php postSaveDefinition() accepts definition_name without sanitization
2. Output: Views echo definition_name without proper escaping

Fix Applied:
- Input sanitization: Added FILTER_SANITIZE_FULL_SPECIAL_CHARS to definition_name and definition_unit
- Output escaping: Added esc() wrapper when displaying definition_name in views
- Defense-in-depth: htmlspecialchars on attribute values saved to database

Files Changed:
- app/Controllers/Attributes.php - Sanitize inputs on save
- app/Views/attributes/form.php - Escape output on display
- app/Views/attributes/item.php - Escape output on display

* Remove input sanitization, keep output escaping only

Use escaping on output (esc() in views) as the sole XSS prevention
measure instead of sanitizing on input. This preserves the original
data in the database while still protecting against XSS attacks.

* Add validation for definition_fk foreign key in attribute definitions

Validate definition_group input before saving:
- Must be a positive integer (> 0)
- Must exist in attribute_definitions table
- Must be of type GROUP to ensure data integrity

Also add translation for definition_invalid_group error message
in all 45 language files (English placeholder for translations).

* Refactor definition_fk validation into single conditional statement

* Add esc() to attribute value outputs for XSS protection

- Add esc() to TEXT input value in item.php
- Add esc() to definition_unit in form.php

These fields display user-provided content and need output escaping
to prevent stored XSS attacks.

* Refactor definition_group validation into separate method

Extract validation logic for definition_fk into validateDefinitionGroup()
private method to improve code readability and reduce method complexity.

Returns:
- null if input is empty (no group selected)
- false if validation fails (invalid group)
- integer ID if valid

* Add translations for definition_invalid_group in all languages

- Added proper translations for 28 languages (de, es, fr, it, nl, pl, pt-BR, ru, tr, uk, th, zh-Hans, zh-Hant, ro, sv, vi, id, el, he, fa, hu, da, sw-KE, sw-TZ, ar-LB, ar-EG)
- Set empty string for 14 languages to fallback to English (cs, hr-HR, bg, bs, ckb, hy, km, lo, ml, nb, ta, tl, ur, az)

---------

Co-authored-by: Ollama <ollama@steganos.dev>
2026-03-14 15:33:58 +00:00

35 lines
2.4 KiB
PHP

<?php
return [
"attribute_value_invalid_chars" => "Giá trị thuộc tính không thể chứa ':' hay '|'",
"confirm_delete" => "Bạn có chắc chắn muốn xóa (các) thuộc tính đã chọn không?",
"confirm_restore" => "Bạn có chắc chắn muốn khôi phục (các) thuộc tính đã chọn không?",
"definition_cannot_be_deleted" => "Không thể xóa (các) thuộc tính được chọn",
"definition_invalid_group" => "Nhóm đã chọn không tồn tại hoặc không hợp lệ.",
"definition_error_adding_updating" => "Thuộc tính {0} không thể thêm hoặc cập nhật. Vui lòng kiểm tra nhật ký lỗi.",
"definition_flags" => "Hiển thị thuộc tính",
"definition_group" => "Nhóm",
"definition_id" => "Mã số",
"definition_name" => "Thêm thuộc tính",
"definition_name_required" => "Tên thuộc tính là trường bắt buộc",
"definition_one_or_multiple" => "thuộc tính",
"definition_successful_adding" => "Bạn vừa mới thêm mục tin thành công",
"definition_successful_deleted" => "Bạn đã xóa thành công",
"definition_successful_updating" => "Bạn đã cập nhật thành công thuộc tính",
"definition_type" => "Loại thuộc tính",
"definition_type_required" => "Loại thuộc tính là trường bắt buộc",
"definition_unit" => "Đơn vị đo lường",
"definition_values" => "Giá trị thuộc tính",
"new" => "Thêm thuộc tính mới",
"no_attributes_to_display" => "Không có mặt hàng nào để hiển thị",
"receipt_visibility" => "Biên lai",
"show_in_items" => "Hiển thị trong các mặt hàng",
"show_in_items_visibility" => "Hàng hóa",
"show_in_receipt" => "Hiển thị trong biên lai",
"show_in_receivings" => "Hiển thị trong nhập hàng",
"show_in_receivings_visibility" => "Nhập hàng",
"show_in_sales" => "Hiển thị trong bán hàng",
"show_in_sales_visibility" => "Bán hàng",
"update" => "Cập nhật thuộc tính",
];