Security: XSS hardening across high-risk output surfaces #697
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.
Summary
This PR strengthens XSS protections across OpenCATS by making output escaping more consistent and safer in both legacy templates and dynamic UI output, especially where user-controlled or database-controlled content can reach HTML or JavaScript contexts.
It improves the core template escape helper (
Template::_) (UTF-8,ENT_QUOTES, safer handling of null/arrays/non-stringable objects) and replaces a few directechooutputs in error/questionnaire templates with the escaping helper to prevent raw HTML injection.It also hardens additional high-risk areas: search result previews are now escaped while still highlighting matched keywords, several Career Portal placeholders and URLs are escaped/sanitized before insertion into HTML, JavaScript string injections are replaced with
json_encode(...)for safe embedding, and Job Orderdescription/notesare sanitized through a strict HTML allowlist (dropping script-like tags, unsafe attributes, and unsafe link protocols).Finally, it adds a small PHPUnit unit test to validate that
Template::_reliably escapes common script payloads and common entity-bypass patterns.I did not add or adjust Behat scenarios here, so some end-to-end coverage might still be missing.
Motivation
OpenCATS contains multiple rendering paths where content originating from users, imported resumes, database text fields, or configuration values can be inserted into HTML/JS without guaranteed context-appropriate escaping, which increases the risk of stored or reflected XSS (including in internal pages and the Careers Portal).
By centralizing and strengthening escaping behavior, sanitizing rich-text fields with a conservative allowlist, and ensuring JS/URL contexts are handled safely, this PR reduces the likelihood that a single unsafe field or template placeholder can become an executable payload while keeping the changes minimal and aligned with existing rendering patterns.