Skip to content

Security: Fix Stored XSS vulnerability in PageRequest#117

Merged
juzaweb merged 2 commits into
masterfrom
fix-page-request-xss-6987435458252747160
Mar 19, 2026
Merged

Security: Fix Stored XSS vulnerability in PageRequest#117
juzaweb merged 2 commits into
masterfrom
fix-page-request-xss-6987435458252747160

Conversation

@juzaweb

@juzaweb juzaweb commented Mar 19, 2026

Copy link
Copy Markdown
Owner

This pull request addresses a Stored Cross-Site Scripting (XSS) vulnerability in the PageRequest.php form request class. Previously, malicious HTML and JavaScript payloads could be submitted via the title and content fields and stored raw in the database, potentially executing when the page is rendered on the frontend.

Changes:

  1. Added the prepareForValidation lifecycle hook to PageRequest.php to sanitize the incoming request data before it is validated and inserted into the database.
  2. The title field is sanitized by first using a regular expression to strip <script> tags (and their contents) and then applying strip_tags() to remove any remaining HTML tags.
  3. The content field is thoroughly sanitized using HTMLPurifier. The configuration explicitly forbids <script> elements and disables the definition cache (Cache.DefinitionImpl set to null) to prevent caching/permission issues, ensuring safe HTML content is stored.
  4. Added a corresponding unit test (PageRequestTest.php) to explicitly verify that the sanitization logic correctly removes dangerous payloads from both the title and content fields.

PR created automatically by Jules for task 6987435458252747160 started by @juzaweb

- Add `prepareForValidation` method to `PageRequest.php` to sanitize input data before validation.
- Use `strip_tags` and regex to remove `<script>` tags and clean the `title` field.
- Use `HTMLPurifier` with forbidden `script` elements and no caching to sanitize the `content` field.
- Add unit test `PageRequestTest` to verify the sanitization logic.

Co-authored-by: juzaweb <47020363+juzaweb@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Added a `clean_html` helper function in `helpers/helpers.php` to encapsulate HTMLPurifier logic with `script` tags explicitly forbidden and cache disabled.
- Refactored `PageRequest::prepareForValidation()` to use the new `clean_html()` helper for sanitizing the `content` field.
- Addressed code style issues to satisfy `pint` CI checks.

Co-authored-by: juzaweb <47020363+juzaweb@users.noreply.github.com>
@juzaweb juzaweb merged commit 3d0e29b into master Mar 19, 2026
0 of 8 checks passed
@juzaweb juzaweb deleted the fix-page-request-xss-6987435458252747160 branch March 19, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant