PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | modules/subscriptions/jetpack-user-content-link-redirection.php +31 -9 12.9.5 → 16.3-a.7 View file →
@@ -8,29 +8,52 @@
8 8 *
9 9 * @package automattic/jetpack
10 10 */
11 11
12 +use Automattic\Jetpack\Connection\Manager as Connection_Manager;
13 +
12 14 /**
13 - * Render a page containing an iframe to track and redirect the user content link in emails.
15 + * Render a page with an iframe to track and redirect user content links in emails.
16 + *
17 + * Hooked to the `init` action, this function renders a page with an iframe pointing to
18 + * subscribe.wordpress.com to track and return the destination URL for redirection.
19 + *
20 + * Redirects to the site's home page if required parameters are missing.
21 + * Returns a 400 error if the request's `blog_id` doesn't match the actual `blog_id`.
22 + *
23 + * @return never
14 24 */
15 25 function jetpack_user_content_link_redirection() {
16 - if ( empty( $_SERVER['QUERY_STRING'] ) ) {
17 - return;
26 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
27 + if ( empty( $_SERVER['QUERY_STRING'] ) || empty( $_SERVER['HTTP_HOST'] ) || empty( $_GET['blog_id'] ) ) {
28 + wp_safe_redirect( get_home_url() );
29 + exit( 0 );
18 30 }
31 +
32 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
33 + $request_blog_id = intval( sanitize_text_field( wp_unslash( $_GET['blog_id'] ) ) );
34 + $actual_blog_id = Connection_Manager::get_site_id( true );
35 +
36 + if ( $actual_blog_id !== $request_blog_id ) {
37 + wp_die( esc_html__( 'Invalid link.', 'jetpack' ), 400 );
38 + exit( 0 );
39 + }
40 +
19 41 $query_params = sanitize_text_field( wp_unslash( $_SERVER['QUERY_STRING'] ) );
20 42 $iframe_url = "https://subscribe.wordpress.com/?$query_params";
21 43
22 - // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
23 - echo <<<EOF
44 + echo <<<'EOF'
24 45 <!DOCTYPE html>
25 46 <html>
26 47 <head>
27 48 <script>
49 + let messageReceived = false;
28 50 window.addEventListener( 'message', function(event) {
29 - if ( event.origin !== 'https://subscribe.wordpress.com' ) {
51 + if ( event.origin !== 'https://subscribe.wordpress.com' || messageReceived ) {
30 52 return;
31 53 }
32 54 if ( event.data.redirectUrl ) {
55 + messageReceived = true;
33 56 window.location.href = event.data.redirectUrl;
34 57 }
35 58 } );
36 59 </script>
@@ -37,14 +60,13 @@
37 60 </head>
38 61 <body>
39 62 EOF;
40 63 echo '<iframe id="user-content-link-redirection" hidden aria-hidden="true" tabindex="-1" width="0" height="0" style="display: none" src="' . esc_url( $iframe_url ) . '"></iframe>';
41 - echo <<<EOF
64 + echo <<<'EOF'
42 65 </body>
43 66 </html>
44 67 EOF;
45 - // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
46 - exit;
68 + exit( 0 );
47 69 }
48 70
49 71 // The WPCOM_USER_CONTENT_LINK_REDIRECTION flag prevents this redirection logic from running
50 72 // on Atomic in case we'd like to override the redirection logic on the Atomic end.