fix(security): Pods-Feldrechte fail-closed
Fehlt pods_has_permissions() oder pods_permission(), gilt kein Pods-Feld mehr als unbeschränkt, sondern als nicht erlaubt (HIDDEN/READONLY). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
29e73caefb
commit
8f3a4e76eb
+4
-3
@@ -50,11 +50,12 @@ final class PodsFieldSource implements FieldSource
|
|||||||
$this->loadPod = $loadPod ?? static fn (string $name): mixed => pods_api()->load_pod(['name' => $name]);
|
$this->loadPod = $loadPod ?? static fn (string $name): mixed => pods_api()->load_pod(['name' => $name]);
|
||||||
$this->podFor = $podFor ?? static fn (string $name, int $id): mixed => pods($name, $id);
|
$this->podFor = $podFor ?? static fn (string $name, int $id): mixed => pods($name, $id);
|
||||||
$this->permitted = $permitted ?? static function (object $field): ?bool {
|
$this->permitted = $permitted ?? static function (object $field): ?bool {
|
||||||
if (! function_exists('pods_has_permissions') || ! pods_has_permissions($field)) {
|
// Fail closed: without the Pods permission API no field counts as permitted.
|
||||||
return null;
|
if (! function_exists('pods_has_permissions') || ! function_exists('pods_permission')) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return function_exists('pods_permission') && (bool) pods_permission($field);
|
return pods_has_permissions($field) ? (bool) pods_permission($field) : null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -32,7 +32,7 @@ final class PodsFieldSourceTest extends TestCase
|
|||||||
|
|
||||||
private function source(?object $pod): PodsFieldSource
|
private function source(?object $pod): PodsFieldSource
|
||||||
{
|
{
|
||||||
return new PodsFieldSource(static fn (string $name) => $pod ?? false);
|
return new PodsFieldSource(static fn (string $name) => $pod ?? false, null, static fn (object $field): ?bool => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, array<string, mixed>> */
|
/** @return array<string, array<string, mixed>> */
|
||||||
@@ -79,6 +79,19 @@ final class PodsFieldSourceTest extends TestCase
|
|||||||
self::assertSame(FieldDefinition::UNKNOWN, $fields['mystery']['status']);
|
self::assertSame(FieldDefinition::UNKNOWN, $fields['mystery']['status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fail-closed: without the Pods permission functions (not loaded in the unit run) no field counts as permitted. */
|
||||||
|
public function testFieldIsHiddenWhenThePodsPermissionFunctionsAreMissing(): void
|
||||||
|
{
|
||||||
|
self::assertFalse(function_exists('pods_has_permissions'));
|
||||||
|
$pod = Mockery::mock();
|
||||||
|
$pod->allows('get_type')->andReturn('post_type');
|
||||||
|
$pod->allows('get_fields')->andReturn(['role' => $this->field('role', 'text')]);
|
||||||
|
|
||||||
|
$fields = (new PodsFieldSource(static fn (string $name) => $pod))->fieldsFor('lit_person');
|
||||||
|
|
||||||
|
self::assertSame(FieldDefinition::HIDDEN, $fields[0]->status);
|
||||||
|
}
|
||||||
|
|
||||||
public function testParsesCustomSimpleChoices(): void
|
public function testParsesCustomSimpleChoices(): void
|
||||||
{
|
{
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
|
|||||||
Reference in New Issue
Block a user