Ticket #4606 (closed defect: fixed)

Opened 1 year ago

Last modified 5 months ago

Redirection Vulnerability in wp-pass.php

Reported by: snakefoot Assigned to: markjaquith
Priority: high Milestone: 2.0.12
Component: Security Version: 2.0.10
Severity: major Keywords: developer-feedback has-patch security redirect
Cc:

Description

It is possible to create an url to a trusted Wordpress blog, that redirects to an evil site:

http://vulnerable.blog/wordpress/wp-pass.php?_wp_http_referer=http://www.evilsite.com

http://blogsecurity.net/wordpress/news-050707/

Attachments

4606.patch (0.7 kB) - added by hakre on 08/26/07 11:43:00.
Patch to solve remote 302 redirect injection flaw #4606
4606.002.diff (1.8 kB) - added by markjaquith on 09/18/07 19:55:52.
introducing wp_safe_redirect()
wp2-4606.002.diff (1.9 kB) - added by snakefoot on 10/13/07 12:31:55.
Fix for branch 2.0
wp2-4606.003.diff (3.2 kB) - added by snakefoot on 10/17/07 21:22:29.
Fix for branch 2.0 (With host filter)

Change History

(follow-up: ↓ 3 ) 07/11/07 07:50:02 changed by matt

This is known and will be addresses in 2.2.2 when it is released, however it is not critical enough to necessitate a release fire drill.

08/10/07 02:14:41 changed by foolswisdom

  • milestone changed from 2.2.2 to 2.2.3.

(in reply to: ↑ 1 ) 08/14/07 17:15:49 changed by Nazgul

  • keywords set to developer-feedback.

Replying to matt:

This is known and will be addresses in 2.2.2 when it is released, however it is not critical enough to necessitate a release fire drill.

Was this included in the 2.2.2 release?

08/26/07 11:43:00 changed by hakre

  • attachment 4606.patch added.

Patch to solve remote 302 redirect injection flaw #4606

08/26/07 11:47:16 changed by hakre

  • keywords changed from developer-feedback to developer-feedback has-patch security redirect.

As the milestone-change was made from 2.2.2 to 2.2.3: no. I just tested it against 2.2.3 alpha and it's not fixed therein either.

I thought that this should be taken seriously so I analyzed it and made a fix:

Analysis

  • By effect the problem is based on unfiltered userdata.
  • Userdata is injected by the _wp_http_referer queryinfo-parameter via a get-request.
  • The reported problem can be invoked by requesting /wp-pass.php.
  • In /wp-padd.php on line 10 wordpress global redirect handler wp_redirect() is called passing wp_get_referer() as parameter.
  • wp_get_referer() injects the value into the wp_redirect() handler.
  • wp_get_referer() is defined in /wp-includes/functions.php on line 874ff.
  • It returns $_REQUEST['_wp_http_referer'] in this case which is then passed to wp_redirect().
  • wp_redirect() is defined in /wp-includes/pluggable.php on line 393ff.
  • Next to some design flaws in this routine, it does what it should: perform the redirect.
  • The problem is to pass the returned value of wp_get_referer() directly to wp_redirect() without checking for valid input.
  • A Fix has to be applied in /wp-padd.php.

Solution

  • /wp-padd.php should only redirect to adresses on the current server (domain based security).
  • This can be achieved by comparing the referer against blog-configuration.
  • This way of solving is done by the attached patch.

Testing Documentation

  1. Requested /wp-pass.php?_wp_http_referer=http://localhost/
  2. No Redirection is made.
  3. Requested /wp-pass.php?_wp_http_referer=http://webroot.loc/wordpress/
  4. Redirect is properly done.

Redirect to other Domains aren't possible any longer. The script still redirects to URLs on the same Domain.

08/26/07 12:53:10 changed by hakre

correction to my report above: 2.2.3 alpha = 2.3 alpha from SVN

08/29/07 17:44:54 changed by foolswisdom

  • milestone changed from 2.2.3 to 2.3.

09/18/07 19:55:52 changed by markjaquith

  • attachment 4606.002.diff added.

introducing wp_safe_redirect()

09/18/07 19:59:19 changed by markjaquith

  • owner changed from anonymous to markjaquith.
  • status changed from new to assigned.

Check out 4606.002.diff which introduces wp_safe_redirect()

wp_safe_redirect is like wp_redirect(), but it only allows server relative redirects (start with a single forward slash) or redirects that start with get_option('home'). Anything else, including URLs that start with "//" or URLs on a different domain, get changed to get_option('home') . '/' before wp_redirect() is called.

This won't be used all, the time -- only when we're using a user-provided redirect.

This allows for the most backwards compatibility (as opposed to patching wp_redirect() itself.

I changed a few instances of using untrusted URLs for redirects, but there may be more.

09/18/07 20:05:43 changed by ryan

+1

09/18/07 22:23:16 changed by markjaquith

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [6131]) Introducing wp_safe_redirect(). fixes #4606 for trunk

09/19/07 03:35:56 changed by markjaquith

  • status changed from closed to reopened.
  • resolution deleted.

Issue with that first swing was that it couldn't handle relative paths, like "wp-admin/" -- which is the default redirect_to for wp-login.php

A more robust solution is coming up.

09/19/07 03:47:37 changed by markjaquith

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [6134]) More robust wp_safe_redirect(). Introducing wp_sanitize_redirect() for use in wp_redirect() and wp_safe_redirect(). fixes #4606

09/19/07 04:14:53 changed by markjaquith

(In [6136]) Put a filter in wp_safe_redirect() so people can whitelist other domains. see #4606

10/13/07 12:10:13 changed by snakefoot

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 2.3 to 2.0.12.

This security fix should be moved to the 2.0 branch

10/13/07 12:31:55 changed by snakefoot

  • attachment wp2-4606.002.diff added.

Fix for branch 2.0

10/17/07 21:22:29 changed by snakefoot

  • attachment wp2-4606.003.diff added.

Fix for branch 2.0 (With host filter)

02/07/08 18:23:51 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [6751]) wp_safe_redirect() for 2.0. Props markjaquith and snakefoot. fixes #4606 for 2.0