Skip to content

Tax Codes/Categories/Jurisdictions names accept HTML-unsafe chars (sanitize instead of reject) #4679

Closed

Description

@objecttothis

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 &lt;script&gt; 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() — reads tax_code_name via FILTER_SANITIZE_FULL_SPECIAL_CHARS, no validation.
  • postSave_tax_categories() — reads tax_category via FILTER_SANITIZE_FULL_SPECIAL_CHARS, no validation.
  • postSave_tax_jurisdictions() — reads jurisdiction_name via FILTER_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:

  1. Reuse the unicode_alpha_numeric_punct validation rule already defined in app/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).
  2. 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, or null on success — same as Items.php does.
  3. In each of the three Taxes.php save methods, before building the save array, validate the posted name field (each is an array, one entry per row) with a rule like:
    'tax_code_name.*' => 'required|max_length[255]|unicode_alpha_numeric_punct'
    and matching messages pointing at a tax_*_invalid lang key, then return early if validateFields() returns non-null — exactly mirroring Items::validateItemFields().
  4. Lang keys: app/Language/en/Taxes.php already 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 the Items.tax_name_invalid naming pattern, propagated to all locale files under app/Language/*/Taxes.php.
  5. Keep the existing FILTER_SANITIZE_FULL_SPECIAL_CHARS read 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions