From d3c86d00163bba1a57d1f597995721b8badbce62 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Aug 2008 22:39:19 -0400 Subject: [PATCH] add CSRF protection to avatar darcs-hash:20080829023919-84dde-38e4bf6bddc120a221af5f856d9f88b7a532096b.gz --- actions/avatar.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/actions/avatar.php b/actions/avatar.php index ebfbd72952..9f397e93c3 100644 --- a/actions/avatar.php +++ b/actions/avatar.php @@ -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; -- 2.39.5