Skip to content

Treat brackets in listing URL fields as text however they are written - #3186

Merged
tellyworth merged 1 commit into
trunkfrom
fix/listing-url-fields
Nov 16, 2026
Merged

tellyworth merged 1 commit into
trunkfrom
fix/listing-url-fields

Conversation

@tellyworth

@tellyworth tellyworth commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Changes Proposed in this Pull Request

Follows on from #3181, for listings whose author can't edit job listings.

  • Brackets in the company website, the X link and the application URL are percent-encoded, wherever they are in the URL and however they were written (as characters, or as character references of any form). New WP_Job_Manager_Post_Types::encode_brackets_in_url() and wpjm_esc_listing_url(). A URL with no bracket in any form is returned exactly as it was.
  • The X link is no longer encoded with character references before it is printed through the HTML filter.
  • Text fields that hold markup (imported, or saved by an older version) get the brackets inside their tags percent-encoded, as the description does. encode_brackets_in_tags() is now public for this.
  • The field sweep test now tries 14 ways of writing the same text in every field of the submission form, both sanitized as the form does and saved directly. It only tried one before.

Testing Instructions

  • vendor/bin/phpunit --filter 'Tests_Listing_Field_Sweep|Tests_Listing_Field_Display'
  • On a listing submitted from the frontend, the company website, X link and application link still work for ordinary URLs, including ones with & in the query string.

Release Notes

  • Fix: Hardening for the company website, X and application links of submitted listings.

Plugin build for 594bf2e
📦 Download plugin zip
▶️ Open in playground

Percent-encode brackets in the company website, X link and application URL of listings whose content is not trusted,
including brackets in the host part and those written as character references. Percent-encode brackets inside tags in
text fields that hold markup. Check every field against more ways of writing the same text.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
}

// Still changing: nothing meant as a URL is encoded this many times over.
if ( 5 === $pass ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why 5?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was a bare number; it is now the URL_DECODING_PASSES constant with the reasoning in the docblock. A limit is needed because each pass costs the length of the value, so a long value encoded many levels deep would otherwise take quadratic time. A real URL is encoded once, or twice when it was saved already escaped, so five leaves room. Tests now pin both sides of the limit (four levels kept, five not).

$next = preg_replace_callback(
'/&(?:#[0-9]+|#x[0-9a-f]+|[a-z][a-z0-9]*);?/i',
function ( $reference ) {
$complete = rtrim( $reference[0], ';' ) . ';';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

rtrim() will trim multiple characters, is that intended behaviour?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could only ever remove one, since the pattern matches at most one semicolon, but that wasn't obvious from reading it. Replaced with a capture group: the reference is rebuilt as '&' . $reference[1] . ';', with a test for a reference followed by several semicolons.


public function data_urls_with_brackets() {
return [
'host' => [ 'http://[' . self::SHORTCODE . ']/', 'http://%5B' . self::SHORTCODE . '%5D/' ],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is a single test for brackets in the hostname sufficient?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The sweep in test_class.listing-field-sweep.php covers more host forms end to end, but the unit tests here were thin. Added: host with port, after user info, with an attribute, without a trailing slash, without a scheme, upper-case scheme, written as references, a single bracket, and an IPv6 address literal. The last one records a side effect: an IPv6 literal in one of these fields on a submitted listing is encoded too, so that link won't work. Listings by users who can edit job listings are unaffected.

@tellyworth tellyworth added this to the 2.4.12 milestone Nov 16, 2026
@tellyworth
tellyworth merged commit b9a3eeb into trunk Nov 16, 2026
9 checks passed
@tellyworth
tellyworth deleted the fix/listing-url-fields branch November 16, 2026 05:06
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