add CSRF protection to avatar

darcs-hash:20080829023919-84dde-38e4bf6bddc120a221af5f856d9f88b7a532096b.gz
This commit is contained in:
Evan Prodromou 2008-08-28 22:39:19 -04:00
parent d146355875
commit d3c86d0016

View 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;