Skip to content

Commit 9c39efd

Browse files
authored
N°8549 - Update inline images secret (#815)
1 parent d5f2303 commit 9c39efd

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

core/ormdocument.class.inc.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ public static function DownloadDocument(WebPage $oPage, $sClass, $id, $sAttCode,
362362
throw new Exception("Invalid id ($id) for class '$sClass' - the object does not exist or you are not allowed to view it");
363363
}
364364
}
365-
if (($sSecretField != null) && ($oObj->Get($sSecretField) != $sSecretValue)) {
366-
usleep(200);
365+
if (($sSecretField != null) && !hash_equals($oObj->Get($sSecretField), $sSecretValue)) {
367366
throw new Exception("Invalid secret for class '$sClass' - the object does not exist or you are not allowed to view it");
368367
}
369368
/** @var \ormDocument $oDocument */

pages/ajax.render.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ function(data){
21402140
$oAttachment->Set('item_class', $sObjClass);
21412141
$oAttachment->SetDefaultOrgId();
21422142
$oAttachment->Set('contents', $oDoc);
2143-
$oAttachment->Set('secret', sprintf('%06x', mt_rand(0, 0xFFFFFF))); // something not easy to guess
2143+
$oAttachment->Set('secret', bin2hex(random_bytes(16))); // 128 bits of entropy, cryptographically secure
21442144
$iAttId = $oAttachment->DBInsert();
21452145

21462146
$aResult['uploaded'] = 1;
@@ -2198,7 +2198,7 @@ function(data){
21982198
$oAttachment->Set('item_class', $sObjClass);
21992199
$oAttachment->SetDefaultOrgId();
22002200
$oAttachment->Set('contents', $oDoc);
2201-
$oAttachment->Set('secret', sprintf('%06x', mt_rand(0, 0xFFFFFF))); // something not easy to guess
2201+
$oAttachment->Set('secret', bin2hex(random_bytes(16))); // 128 bits of entropy, cryptographically secure
22022202
$iAttId = $oAttachment->DBInsert();
22032203

22042204
IssueLog::Trace('InlineImage created', LogChannels::INLINE_IMAGE, [

0 commit comments

Comments
 (0)