]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add whitelist and blacklist for openid URLs
authorEvan Prodromou <evan@status.net>
Thu, 25 Mar 2010 20:58:05 +0000 (16:58 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 25 Mar 2010 20:58:05 +0000 (16:58 -0400)
plugins/OpenID/finishopenidlogin.php
plugins/OpenID/openid.php
plugins/OpenID/openidlogin.php

index 1f9bde0f157959fc86fd5e98ea26a798b9b49102..f3a48330063f1a93aac04835785b01c66f520f3c 100644 (file)
@@ -158,6 +158,9 @@ class FinishopenidloginAction extends Action
             $canonical = ($response->endpoint->canonicalID) ?
               $response->endpoint->canonicalID : $response->getDisplayIdentifier();
 
+            oid_assert_allowed($display);
+            oid_assert_allowed($canonical);
+
             $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
 
             if ($sreg_resp) {
index d49941aed1e42a4ba99b8eebc48202ecc6122f9e..1524389177eb5ee0e6eb158655539927ec30b343 100644 (file)
@@ -257,6 +257,35 @@ function oid_update_user(&$user, &$sreg)
     return true;
 }
 
+function oid_assert_allowed($url)
+{
+    $blacklist = common_config('openid', 'blacklist');
+    $whitelist = common_config('openid', 'whitelist');
+
+    if (empty($blacklist)) {
+        $blacklist = array();
+    }
+
+    if (empty($whitelist)) {
+        $whitelist = array();
+    }
+
+    foreach ($blacklist as $pattern) {
+        if (preg_match("/$pattern/", $url)) {
+            common_log(LOG_INFO, "Matched OpenID blacklist pattern {$pattern} with {$url}");
+            foreach ($whitelist as $exception) {
+                if (preg_match("/$exception/", $url)) {
+                    common_log(LOG_INFO, "Matched OpenID whitelist pattern {$exception} with {$url}");
+                    return;
+                }
+            }
+            throw new ClientException(_m("Unauthorized URL used for OpenID login."), 403);
+        }
+    }
+
+    return;
+}
+
 class AutosubmitAction extends Action
 {
     var $form_html = null;
index 9ba55911c014c8afa156e16ce71b7fb33610ba3d..2a743672cf68d2bfb59e4bcfa61c0239cccd489c 100644 (file)
@@ -31,6 +31,8 @@ class OpenidloginAction extends Action
         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $openid_url = $this->trimmed('openid_url');
 
+            oid_assert_allowed($openid_url);
+
             # CSRF protection
             $token = $this->trimmed('token');
             if (!$token || $token != common_session_token()) {