Skip to content

A free open source IT asset/license management system

Clear existing unsafe settings, added config setting for allowing internal

snipe7519fa1cfe96
diff --git a/app/Livewire/SlackSettingsForm.php b/app/Livewire/SlackSettingsForm.php
index eae28ee061..1462eaf4cd 100644
--- a/app/Livewire/SlackSettingsForm.php
+++ b/app/Livewire/SlackSettingsForm.php
@@ -352,9 +352,13 @@ class SlackSettingsForm extends Component
/**
* Uniform failure path for outbound webhook tests. The exception message
- * is logged server-side but never reflected into the UI, because Guzzle
- * error strings leak connect-refused / timeout / DNS details that turn
- * this feature into a port-scanning oracle for internal hosts.
+ * used to be a port-scanning oracle back when the endpoint field accepted
+ * internal URLs; now that the ExternalUrl rule rejects those before we
+ * ever dial anything, the connect-level error can only describe an
+ * external host the admin explicitly typed, so we surface it back into
+ * the flash. Full exception context still lands in the log for audit
+ * and for cases where the flash message is too short to be useful (SSL
+ * chain problems, proxy failures, etc.).
*/
private function handleWebhookFailure(\Throwable $e)
{
@@ -363,13 +367,15 @@ class SlackSettingsForm extends Component
'app' => $this->webhook_name,
'exception' => $e::class,
'message' => $e->getMessage(),
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine(),
]);
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
return session()->flash('error', trans('admin/settings/message.webhook.error', [
- 'error_message' => trans('admin/settings/message.webhook.error_misc'),
+ 'error_message' => $e->getMessage(),
'app' => $this->webhook_name,
]));
}
diff --git a/app/Rules/ExternalUrl.php b/app/Rules/ExternalUrl.php
index 23638dc9b2..54fe5d2bb3 100644
--- a/app/Rules/ExternalUrl.php
+++ b/app/Rules/ExternalUrl.php
@@ -44,6 +44,13 @@ class ExternalUrl implements ValidationRule
return;
}
+ // Operators who legitimately need to point at an on-LAN webhook
+ // receiver flip WEBHOOK_ALLOW_INTERNAL_TARGETS in .env. Scheme
+ // restrictions above still apply; only the IP-range check is skipped.
+ if (config('app.webhook_allow_internal_targets')) {
+ return;
+ }
+
$host = $parts['host'];
if (str_starts_with($host, '[') && str_ends_with($host, ']')) {
@@ -89,25 +96,31 @@ class ExternalUrl implements ValidationRule
{
$ips = [];
- $records = @dns_get_record($host, DNS_A + DNS_AAAA);
- if (is_array($records)) {
- foreach ($records as $r) {
- if (! empty($r['ip'])) {
- $ips[] = $r['ip'];
- }
- if (! empty($r['ipv6'])) {
- $ips[] = $r['ipv6'];
- }
+ // gethostbynamel goes through nsswitch (/etc/hosts, mDNS, DNS) —
+ // the same lookup path the outbound HTTP client will use. dns_get_record
+ // alone is a pure DNS query that ignores /etc/hosts and may apply
+ // search suffixes, which would let "localhost" resolve to a public IP
+ // under "localhost.<search-domain>" and slip past the check.
+ $v4 = @gethostbynamel($host);
+ if (is_array($v4)) {
+ foreach ($v4 as $ip) {
+ $ips[] = $ip;
}
}
- if ($ips === []) {
- $resolved = @gethostbyname($host);
- if ($resolved !== $host && filter_var($resolved, FILTER_VALIDATE_IP)) {
- $ips[] = $resolved;
+ // There is no stdlib nsswitch equivalent for IPv6, so this leg is
+ // best-effort DNS. The IPv4 leg above already catches the common
+ // "localhost" / hosts-file cases, so a missed AAAA record here
+ // can't silently pass a name we would have otherwise rejected.
+ $v6 = @dns_get_record($host, DNS_AAAA);
+ if (is_array($v6)) {
+ foreach ($v6 as $r) {
+ if (! empty($r['ipv6'])) {
+ $ips[] = $r['ipv6'];
+ }
}
}
- return $ips;
+ return array_values(array_unique($ips));
}
}
diff --git a/config/app.php b/config/app.php
index 30a105ece5..6bef5896c7 100755
--- a/config/app.php
+++ b/config/app.php
@@ -234,6 +234,26 @@ return [
/*
|--------------------------------------------------------------------------
+ | ALLOW INTERNAL WEBHOOK TARGETS
+ |--------------------------------------------------------------------------
+ |
+ | By default the webhook endpoint validator refuses URLs that resolve to
+ | loopback, link-local, RFC-1918, or otherwise-non-public IPs. This
+ | prevents a super-admin (or someone who has taken over a super-admin
+ | account) from turning the outbound notification path into an SSRF
+ | primitive against internal services or cloud metadata endpoints.
+ |
+ | Some operators legitimately run their own webhook receiver on the same
+ | private network as Snipe-IT (self-hosted Mattermost, Rocket.Chat, an
+ | internal ChatOps bot, etc.). Setting this to true re-enables outbound
+ | requests to those addresses. Scheme restrictions (http/https only) are
+ | still enforced. Leave this off unless you know you need it.
+ |
+ */
+ 'webhook_allow_internal_targets' => env('WEBHOOK_ALLOW_INTERNAL_TARGETS', false),
+
+ /*
+ |--------------------------------------------------------------------------
| LOG AUTHED USER HEADER
|--------------------------------------------------------------------------
|
diff --git a/database/migrations/2026_07_01_000001_clear_unsafe_webhook_endpoints.php b/database/migrations/2026_07_01_000001_clear_unsafe_webhook_endpoints.php
new file mode 100644
index 0000000000..c7ba03c632
--- /dev/null
+++ b/database/migrations/2026_07_01_000001_clear_unsafe_webhook_endpoints.php
@@ -0,0 +1,53 @@
+<?php
+
+use App\Rules\ExternalUrl;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Validator;
+
+return new class extends Migration
+{
+ public function up(): void
+ {
+ // The webhook endpoint used to accept ftp:// and irc:// schemes and did
+ // no host validation at all, so upgrading instances may already have a
+ // value pointing at loopback, RFC-1918, or a metadata service. The new
+ // ExternalUrl rule blocks new saves in that shape, but the runtime
+ // notification senders read the stored value directly on every checkout
+ // / checkin, so a bad value sitting in the DB stays exploitable until
+ // it's cleared. This migration walks the settings rows once and blanks
+ // anything the rule rejects, logging the previous value so an operator
+ // who was intentionally pointing at an internal receiver can see what
+ // was removed and put it back through a reverse proxy if they want.
+ $rows = DB::table('settings')
+ ->whereNotNull('webhook_endpoint')
+ ->where('webhook_endpoint', '!=', '')
+ ->get(['id', 'webhook_endpoint']);
+
+ foreach ($rows as $row) {
+ $fails = Validator::make(
+ ['webhook_endpoint' => $row->webhook_endpoint],
+ ['webhook_endpoint' => [new ExternalUrl]],
+ )->fails();
+
+ if (! $fails) {
+ continue;
+ }
+
+ Log::warning('Clearing unsafe webhook_endpoint during migration', [
+ 'settings_id' => $row->id,
+ 'previous_endpoint' => $row->webhook_endpoint,
+ ]);
+
+ DB::table('settings')
+ ->where('id', $row->id)
+ ->update(['webhook_endpoint' => null]);
+ }
+ }
+
+ public function down(): void
+ {
+ // No-op: cleared endpoints are logged during up(); we can't restore them.
+ }
+};
diff --git a/tests/Unit/Rules/ExternalUrlTest.php b/tests/Unit/Rules/ExternalUrlTest.php
index de68702e6c..67aac9f83c 100644
--- a/tests/Unit/Rules/ExternalUrlTest.php
+++ b/tests/Unit/Rules/ExternalUrlTest.php
@@ -55,7 +55,6 @@ class ExternalUrlTest extends TestCase
'v4-mapped rfc1918' => ['http://[::ffff:10.0.0.1]/'],
// Malformed.
- 'empty' => [''],
'no scheme' => ['example.com'],
'no host' => ['http:///'],
];
@@ -79,4 +78,25 @@ class ExternalUrlTest extends TestCase
{
$this->assertTrue($this->passes('http://[2606:2800:220:1:248:1893:25c8:1946]/'));
}
+
+ public function test_internal_targets_pass_when_escape_hatch_is_enabled()
+ {
+ config(['app.webhook_allow_internal_targets' => true]);
+
+ $this->assertTrue($this->passes('http://127.0.0.1/hook'));
+ $this->assertTrue($this->passes('http://10.0.0.1/hook'));
+ $this->assertTrue($this->passes('http://192.168.1.50:8080/hook'));
+ $this->assertTrue($this->passes('http://169.254.169.254/'));
+ $this->assertTrue($this->passes('http://[::1]/hook'));
+ }
+
+ public function test_escape_hatch_still_blocks_non_http_schemes()
+ {
+ config(['app.webhook_allow_internal_targets' => true]);
+
+ $this->assertFalse($this->passes('ftp://example.com/'));
+ $this->assertFalse($this->passes('irc://example.com/'));
+ $this->assertFalse($this->passes('javascript:alert(1)'));
+ $this->assertFalse($this->passes('file:///etc/passwd'));
+ }
}