Repository navigation
Treat brackets in listing URL fields as text however they are written - #3186
Conversation
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 ) { |
There was a problem hiding this comment.
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], ';' ) . ';'; |
There was a problem hiding this comment.
rtrim() will trim multiple characters, is that intended behaviour?
There was a problem hiding this comment.
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/' ], |
There was a problem hiding this comment.
Is a single test for brackets in the hostname sufficient?
There was a problem hiding this comment.
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.
Changes Proposed in this Pull Request
Follows on from #3181, for listings whose author can't edit job listings.
WP_Job_Manager_Post_Types::encode_brackets_in_url()andwpjm_esc_listing_url(). A URL with no bracket in any form is returned exactly as it was.encode_brackets_in_tags()is now public for this.Testing Instructions
vendor/bin/phpunit --filter 'Tests_Listing_Field_Sweep|Tests_Listing_Field_Display'&in the query string.Release Notes