@@ -344,40 +344,45 @@ function uploadGeneratetoken($args)
344
344
$ existingBitstream = $ bitstreamModel ->getByChecksum ($ args ['checksum ' ]);
345
345
if ($ existingBitstream )
346
346
{
347
- $ revision = $ itemModel -> getLastRevision ( $ item );
348
-
349
- if ($ revision == false )
347
+ // User must have read access to the existing bitstream if they are circumventing the upload.
348
+ // Otherwise an attacker could spoof the checksum and read a private bitstream with a known checksum.
349
+ if ($ itemModel -> policyCheck ( $ existingBitstream -> getItemrevision ()-> getItem (), $ userDao , MIDAS_POLICY_READ ) )
350
350
{
351
- // Create new revision if none exists yet
352
- Zend_Loader::loadClass ('ItemRevisionDao ' , BASE_PATH .'/core/models/dao ' );
353
- $ revision = new ItemRevisionDao ();
354
- $ revision ->setChanges ('Initial revision ' );
355
- $ revision ->setUser_id ($ userDao ->getKey ());
356
- $ revision ->setDate (date ('c ' ));
357
- $ revision ->setLicenseId (null );
358
- $ itemModel ->addRevision ($ item , $ revision );
359
- }
351
+ $ revision = $ itemModel ->getLastRevision ($ item );
360
352
361
- $ siblings = $ revision ->getBitstreams ();
362
- foreach ($ siblings as $ sibling )
363
- {
364
- if ($ sibling ->getName () == $ args ['filename ' ])
353
+ if ($ revision == false )
354
+ {
355
+ // Create new revision if none exists yet
356
+ Zend_Loader::loadClass ('ItemRevisionDao ' , BASE_PATH .'/core/models/dao ' );
357
+ $ revision = new ItemRevisionDao ();
358
+ $ revision ->setChanges ('Initial revision ' );
359
+ $ revision ->setUser_id ($ userDao ->getKey ());
360
+ $ revision ->setDate (date ('c ' ));
361
+ $ revision ->setLicenseId (null );
362
+ $ itemModel ->addRevision ($ item , $ revision );
363
+ }
364
+
365
+ $ siblings = $ revision ->getBitstreams ();
366
+ foreach ($ siblings as $ sibling )
365
367
{
366
- // already have a file with this name. don't add new record.
367
- return array ('token ' => '' );
368
+ if ($ sibling ->getName () == $ args ['filename ' ])
369
+ {
370
+ // already have a file with this name. don't add new record.
371
+ return array ('token ' => '' );
372
+ }
368
373
}
374
+ Zend_Loader::loadClass ('BitstreamDao ' , BASE_PATH .'/core/models/dao ' );
375
+ $ bitstream = new BitstreamDao ();
376
+ $ bitstream ->setChecksum ($ args ['checksum ' ]);
377
+ $ bitstream ->setName ($ args ['filename ' ]);
378
+ $ bitstream ->setSizebytes ($ existingBitstream ->getSizebytes ());
379
+ $ bitstream ->setPath ($ existingBitstream ->getPath ());
380
+ $ bitstream ->setAssetstoreId ($ existingBitstream ->getAssetstoreId ());
381
+ $ bitstream ->setMimetype ($ existingBitstream ->getMimetype ());
382
+ $ revisionModel = MidasLoader::loadModel ('ItemRevision ' );
383
+ $ revisionModel ->addBitstream ($ revision , $ bitstream );
384
+ return array ('token ' => '' );
369
385
}
370
- Zend_Loader::loadClass ('BitstreamDao ' , BASE_PATH .'/core/models/dao ' );
371
- $ bitstream = new BitstreamDao ();
372
- $ bitstream ->setChecksum ($ args ['checksum ' ]);
373
- $ bitstream ->setName ($ args ['filename ' ]);
374
- $ bitstream ->setSizebytes ($ existingBitstream ->getSizebytes ());
375
- $ bitstream ->setPath ($ existingBitstream ->getPath ());
376
- $ bitstream ->setAssetstoreId ($ existingBitstream ->getAssetstoreId ());
377
- $ bitstream ->setMimetype ($ existingBitstream ->getMimetype ());
378
- $ revisionModel = MidasLoader::loadModel ('ItemRevision ' );
379
- $ revisionModel ->addBitstream ($ revision , $ bitstream );
380
- return array ('token ' => '' );
381
386
}
382
387
}
383
388
//we don't already have this content, so create the token
0 commit comments