]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TagSub/actions/tagsub.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / TagSub / actions / tagsub.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008-2011, StatusNet, Inc.
5  *
6  * Tag subscription action.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * PHP version 5
22  *
23  * @category  Action
24  * @package   StatusNet
25  * @author    Brion Vibber <brion@status.net>
26  * @author    Evan Prodromou <evan@status.net>
27  * @copyright 2008-2010 StatusNet, Inc.
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
29  * @link      http://status.net/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 /**
37  * Tag subscription action
38  *
39  * Takes parameters:
40  *
41  *    - token: session token to prevent CSRF attacks
42  *    - ajax: boolean; whether to return Ajax or full-browser results
43  *
44  * Only works if the current user is logged in.
45  *
46  * @category  Action
47  * @package   StatusNet
48  * @author    Evan Prodromou <evan@status.net>
49  * @author    Brion Vibber <brion@status.net>
50  * @copyright 2008-2011 StatusNet, Inc.
51  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
52  * @link      http://status.net/
53  */
54 class TagsubAction extends Action
55 {
56     var $user;
57     var $tag;
58
59     /**
60      * Check pre-requisites and instantiate attributes
61      *
62      * @param Array $args array of arguments (URL, GET, POST)
63      *
64      * @return boolean success flag
65      */
66     function prepare($args)
67     {
68         parent::prepare($args);
69         if ($this->boolean('ajax')) {
70             GNUsocial::setApi(true);
71         }
72
73         // Only allow POST requests
74
75         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
76             // TRANS: Client error displayed trying to perform any request method other than POST.
77             // TRANS: Do not translate POST.
78             $this->clientError(_m('This action only accepts POST requests.'));
79         }
80
81         // CSRF protection
82
83         $token = $this->trimmed('token');
84
85         if (!$token || $token != common_session_token()) {
86             // TRANS: Client error displayed when the session token is not okay.
87             $this->clientError(_m('There was a problem with your session token.'.
88                                  ' Try again, please.'));
89         }
90
91         // Only for logged-in users
92
93         $this->user = common_current_user();
94
95         if (empty($this->user)) {
96             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
97             $this->clientError(_m('Not logged in.'));
98         }
99
100         // Profile to subscribe to
101
102         $this->tag = $this->arg('tag');
103
104         if (empty($this->tag)) {
105             // TRANS: Client error displayed trying to subscribe to a non-existing profile.
106             $this->clientError(_m('No such profile.'));
107         }
108
109         return true;
110     }
111
112     /**
113      * Handle request
114      *
115      * Does the subscription and returns results.
116      *
117      * @param Array $args unused.
118      *
119      * @return void
120      */
121     function handle($args)
122     {
123         // Throws exception on error
124
125         TagSub::start($this->user->getProfile(),
126                       $this->tag);
127
128         if ($this->boolean('ajax')) {
129             $this->startHTML('text/xml;charset=utf-8');
130             $this->elementStart('head');
131             // TRANS: Page title when tag subscription succeeded.
132             $this->element('title', null, _m('Subscribed'));
133             $this->elementEnd('head');
134             $this->elementStart('body');
135             $unsubscribe = new TagUnsubForm($this, $this->tag);
136             $unsubscribe->show();
137             $this->elementEnd('body');
138             $this->endHTML();
139         } else {
140             $url = common_local_url('tag',
141                                     array('tag' => $this->tag));
142             common_redirect($url, 303);
143         }
144     }
145 }