Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#47479 closed enhancement (fixed)

Do not return 5xx for invalid/expired recovery mode cookies

Reported by: david.binda Owned by: SergeyBiryukov
Priority: normal Milestone: 5.3
Component: Site Health Version: 5.2
Severity: normal Keywords: servehappy has-patch
Cc: Focuses:

Description

The WP_Recovery_Mode class dies in certain situations where returning a 5xx status code does not feel appropriate, as the request did not produce a server error, but rather the authentication failed. In such situations, it might be more appropriate to return a 4xx error (presumably 403). The situations in mind here are the following:

  1. when the recovery mode cookie is expired
  2. when the recovery mode cookie is invalid
  3. when the exit recovery mode nonce check failed

As those failures also unset related cookies, the 5xx status may result in an improper handling on certain server configurations (eg.: overriding 5xx responses with a custom response which is not properly passing the cookie headers).

I'm attaching a patch which changes the response codes from default 500 to 403 in the cases mentioned above.

Attachments (2)

47479.diff (983 bytes ) - added by david.binda 7 years ago.
47479-2.diff (1.0 KB ) - added by david.binda 7 years ago.

Download all attachments as: .zip

Change History (13)

@david.binda
7 years ago

#1 @spacedmonkey
7 years ago

  • Keywords needs-patch servehappy added
  • Owner set to spacedmonkey
  • Status newassigned

#2 @SergeyBiryukov
7 years ago

  • Component GeneralBootstrap/Load

#3 @spacedmonkey
7 years ago

@davidbinda This looks good.

For calls to wp_die that pass a WP_Error object. Please add the status code like this.

@david.binda
7 years ago

#4 @david.binda
7 years ago

Thanks for the feedback @spacedmonkey ! I've updated the patch accordingly, please let me know if it works for you :)

#5 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review5.3

This ticket was mentioned in Slack in #core-php by spacedmonkey. View the logs.


7 years ago

#7 @spacedmonkey
7 years ago

  • Owner changed from spacedmonkey to SergeyBiryukov

Assigning to @SergeyBiryukov to merge.

This ticket was mentioned in Slack in #core-php by spacedmonkey. View the logs.


7 years ago

#9 @SergeyBiryukov
7 years ago

  • Keywords has-patch added; needs-patch removed

#10 @SergeyBiryukov
7 years ago

  • Resolutionfixed
  • Status assignedclosed

In 45544:

Bootstrap/Load: Return a 403 error code when the recovery mode cookie is invalid or expired, or the exit recovery mode nonce check failed.

Props david.binda, spacedmonkey.
Fixes #47479.

#11 @spacedmonkey
7 years ago

  • Component Bootstrap/LoadSite Health
Note: See TracTickets for help on using tickets.