Skip to content

Commit 4068735

Browse files
authored
Merge pull request #1116 from hashtopolis/bug/1112-bug-encoding-error-in-the-database-or-api
Bug/1112 bug encoding error in the database or api
2 parents ca875e0 + 4350656 commit 4068735

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/inc/apiv2/common/AbstractBaseAPI.class.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ protected static function db2json(array $feature, mixed $val): mixed
398398
$obj = array_map('intval', preg_split("/,/", $val, -1, PREG_SPLIT_NO_EMPTY));
399399
} elseif ($feature['type'] == 'dict' && $feature['subtype'] = 'bool') {
400400
$obj = unserialize($val);
401-
} else {
401+
} elseif (str_starts_with($feature['type'], 'str') && $val !== null) {
402+
$obj = html_entity_decode($val, ENT_COMPAT, "UTF-8");
403+
}
404+
else {
402405
// TODO: Check all objects, instead of wild cast to hopefully-JSON compatible object
403406
$obj = $val;
404407
}
@@ -420,7 +423,7 @@ protected static function json2db(array $feature, mixed $obj): mixed
420423
$val = htmlentities($obj, ENT_QUOTES, "UTF-8");
421424
} elseif ($feature['type'] == 'array' && $feature['subtype'] == 'int') {
422425
$val = implode(",", $obj);
423-
} elseif ($feature['type'] == 'dict' && $feature['subtype'] = 'bool') {
426+
} elseif ($feature['type'] == 'dict' && $feature['subtype'] == 'bool') {
424427
$val = serialize($obj);
425428
} else {
426429
$val = strval($obj);

src/inc/utils/HashlistUtils.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function editNotes($hashlistId, $notes, $user) {
3434
if (!AccessUtils::userCanAccessHashlists($hashlist, $user)) {
3535
throw new HTException("No access to hashlist!");
3636
}
37-
Factory::getHashlistFactory()->set($hashlist, Hashlist::NOTES, htmlentities($notes, ENT_QUOTES, "UTF-8"));
37+
Factory::getHashlistFactory()->set($hashlist, Hashlist::NOTES, $notes);
3838
}
3939

4040
/**
@@ -744,7 +744,6 @@ public static function export($hashlistId, $user) {
744744
* @throws HTException
745745
*/
746746
public static function createHashlist($name, $isSalted, $isSecret, $isHexSalted, $separator, $format, $hashtype, $saltSeparator, $accessGroupId, $source, $post, $files, $user, $brainId, $brainFeatures) {
747-
$name = htmlentities($name, ENT_QUOTES, "UTF-8");
748747
$salted = ($isSalted) ? "1" : "0";
749748
$secret = ($isSecret) ? "1" : "0";
750749
$hexsalted = ($isHexSalted) ? "1" : "0";

src/inc/utils/SupertaskUtils.class.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class SupertaskUtils {
2828
* @throws HTException
2929
*/
3030
public static function bulkSupertask($name, $command, $isCpuOnly, $maxAgents, $isSmall, $crackerBinaryTypeId, $benchtype, $basefiles, $iterfiles, $user) {
31-
$name = htmlentities($name, ENT_QUOTES, "UTF-8");
3231
$isCpuOnly = ($isCpuOnly) ? 1 : 0;
3332
$isSmall = ($isSmall) ? 1 : 0;
3433
$benchtype = ($benchtype == 'speed') ? 1 : 0;
@@ -146,7 +145,7 @@ public static function createIterationPretasks($command, $name, $basefiles, $ite
146145
*/
147146
public static function renameSupertask($supertaskId, $newName) {
148147
$supertask = SupertaskUtils::getSupertask($supertaskId);
149-
Factory::getSupertaskFactory()->set($supertask, Supertask::SUPERTASK_NAME, htmlentities($newName, ENT_QUOTES, "UTF-8"));
148+
Factory::getSupertaskFactory()->set($supertask, Supertask::SUPERTASK_NAME, $newName);
150149
}
151150

152151
/**
@@ -327,7 +326,6 @@ public static function createSupertask($name, $pretasks) {
327326
if (!is_array($pretasks) || sizeof($pretasks) == 0) {
328327
throw new HTException("Cannot create empty supertask!");
329328
}
330-
$name = htmlentities($name, ENT_QUOTES, "UTF-8");
331329
$tasks = [];
332330
foreach ($pretasks as $pretaskId) {
333331
$pretask = Factory::getPretaskFactory()->get($pretaskId);
@@ -360,7 +358,6 @@ public static function createSupertask($name, $pretasks) {
360358
* @throws HTException
361359
*/
362360
public static function importSupertask($name, $isCpuOnly, $maxAgents, $isSmall, $useOptimized, $crackerBinaryTypeId, $masks, $benchtype) {
363-
$name = htmlentities($name, ENT_QUOTES, "UTF-8");
364361
$isCpuOnly = ($isCpuOnly) ? 1 : 0;
365362
$isSmall = ($isSmall) ? 1 : 0;
366363
$useOptimized = ($useOptimized) ? true : false;

src/inc/utils/TaskUtils.class.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public static function getDefault() {
9999
* @throws HTException
100100
*/
101101
public static function editNotes($taskId, $notes, $user) {
102-
$notes = htmlentities($notes, ENT_QUOTES, "UTF-8");
103102
$task = TaskUtils::getTask($taskId, $user);
104103
Factory::getTaskFactory()->set($task, Task::NOTES, $notes);
105104
}
@@ -186,7 +185,7 @@ public static function archiveTask($taskId, $user) {
186185
*/
187186
public static function renameSupertask($taskWrapperId, $newName, $user) {
188187
$taskWrapper = TaskUtils::getTaskWrapper($taskWrapperId, $user);
189-
Factory::getTaskWrapperFactory()->set($taskWrapper, TaskWrapper::TASK_WRAPPER_NAME, htmlentities($newName, ENT_QUOTES, "UTF-8"));
188+
Factory::getTaskWrapperFactory()->set($taskWrapper, TaskWrapper::TASK_WRAPPER_NAME, $newName);
190189
}
191190

192191
/**
@@ -635,7 +634,7 @@ public static function updateColor($taskId, $color, $user) {
635634
public static function rename($taskId, $name, $user) {
636635
// change task name
637636
$task = TaskUtils::getTask($taskId, $user);
638-
Factory::getTaskFactory()->set($task, Task::TASK_NAME, htmlentities($name, ENT_QUOTES, "UTF-8"));
637+
Factory::getTaskFactory()->set($task, Task::TASK_NAME, $name);
639638
}
640639

641640
/**
@@ -745,7 +744,6 @@ public static function createTask($hashlistId, $name, $attackCmd, $chunkTime, $s
745744
throw new HTException("You cannot create a task for an archived hashlist!");
746745
}
747746

748-
$name = htmlentities($name, ENT_QUOTES, "UTF-8");
749747
if (strlen($name) == 0) {
750748
$name = "Task_" . $hashlist->getId() . "_" . date("Ymd_Hi");
751749
}

0 commit comments

Comments
 (0)