]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/remotesubscribe.php
allow doc and api calls from private
[quix0rs-gnu-social.git] / actions / remotesubscribe.php
index a37ca8c3ff91f1fdf8e9ff303b5ffb9e51466697..0adcc08481a30038f6d2c6ec139bce3350e22776 100644 (file)
@@ -33,6 +33,14 @@ class RemotesubscribeAction extends Action {
                }
 
                if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+                       
+                       # CSRF protection
+                       $token = $this->trimmed('token');
+                       if (!$token || $token != common_session_token()) {
+                               $this->show_form(_('There was a problem with your session token. Try again, please.'));
+                               return;
+                       }
+                       
                        $this->remote_subscription();
                } else {
                        $this->show_form();
@@ -64,10 +72,11 @@ class RemotesubscribeAction extends Action {
                $profile = $this->trimmed('profile_url');
                common_show_header(_('Remote subscribe'), NULL, $err,
                                                   array($this, 'show_top'));
-               # id = remotesubscribe conflicts with the 
+               # id = remotesubscribe conflicts with the
                # button on profile page
                common_element_start('form', array('id' => 'remsub', 'method' => 'post',
                                                                                   'action' => common_local_url('remotesubscribe')));
+               common_hidden('token', common_session_token());
                common_input('nickname', _('User nickname'), $nickname,
                                         _('Nickname of the user you want to follow'));
                common_input('profile_url', _('Profile URL'), $profile,
@@ -81,14 +90,14 @@ class RemotesubscribeAction extends Action {
                $user = $this->get_user();
 
                if (!$user) {
-                       $this->show_form(_('No such user!'));
+                       $this->show_form(_('No such user.'));
                        return;
                }
 
                $profile = $this->trimmed('profile_url');
 
                if (!$profile) {
-                       $this->show_form(_('No such user!'));
+                       $this->show_form(_('No such user.'));
                        return;
                }
 
@@ -105,7 +114,9 @@ class RemotesubscribeAction extends Action {
                        return;
                }
 
-        $xrds =& Auth_Yadis_XRDS::parseXRDS($yadis->response_text);
+               # XXX: a little liberal for sites that accidentally put whitespace before the xml declaration
+               
+        $xrds =& Auth_Yadis_XRDS::parseXRDS(trim($yadis->response_text));
 
                if (!$xrds) {
                        $this->show_form(_('Not a valid profile URL (no XRDS defined).'));
@@ -119,6 +130,18 @@ class RemotesubscribeAction extends Action {
                        return;
                }
 
+               if (omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]) ==
+                       common_local_url('requesttoken'))
+               {
+                       $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+                       return;
+               }
+
+               if (User::staticGet('uri', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]))) {
+                       $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+                       return;
+               }
+               
                list($token, $secret) = $this->request_token($omb);
 
                if (!$token || !$secret) {
@@ -302,7 +325,14 @@ class RemotesubscribeAction extends Action {
                $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname));
                $req->set_parameter('omb_listenee_nickname', $user->nickname);
                $req->set_parameter('omb_listenee_license', $config['license']['url']);
+
                $profile = $user->getProfile();
+               if (!$profile) {
+                       common_log_db_error($user, 'SELECT', __FILE__);
+                       $this->server_error(_('User without matching profile'));
+                       return;
+               }
+               
                if ($profile->fullname) {
                        $req->set_parameter('omb_listenee_fullname', $profile->fullname);
                }
@@ -339,6 +369,8 @@ class RemotesubscribeAction extends Action {
                $omb['post_notice_url'] = omb_service_uri($omb[OMB_ENDPOINT_POSTNOTICE]);
                $omb['update_profile_url'] = omb_service_uri($omb[OMB_ENDPOINT_UPDATEPROFILE]);
 
+               common_ensure_session();
+               
                $_SESSION['oauth_authorization_request'] = $omb;
 
                # Redirect to authorization service