From 990331cd7401c6295552dd1fa7e6211c022af6e6 Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Mon, 25 Aug 2025 09:31:31 +0200
Subject: [PATCH] feat(validation): add ValidIpOrCidr rule for validating IP
addresses and CIDR notations; update API access settings UI and add
comprehensive tests
---
app/Rules/ValidIpOrCidr.php | 63 ++++++
.../livewire/settings/advanced.blade.php | 4 +-
tests/Feature/IpAllowlistTest.php | 183 ++++++++++++++++++
3 files changed, 248 insertions(+), 2 deletions(-)
create mode 100644 app/Rules/ValidIpOrCidr.php
create mode 100644 tests/Feature/IpAllowlistTest.php
diff --git a/app/Rules/ValidIpOrCidr.php b/app/Rules/ValidIpOrCidr.php
new file mode 100644
index 000000000..e172ffd1a
--- /dev/null
+++ b/app/Rules/ValidIpOrCidr.php
@@ -0,0 +1,63 @@
+ 32) {
+ $invalidEntries[] = $entry;
+ }
+ } else {
+ // Check if it's a valid IP
+ if (! filter_var($entry, FILTER_VALIDATE_IP)) {
+ $invalidEntries[] = $entry;
+ }
+ }
+ }
+
+ if (! empty($invalidEntries)) {
+ $fail('The following entries are not valid IP addresses or CIDR notations: '.implode(', ', $invalidEntries));
+ }
+ }
+}
diff --git a/resources/views/livewire/settings/advanced.blade.php b/resources/views/livewire/settings/advanced.blade.php
index 6f7e5c867..b68370a09 100644
--- a/resources/views/livewire/settings/advanced.blade.php
+++ b/resources/views/livewire/settings/advanced.blade.php
@@ -32,8 +32,8 @@
Supports single IPs (192.168.1.100) and CIDR notation (192.168.1.0/24).
Use comma to separate multiple entries.
Use 0.0.0.0 or leave empty to allow from anywhere."
+ placeholder="192.168.1.100,10.0.0.0/8,203.0.113.0/24" />