Skip to content

Commit 9d04cdc

Browse files
committed
Completely remove the reject_url handling. If a user rejects a request, it should not send any data to the requesting site or app.
1 parent f569501 commit 9d04cdc

4 files changed

Lines changed: 21 additions & 70 deletions

File tree

src/js/_enqueues/admin/auth-app.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
$form = $appNameField.closest( 'form' ),
1212
context = {
1313
userLogin: authApp.user_login,
14-
successUrl: authApp.success,
15-
rejectUrl: authApp.reject
14+
successUrl: authApp.success
1615
};
1716

1817
// If redirecting to an external site, gate the approve button behind the confirmation checkbox.
@@ -61,12 +60,12 @@
6160
* Filters the request data used to Authorize an Application Password request.
6261
*
6362
* @since 5.6.0
63+
* @since x.y.z A reject URL is no longer supported or used.
6464
*
6565
* @param {Object} request The request data.
6666
* @param {Object} context Context about the Application Password request.
6767
* @param {string} context.userLogin The user's login username.
6868
* @param {string} context.successUrl The URL the user will be redirected to after approving the request.
69-
* @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request.
7069
*/
7170
request = wp.hooks.applyFilters( 'wp_application_passwords_approve_app_request', request, context );
7271

@@ -187,16 +186,22 @@
187186
* Fires when an Authorize Application Password request has been rejected by the user.
188187
*
189188
* @since 5.6.0
189+
* @since x.y.z A reject URL is no longer supported or used.
190190
*
191191
* @param {Object} context Context about the Application Password request.
192192
* @param {string} context.userLogin The user's login username.
193193
* @param {string} context.successUrl The URL the user will be redirected to after approving the request.
194-
* @param {string} context.rejectUrl The URL the user will be redirected to after rejecting the request.
195194
*/
196195
wp.hooks.doAction( 'wp_application_passwords_reject_app', context );
197196

198-
// @todo: Make a better way to do this so it feels like less of a semi-open redirect.
199-
window.location = authApp.reject;
197+
var $notice = $( '<div></div>' )
198+
.attr( 'role', 'alert' )
199+
.attr( 'tabindex', -1 )
200+
.addClass( 'notice notice-info' )
201+
.append( $( '<p></p>' ).text( wp.i18n.__( 'You have not approved this connection. No data has been shared with the application.' ) ) );
202+
203+
$form.replaceWith( $notice );
204+
$notice.trigger( 'focus' );
200205
} );
201206

202207
$form.on( 'submit', function( e ) {

src/wp-admin/authorize-application.php

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@
1717
check_admin_referer( 'authorize_application_password' );
1818

1919
$success_url = $_POST['success_url'];
20-
$reject_url = $_POST['reject_url'];
2120
$app_name = $_POST['app_name'];
2221
$app_id = $_POST['app_id'];
2322
$redirect = '';
2423

2524
if ( isset( $_POST['reject'] ) ) {
26-
if ( $reject_url ) {
27-
$redirect = $reject_url;
28-
} else {
29-
$redirect = admin_url();
30-
}
25+
$redirect = admin_url();
3126
} elseif ( isset( $_POST['approve'] ) ) {
3227
$created = WP_Application_Passwords::create_new_application_password(
3328
get_current_user_id(),
@@ -69,17 +64,9 @@
6964
$app_id = ! empty( $_REQUEST['app_id'] ) ? $_REQUEST['app_id'] : '';
7065
$success_url = ! empty( $_REQUEST['success_url'] ) ? $_REQUEST['success_url'] : null;
7166

72-
if ( ! empty( $_REQUEST['reject_url'] ) ) {
73-
$reject_url = $_REQUEST['reject_url'];
74-
} elseif ( $success_url ) {
75-
$reject_url = add_query_arg( 'success', 'false', $success_url );
76-
} else {
77-
$reject_url = null;
78-
}
79-
8067
$user = wp_get_current_user();
8168

82-
$request = compact( 'app_name', 'app_id', 'success_url', 'reject_url' );
69+
$request = compact( 'app_name', 'app_id', 'success_url' );
8370
$is_valid = wp_is_authorize_application_password_request_valid( $request, $user );
8471

8572
if ( is_wp_error( $is_valid ) ) {
@@ -96,7 +83,7 @@
9683
array(
9784
'response' => 501,
9885
'link_text' => __( 'Go Back' ),
99-
'link_url' => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(),
86+
'link_url' => admin_url(),
10087
)
10188
);
10289
}
@@ -114,7 +101,7 @@
114101
array(
115102
'response' => 501,
116103
'link_text' => __( 'Go Back' ),
117-
'link_url' => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(),
104+
'link_url' => admin_url(),
118105
)
119106
);
120107
}
@@ -131,10 +118,9 @@
131118
'auth-app',
132119
'authApp',
133120
array(
134-
'site_url' => site_url(),
135-
'user_login' => $user->user_login,
136-
'success' => $success_url,
137-
'reject' => $reject_url ? $reject_url : admin_url(),
121+
'site_url' => site_url(),
122+
'user_login' => $user->user_login,
123+
'success' => $success_url,
138124
'successHost' => $success_host,
139125
)
140126
);
@@ -203,7 +189,6 @@
203189
<input type="hidden" name="action" value="authorize_application_password" />
204190
<input type="hidden" name="app_id" value="<?php echo esc_attr( $app_id ); ?>" />
205191
<input type="hidden" name="success_url" value="<?php echo esc_url( $success_url ); ?>" />
206-
<input type="hidden" name="reject_url" value="<?php echo esc_url( $reject_url ); ?>" />
207192

