Make WordPress Core


Ignore:
Timestamp:
12/04/2020 09:46:42 PM (4 years ago)
Author:
helen
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.
Reviewed by TimothyBlynJacobs, helen.
Merges [49752] to the 5.6 branch.
Fixes #51939.

Location:
branches/5.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

    r49617 r49754  
    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.