WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/04/2020 09:42:52 PM (12 months ago)
Author:
TimothyBlynJacobs
Message:

App Passwords: Prevent conflicts when Basic Auth is already used by the site.

Application Passwords uses Basic Authentication to transfer authentication details. If the site is already using Basic Auth, for instance to implement a private staging environment, then the REST API will treat this as an authentication attempt and would end up generating an error for any REST API request.

Now, Application Password authentication will only be attempted if Application Passwords is in use by a site. This is flagged by setting an option whenever an Application Password is created. An upgrade routine is added to set this option if any App Passwords already exist.

Lastly, creating an Application Password will be prevented if the site appears to already be using Basic Authentication.

Props chexwarrior, georgestephanis, adamsilverstein, helen, Clorith, marybaum, TimothyBlynJacobs.
Fixes #51939.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

    r49617 r49752  
    406406
    407407    /**
     408     * @ticket 51939
     409     */
     410    public function test_create_item_records_app_passwords_in_use() {
     411        wp_set_current_user( self::$admin );
     412
     413        $this->assertFalse( WP_Application_Passwords::is_in_use() );
     414
     415        $request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' );
     416        $request->set_body_params( array( 'name' => 'App' ) );
     417        $response = rest_do_request( $request );
     418
     419        $this->assertSame( 201, $response->get_status() );
     420        $this->assertTrue( WP_Application_Passwords::is_in_use() );
     421    }
     422
     423    /**
    408424     * @ticket 42790
    409425     */
Note: See TracChangeset for help on using the changeset viewer.