]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 476603 - "[SECURITY] Editing attachments doesn't have any CSRF protection" [p...
authorreed%reedloden.com <>
Mon, 30 Mar 2009 21:03:43 +0000 (21:03 +0000)
committerreed%reedloden.com <>
Mon, 30 Mar 2009 21:03:43 +0000 (21:03 +0000)
attachment.cgi
template/en/default/attachment/edit.html.tmpl
template/en/default/bug/show.xml.tmpl

index a0f14c185ce0fe821268c7abd4975a99172391ff..951e995eac983c0401da019595a85501eb1935b5 100755 (executable)
@@ -585,6 +585,9 @@ sub update {
         ($vars->{'operations'}) =
             Bugzilla::Bug::GetBugActivity($bug->id, $attachment->id, $cgi->param('delta_ts'));
 
+        # The token contains the old modification_time. We need a new one.
+        $cgi->param('token', issue_hash_token([$attachment->id, $attachment->modification_time]));
+
         # If the modification date changed but there is no entry in
         # the activity table, this means someone commented only.
         # In this case, there is no reason to midair.
@@ -599,6 +602,12 @@ sub update {
             exit;
         }
     }
+
+    # We couldn't do this check earlier as we first had to validate attachment ID
+    # and display the mid-air collision page if modification_time changed.
+    my $token = $cgi->param('token');
+    check_hash_token($token, [$attachment->id, $attachment->modification_time]);
+
     # If the submitter of the attachment is not in the insidergroup,
     # be sure that he cannot overwrite the private bit.
     # This check must be done before calling Bugzilla::Flag*::validate(),
index ca0a8bc6e126fd257aa4edd2112de36a2df5ac38..1b00df9994c921f37e4a4eb3ade189f0c7b7718b 100644 (file)
   <input type="hidden" name="action" value="update">
   <input type="hidden" name="contenttypemethod" value="manual">
   <input type="hidden" name="delta_ts" value="[% attachment.modification_time FILTER html %]">
+  [% IF user.id %]
+    <input type="hidden" name="token" value="[% issue_hash_token([attachment.id, attachment.modification_time]) FILTER html %]">
+  [% END %]
 
   <table class="attachment_info" width="100%">
 
index bd7459271453afdc0b1186a14a2f176763655027..c59b2bed03e510f0133bff9ab8eb6aa68201df80 100644 (file)
             <type>[% a.contenttype FILTER xml %]</type>
             <size>[% a.datasize FILTER xml %]</size>
             <attacher>[% a.attacher.email FILTER xml %]</attacher>
-        [% IF displayfields.attachmentdata %]
-            <data encoding="base64">[% a.data FILTER base64 %]</data>
-        [% END %]        
+            [%# This is here so automated clients can still use attachment.cgi %]
+            [% IF displayfields.token && user.id %]
+              <token>[% issue_hash_token([a.id, a.modification_time]) FILTER xml %]</token>
+            [% END %]
+            [% IF displayfields.attachmentdata %]
+              <data encoding="base64">[% a.data FILTER base64 %]</data>
+            [% END %]        
 
             [% FOREACH flag = a.flags %]
               <flag name="[% flag.type.name FILTER xml %]"