Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#42828 closed defect (bug) (fixed)

Hard-coded 403 status in REST response should use `rest_authorization_required_code()`

Reported by: jaswrks Owned by: rachelbaker
Priority: normal Milestone: 4.9.2
Component: REST API Version: 4.7
Severity: normal Keywords: commit
Cc: Focuses: rest-api

Description

Line 911 in the WP_REST_Server class currently uses a hard-coded 403 error code. It should be calling upon rest_authorization_required_code() to determine the proper response code; e.g., 401 instead of a 403 whenever a user is not logged-in.

<?php
$response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) );

Should be:

<?php
$response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => rest_authorization_required_code() ) );

Attachments (1)

42828.patch​ (740 bytes ) - added by jaswrks 9 years ago.

Download all attachments as: .zip

Change History (7)

#1 @rmccue
9 years ago

  • Keywords commit added
  • Milestone Awaiting Review → 4.9.2
  • Version trunk → 4.7

#2 @rachelbaker
9 years ago

  • Owner set to rachelbaker
  • Resolution → fixed
  • Status new → closed

In 42421:

REST API: Return the proper status code for failed permission callbacks in WP_REST_Server->dispatch().

Use the rest_authorization_required_code() function to return a 401 status code when a permission callback fails due to a user not being logged in.

Props jaswrks.
Fixes #42828.

#3 @rachelbaker
9 years ago

In 42422:

REST API: Return the proper status code for failed permission callbacks in WP_REST_Server->dispatch().

Use the rest_authorization_required_code() function to return a 401 status code when a permission callback fails due to a user not being logged in.

Merges [42421] to the 4.9 branch.

Props jaswrks.
Fixes #42828.

#4 @rachelbaker
9 years ago

  • Resolution fixed
  • Status closed → reopened

Reopening because I missed committing the unit test changes needed here.

#5 @rachelbaker
9 years ago

  • Resolution → fixed
  • Status reopened → closed

In 42423:

REST API: Adjust unit testes to expect a 401 status code in error responses from permission callbacks when user is not authenticated.

Missed in [42421].

Fixes #42828.

#6 @rachelbaker
9 years ago

In 42427:

EST API: Adjust unit testes to expect a 401 status code in error responses from permission callbacks when user is not authenticated.

Missed in [42421].

Merges [42423] to the 4.9 branch.
Fixes #42828.

Note: See TracTickets for help on using tickets.