208193
<?php if ( $app_name ) : ?>
209194
<p>
@@ -305,7 +290,6 @@
305290
*
306291
* @type string $app_name The suggested name of the application.
307292
* @type string $success_url The URL the user will be redirected to after approving the application.
308-
* @type string $reject_url The URL the user will be redirected to after rejecting the application.
309293
* }
310294
* @param WP_User $user The user authorizing the application.
311295
*/
@@ -326,25 +310,9 @@
326310
__( 'No, I do not approve of this connection' ),
327311
'secondary',
328312
'reject',
329-
false,
330-
array(
331-
'aria-describedby' => 'description-reject',
332-
)
313+
false
333314
);
334315
?>
335-
<p class="description" id="description-reject">
336-
<?php
337-
if ( $reject_url ) {
338-
printf(
339-
/* translators: %s: The URL the user is being redirected to. */
340-
__( 'You will be sent to %s' ),
341-
'<strong><code>' . esc_html( $reject_url ) . '</code></strong>'
342-
);
343-
} else {
344-
_e( 'You will be returned to the WordPress Dashboard, and no changes will be made.' );
345-
}
346-
?>
347-
</p>
348316
</form>
349317
<?php endif; ?>
350318
</div>

src/wp-admin/includes/user.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,15 @@ function admin_created_user_email( $text ) {
638638
*
639639
* @since 5.6.0
640640
* @since 6.2.0 Allow insecure HTTP connections for the local environment.
641-
* @since 6.3.2 Validates the success and reject URLs to prevent `javascript` pseudo protocol from being executed.
641+
* @since 6.3.2 Validates the success URL to prevent `javascript` pseudo protocol from being executed.
642+
* @since x.y.z A reject URL is no longer supported or used.
642643
*
643644
* @param array $request {
644645
* The array of request data. All arguments are optional and may be empty.
645646
*
646647
* @type string $app_name The suggested name of the application.
647648
* @type string $app_id A UUID provided by the application to uniquely identify it.
648649
* @type string $success_url The URL the user will be redirected to after approving the application.
649-
* @type string $reject_url The URL the user will be redirected to after rejecting the application.
650650
* }
651651
* @param WP_User $user The user authorizing the application.
652652
* @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not.
@@ -664,16 +664,6 @@ function wp_is_authorize_application_password_request_valid( $request, $user ) {
664664
}
665665
}
666666

667-
if ( isset( $request['reject_url'] ) ) {
668-
$validated_reject_url = wp_is_authorize_application_redirect_url_valid( $request['reject_url'] );
669-
if ( is_wp_error( $validated_reject_url ) ) {
670-
$error->add(
671-
$validated_reject_url->get_error_code(),
672-
$validated_reject_url->get_error_message()
673-
);
674-
}
675-
}
676-
677667
if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
678668
$error->add(
679669
'invalid_app_id',

tests/phpunit/tests/admin/Admin_Includes_User_WpIsAuthorizeApplicationPasswordRequestValid_Test.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,12 @@ public function data_is_authorize_application_password_request_valid() {
5252
'env' => $environment_type,
5353
);
5454

55-
$datasets[ $environment_type . ' and a "https" scheme "reject_url"' ] = array(
56-
'request' => array( 'reject_url' => 'https://example.org' ),
57-
'expected_error_code' => '',
58-
'env' => $environment_type,
59-
);
60-
6155
$datasets[ $environment_type . ' and an app scheme "success_url"' ] = array(
6256
'request' => array( 'success_url' => 'wordpress://example' ),
6357
'expected_error_code' => '',
6458
'env' => $environment_type,
6559
);
6660

67-
$datasets[ $environment_type . ' and an app scheme "reject_url"' ] = array(
68-
'request' => array( 'reject_url' => 'wordpress://example' ),
69-
'expected_error_code' => '',
70-
'env' => $environment_type,
71-
);
72-
7361
$datasets[ $environment_type . ' and a "http" scheme "success_url"' ] = array(
7462
'request' => array( 'success_url' => 'http://example.org' ),
7563
'expected_error_code' => 'local' === $environment_type ? '' : 'invalid_redirect_scheme',

0 commit comments

Comments
 (0)