Skip to content

Commit 71e6d2e

Browse files
committed
Fixes potential for accidental update/deletion of edited model
1 parent 65a91ba commit 71e6d2e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/Models/Server.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,21 @@ public static function getByUUID($uuid)
122122

123123
$result = $query->first();
124124

125-
// @TODO: saving after calling this could end up resetting the daemon secret.
126-
// We probably need to just allow access to self::getUserDaemonSecret() to
127-
// get this result.
128125
if(!is_null($result)) {
129126
$result->daemonSecret = self::getUserDaemonSecret($result);
130127
}
131128

129+
// Prevent saving of model called in this manner.
130+
// Prevents accidental overwrite of main daemon secret.
131+
$result::saving(function () {
132+
return false;
133+
});
134+
135+
// Prevent deleting this model call.
136+
$result::deleting(function () {
137+
return false;
138+
});
139+
132140
self::$serverUUIDInstance[$uuid] = $result;
133141
return self::$serverUUIDInstance[$uuid];
134142

0 commit comments

Comments
 (0)