mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Restrict createdAt and updatedAt attributes for non-API key and non-privileged users in Create, Update, and Upsert actions
This commit is contained in:
1 parent
de69692ff2
commit
983d102ff2
3 files changed
+11
-17
No files matched your search
+5
-7
@@ -332,7 +332,7 @@ class Create extends Action
|
||||
}
|
||||
};
|
||||
|
||||
$documents = \array_map(function ($document) use ($collection, $permissions, $checkPermissions, $isBulk, $documentId, $setPermissions, $isAPIKey) {
|
||||
$documents = \array_map(function ($document) use ($collection, $permissions, $checkPermissions, $isBulk, $documentId, $setPermissions, $isAPIKey, $isPrivilegedUser) {
|
||||
$document['$collection'] = $collection->getId();
|
||||
|
||||
// Determine the source ID depending on whether it's a bulk operation.
|
||||
@@ -351,15 +351,13 @@ class Create extends Action
|
||||
// Assign a unique ID if needed, otherwise use the provided ID.
|
||||
$document['$id'] = $sourceId === 'unique()' ? ID::unique() : $sourceId;
|
||||
|
||||
// Allowing to add createdAt and updatedAt timestamps if server side(api key)
|
||||
$createdAt = $document['$createdAt'] ?? null;
|
||||
$updatedAt = $document['$updatedAt'] ?? null;
|
||||
if (!$isAPIKey) {
|
||||
if ($createdAt !== null) {
|
||||
// Allowing to add createdAt and updatedAt timestamps if server side(api key
|
||||
if (!$isAPIKey && !$isPrivilegedUser) {
|
||||
if (isset($document['$createdAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$createdAt" is not allowed');
|
||||
}
|
||||
|
||||
if ($updatedAt !== null) {
|
||||
if (isset($document['$updatedAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$updatedAt" is not allowed');
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -110,14 +110,12 @@ class Update extends Action
|
||||
}
|
||||
|
||||
// Allowing to add createdAt and updatedAt timestamps if server side(api key)
|
||||
$createdAt = $data['$createdAt'] ?? null;
|
||||
$updatedAt = $data['$updatedAt'] ?? null;
|
||||
if (!$isAPIKey) {
|
||||
if ($createdAt !== null) {
|
||||
if (!$isAPIKey && !$isPrivilegedUser) {
|
||||
if (isset($data['$createdAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$createdAt" is not allowed');
|
||||
}
|
||||
|
||||
if ($updatedAt !== null) {
|
||||
if (isset($data['$updatedAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$updatedAt" is not allowed');
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -154,14 +154,12 @@ class Upsert extends Action
|
||||
}
|
||||
}
|
||||
// Allowing to add createdAt and updatedAt timestamps if server side(api key)
|
||||
$createdAt = $data['$createdAt'] ?? null;
|
||||
$updatedAt = $data['$updatedAt'] ?? null;
|
||||
if (!$isAPIKey) {
|
||||
if ($createdAt !== null) {
|
||||
if (!$isAPIKey && !$isPrivilegedUser) {
|
||||
if (isset($data['$createdAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$createdAt" is not allowed');
|
||||
}
|
||||
|
||||
if ($updatedAt !== null) {
|
||||
if (isset($data['$updatedAt'])) {
|
||||
throw new Exception($this->getInvalidStructureException(), 'Attribute "$updatedAt" is not allowed');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user