I think we need to not use drupal_get_token() and drupal_valid_token() inside the functions file_entity_download_uri() and file_entity_download_page().
Probably something like the following:
function file_entity_get_download_token($file) {
$identifier = !empty($GLOBALS['user']->uid) ? session_id() : ip_address();
return drupal_hmac_base64("file/$file->fid/download", $identifier . drupal_get_private_key() . drupal_get_hash_salt());
}
And a converse of drupal_valid_token().
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2062663-fix-the-token-on-callback-for-anonymous-users-5.patch | 1.64 KB | KarlKedrovsky |
| #2 | 2062663-fix-the-token-on-callback-for-anonymous-users-2.patch | 1.73 KB | KarlKedrovsky |
Comments
Comment #1
dave reidComment #2
KarlKedrovsky commentedAttached is my first whack at the patch to implement this.
Comment #4
dave reidI think this will need to be changed to
!isset($_GET['token']) || $_GET['token'] !== file_entity_get_download_token($file)Comment #5
KarlKedrovsky commentedOK, so I actually read the documentation for drupal_valid_token() this time which made it pretty obvious my original patch wasn't going to give us what we want. I made the update specified in #4 and worked just fine for me.
Comment #6
aaron commentedIt works as advertised.
Comment #7
dave reidCommmitted #5 to 7.x-2.x since it worked great! http://drupalcode.org/project/file_entity.git/commit/ca3f015