Skip to content

Commit a67be9c

Browse files
abnegateclaude
andcommitted
fix: revert to strict comparison in updateDocument, normalize tenant instead
The loose comparison in the update-detection block could miss type-only changes, allowing writes to persist with only READ authorization checked instead of UPDATE. Normalize the old document's $tenant value so both sides match under strict comparison. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5fb39b6 commit a67be9c

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/Database/Database.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,9 @@ public function updateDocument(string $collection, string $id, Document $documen
60556055
$document['$createdAt'] = ($createdAt === null || !$this->preserveDates) ? $old->getCreatedAt() : $createdAt;
60566056

60576057
if ($this->adapter->getSharedTables()) {
6058-
$document['$tenant'] = $old->getTenant(); // Make sure user doesn't switch tenant
6058+
$tenant = $old->getTenant();
6059+
$document['$tenant'] = $tenant;
6060+
$old->setAttribute('$tenant', $tenant); // Normalize for strict comparison
60596061
}
60606062
$document = new Document($document);
60616063

@@ -6065,13 +6067,6 @@ public function updateDocument(string $collection, string $id, Document $documen
60656067
return $attribute['type'] === Database::VAR_RELATIONSHIP;
60666068
});
60676069

6068-
$idAttributes = [];
6069-
foreach (\array_merge(self::INTERNAL_ATTRIBUTES, $attributes) as $attribute) {
6070-
if ($attribute['type'] === Database::VAR_ID) {
6071-
$idAttributes[$attribute['$id']] = true;
6072-
}
6073-
}
6074-
60756070
$shouldUpdate = false;
60766071

60776072
if ($collection->getId() !== self::METADATA) {
@@ -6169,8 +6164,7 @@ public function updateDocument(string $collection, string $id, Document $documen
61696164

61706165
$oldValue = $old->getAttribute($key);
61716166

6172-
$isIdType = isset($idAttributes[$key]);
6173-
if ($isIdType ? $value != $oldValue : $value !== $oldValue) {
6167+
if ($value !== $oldValue) {
61746168
$shouldUpdate = true;
61756169
break;
61766170
}

0 commit comments

Comments
 (0)