Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

feat: Add environment variable to bypass NoInternalIP rule for specific webhook hosts (#1122)

Nils Z.65e0e4ea0e28
diff --git a/backend/.env.example b/backend/.env.example
index 12971f17a..c5ee655b3 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -13,6 +13,7 @@ APP_HOMEPAGE_VIEWS_UPDATE_BATCH_SIZE=8
APP_DISABLE_REGISTRATION=false
APP_STRIPE_CONNECT_ACCOUNT_TYPE=express
+APP_ALLOWED_INTERNAL_WEBHOOK_HOSTS=
STRIPE_PUBLIC_KEY=
STRIPE_SECRET_KEY=
diff --git a/backend/app/Validators/Rules/NoInternalUrlRule.php b/backend/app/Validators/Rules/NoInternalUrlRule.php
index 5e3360ef8..a24c1df23 100644
--- a/backend/app/Validators/Rules/NoInternalUrlRule.php
+++ b/backend/app/Validators/Rules/NoInternalUrlRule.php
@@ -4,6 +4,7 @@ namespace HiEvents\Validators\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
+use Illuminate\Support\Facades\Config;
class NoInternalUrlRule implements ValidationRule
{
@@ -52,6 +53,11 @@ class NoInternalUrlRule implements ValidationRule
$host = substr($host, 1, -1);
}
+ // Handle NoInternalIP/Host Exceptions
+ if ($this->isWhitelistedHost($host)) {
+ return;
+ }
+
if ($this->isBlockedHost($host)) {
$fail(__('The :attribute cannot point to localhost or internal addresses.'));
return;
@@ -145,4 +151,16 @@ class NoInternalUrlRule implements ValidationRule
return $ip;
}
-}
+
+ private function isWhitelistedHost(string $host): bool
+ {
+ $whitelistedHosts = Config::string('app.allowed_internal_webhook_hosts');
+ if (!empty($whitelistedHosts)) {
+ $allowedList = array_filter(array_map('trim', explode(',', $whitelistedHosts)));
+ if (in_array($host, $allowedList) || in_array(gethostbyname($host), $allowedList)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/backend/config/app.php b/backend/config/app.php
index f5c6bcbaa..50bcabc3e 100644
--- a/backend/config/app.php
+++ b/backend/config/app.php
@@ -22,6 +22,7 @@ return [
'stripe_connect_account_type' => env('APP_STRIPE_CONNECT_ACCOUNT_TYPE', 'express'),
'platform_support_email' => env('APP_PLATFORM_SUPPORT_EMAIL', '[email protected]'),
'enforce_email_confirmation_during_registration' => env('APP_ENFORCE_EMAIL_CONFIRMATION_DURING_REGISTRATION', false),
+ 'allowed_internal_webhook_hosts' => env('APP_ALLOWED_INTERNAL_WEBHOOK_HOSTS', ''),
/**
* The number of page views to batch before updating the database