Skip to content

Commit 741f40e

Browse files
authored
Merge pull request #2350 from nextcloud/fix/url-hash-xxh128
fix: Use xxh128 for url_hash column instead of md5
2 parents 491df29 + 19268f0 commit 741f40e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/Db/BookmarkMapper.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ protected function getFindByUrlQuery(): IQueryBuilder {
109109
->select('*')
110110
->from('bookmarks')
111111
->where($qb->expr()->eq('user_id', $qb->createParameter('user_id')))
112-
->andWhere($qb->expr()->eq('url_hash', $qb->createParameter('url_hash')));
112+
->andWhere($qb->expr()->eq('url_hash', $qb->createParameter('url_hash')))
113+
->andWhere($qb->expr()->eq('url', $qb->createParameter('url')));
113114
return $qb;
114115
}
115116

@@ -132,7 +133,8 @@ public function findByUrl($userId, $url): Bookmark {
132133
$qb = $this->findByUrlQuery;
133134
$qb->setParameters([
134135
'user_id' => $userId,
135-
'url_hash' => md5($url),
136+
'url' => $url,
137+
'url_hash' => hash('xxh128', $url),
136138
]);
137139
return $this->findEntity($qb);
138140
}
@@ -401,7 +403,8 @@ private function _sortAndPaginate(IQueryBuilder $qb, QueryParameters $params): v
401403
private function _filterUrl(IQueryBuilder $qb, QueryParameters $params): void {
402404
if (($url = $params->getUrl()) !== null) {
403405
$normalized = $this->urlNormalizer->normalize($url);
404-
$qb->andWhere($qb->expr()->eq('b.url_hash', $qb->createPositionalParameter(md5($normalized))));
406+
$qb->andWhere($qb->expr()->eq('b.url_hash', $qb->createPositionalParameter(hash('xxh128', $normalized))));
407+
$qb->andWhere($qb->expr()->eq('b.url', $qb->createPositionalParameter($normalized)));
405408
}
406409
}
407410

@@ -880,7 +883,7 @@ public function insert(Entity $entity): Bookmark {
880883
if ($entity->isWebLink()) {
881884
$entity->setUrl($this->urlNormalizer->normalize($entity->getUrl()));
882885
}
883-
$entity->setUrlHash(md5($entity->getUrl()));
886+
$entity->setUrlHash(hash('xxh128', $entity->getUrl()));
884887

885888
if ($entity->getAdded() === null) {
886889
$entity->setAdded(time());

lib/Migration/Version016002000Date20260201124723.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
6969
$this->db->commit();
7070
$this->db->beginTransaction();
7171
}
72-
$setQb->setParameter('url_hash', md5($row['url']));
72+
$setQb->setParameter('url_hash', hash('xxh128', $row['url']));
7373
$setQb->setParameter('id', $row['id']);
7474
$setQb->executeStatement();
7575
$output->advance();

0 commit comments

Comments
 (0)