Repository navigation
Description
Problem
Submitting a tax name containing <script> (or other HTML-unsafe chars) on the Tax Codes, Tax Categories, or Tax Jurisdictions admin screens does not get rejected — it gets silently sanitized (HTML-encoded via FILTER_SANITIZE_FULL_SPECIAL_CHARS) and saved as <script> instead of surfacing a validation error to the user.
This is not currently exploitable as XSS — output paths (form_input()/form_hidden() in the admin forms, and esc() on the sales/receipt views that render tax_group) already escape the value again downstream. But it's a data-integrity/UX bug: invalid input is silently mangled and stored rather than being rejected like it should be.
Where
app/Controllers/Taxes.php:
postSave_tax_codes()— readstax_code_nameviaFILTER_SANITIZE_FULL_SPECIAL_CHARS, no validation.postSave_tax_categories()— readstax_categoryviaFILTER_SANITIZE_FULL_SPECIAL_CHARS, no validation.postSave_tax_jurisdictions()— readsjurisdiction_nameviaFILTER_SANITIZE_FULL_SPECIAL_CHARS, no validation.
Prior art
A near-identical bug was already fixed for the Items tax name field in app/Controllers/Items.php (see validateItemFields() / validateBulkUpdateFields()). That fix should be replicated here using the exact same pattern:
- Reuse the
unicode_alpha_numeric_punctvalidation rule already defined inapp/Config/Validation/OSPOSRules.php— it allows unicode letters/digits/standard punctuation but excludes</>, so it doubles as a defense-in-depth backstop against HTML injection while still accepting legitimate non-English text (accented/CJK characters). - Reuse the shared
Secure_Controller::validateFields(array $rules, array $messages, $id)helper (app/Controllers/Secure_Controller.php), which runs$this->validate()and returns a JSON error response ({success: false, message, id}) on failure, ornullon success — same asItems.phpdoes. - In each of the three
Taxes.phpsave methods, before building the save array, validate the posted name field (each is an array, one entry per row) with a rule like:and matching messages pointing at a'tax_code_name.*' => 'required|max_length[255]|unicode_alpha_numeric_punct'
tax_*_invalidlang key, then return early ifvalidateFields()returns non-null — exactly mirroringItems::validateItemFields(). - Lang keys:
app/Language/en/Taxes.phpalready has unused keys that fit this purpose —tax_code_invalid_chars,tax_category_invalid_chars,tax_jurisdiction_invalid_chars. Reuse these if their wording fits, or add new keys following theItems.tax_name_invalidnaming pattern, propagated to all locale files underapp/Language/*/Taxes.php. - Keep the existing
FILTER_SANITIZE_FULL_SPECIAL_CHARSread as defense-in-depth for whatever passes validation — validation should just run first and short-circuit invalid input, not replace the sanitize filter.
Acceptance criteria
- Submitting
<script>(or any string containing</>) in Tax Code Name, Tax Category Name, or Jurisdiction Name is rejected with a validation error, not silently saved. - Legitimate accented/CJK/punctuated names still save successfully.
- Regression tests added mirroring the pattern used for the Items fix.
Activity
fix(taxes): permit slash and CJK in tax names, add regression tests
fix(taxes): reject invalid characters in tax code, category, and juri…
fix(taxes): reject invalid characters in tax code, category, and juri…
fix(taxes): reject invalid characters in tax code, category, and juri…