Skip to content

Encode user information attribute in user selector - #177

Merged
sorinmarta merged 1 commit into
masterfrom
fix-3211
Nov 17, 2026
Merged

sorinmarta merged 1 commit into
masterfrom
fix-3211

Conversation

@sorinmarta

Copy link
Copy Markdown
Contributor

Fixes Strategy11/awpcp#3211
Encode the user information JSON on the user selector options so profile values with quotes or entities are output and parsed correctly.

@sorinmarta sorinmarta added run analysis Run the phpcs run tests Run the unit tests franky-review labels Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The full-user-information option now applies JSON hex encoding flags and esc_attr() to the JSON value in data-user-information. The attribute uses double quotes.

Changes

User selector output

Layer / File(s) Summary
Encode full user information for the attribute
templates/components/user-selector.tpl.php
The option applies JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_QUOT, and JSON_HEX_AMP to the JSON value, then passes it through esc_attr(). The attribute uses double quotes.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix

Suggested reviewers: wvega

Merge Risk: Minimal · up to bc65f

The user selector now outputs profile data containing quotes or entities correctly in its data attribute. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the user information attribute in the user selector is now encoded. The raw summary confirms the data-user-information attribute now uses encoded JSON escaped with esc…
Description check Passed The description states the change is encoding the user information JSON on user selector options so values with quotes or entities are output and parsed correctly. It references the linked issue Strat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the user information attribute in the user selector is now encoded. The raw summary confirms the data-user-information attribute now uses encoded JSON escaped with esc_attr(), which matches the title.

Full details: Description check

Explanation

The description states the change is encoding the user information JSON on user selector options so values with quotes or entities are output and parsed correctly. It references the linked issue Strategy11/awpcp#3211. This matches the summary, which describes JSON encoding with JSON_HEX flags and esc_attr() for the data-user-information attribute.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

PHPStan (2.3.3)

PHPStan was skipped because the config uses disallowed bootstrapFiles or bootstrapFile directives.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4e9fee65-d0e0-482b-98d6-c5f41ef0aafd
Commits

Reviewing files that changed from the base of the PR and between 0072caf and bc65f97.

Files selected for processing: 1

  • templates/components/user-selector.tpl.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 17, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with 1 non-blocking note. The one-line change fixes the single-quote breakout in data-user-information and I found no way around it.

What the change does: the old markup put wp_json_encode( $user ) inside a single-quoted attribute, and wp_json_encode does not escape '. The new markup uses a double-quoted attribute, esc_attr(), and the JSON_HEX_* flags, so quotes, <, > and & leave the JSON as \uXXXX escapes. $user->ID, the selected check and the option text are untouched. php -l is clean. The consumers ($user.data( 'user-information' ) in order-section-controller.js and edit-post.js, and JSON.parse( attr(...) ) in users-dropdown.js) read the attribute value after the browser has decoded it, so they get the same JSON as before. The sibling html-widget-users-dropdown.tpl.php already used esc_attr( wp_json_encode( $user ) ) in double quotes, so the two templates now agree.

Live before/after: I built both versions of the option tag for a user whose display_name is x' onmouseover='alert(1)' data-x=' and whose email contains ", <script> and &amp;, then parsed the HTML with Python's HTML parser and decoded the attribute as JSON. Old: the parser sees extra onmouseover and data-x attributes on the option, and the JSON fails to parse (unterminated string). New: only value and data-user-information exist, and the JSON parses back to the exact original display name and email. Limits: this used a 3-line PHP stand-in for esc_attr (htmlspecialchars with ENT_QUOTES, no double-encode, which is what WordPress does) and plain json_encode, not a booted WordPress, and no browser. I did not see the Patchstack report (the awpcp issue only links it), so I can only say this closes the single-quote breakout, not that it covers everything the report describes.

CI at this head: PHPUnit (PHP 7.4 and 8) and PHPCS passed.

Non-blocking: the PR adds no test, and this is a security fix. tests/suite has a test for the sibling users-dropdown widget but none for components/user-selector.tpl.php. A test that renders the template with a user whose display_name is x' onmouseover='alert(1)' and asserts the output has no raw ' or < inside the attribute would keep this from regressing.

Not run: browser, the plugin's own PHPUnit suite locally (CI ran it), code-review / security-review / simplify skills (I read the whole one-line diff).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 17, 2026
@sorinmarta
sorinmarta merged commit dc40617 into master Nov 17, 2026
12 of 16 checks passed
@sorinmarta
sorinmarta deleted the fix-3211 branch November 17, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Run the phpcs run tests Run the unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant