]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add CSRF protection to avatar
authorEvan Prodromou <evan@prodromou.name>
Fri, 29 Aug 2008 02:39:19 +0000 (22:39 -0400)
committerEvan Prodromou <evan@prodromou.name>
Fri, 29 Aug 2008 02:39:19 +0000 (22:39 -0400)
darcs-hash:20080829023919-84dde-38e4bf6bddc120a221af5f856d9f88b7a532096b.gz

actions/avatar.php

index ebfbd72952e9d1bec9ec315d3c958c948de38e4b..9f397e93c3e0148248955ae8746308a489631f02 100644 (file)
@@ -58,6 +58,7 @@ class AvatarAction extends SettingsAction {
                                                                                   'id' => 'avatar',
                                                                                   'action' =>
                                                                                   common_local_url('avatar')));
+               common_hidden('token', common_session_token());
                common_element('input', array('name' => 'MAX_FILE_SIZE',
                                                                          'type' => 'hidden',
                                                                          'id' => 'MAX_FILE_SIZE',
@@ -72,6 +73,14 @@ class AvatarAction extends SettingsAction {
 
        function handle_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;
+               }
+
                switch ($_FILES['avatarfile']['error']) {
                 case UPLOAD_ERR_OK: # success, jump out
                        break;