Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

add SSRF_ALLOWLIST environment variable (#1123)

Jonathan Rehmde59c1e6c6c0
diff --git a/README.md b/README.md
index d2660f7..77972c3 100644
--- a/README.md
+++ b/README.md
@@ -247,6 +247,12 @@ If `OIDC_ISSUER` is set, Wallos will fetch `/.well-known/openid-configuration` a
| `OIDC_DISABLE_PASSWORD_LOGIN` | `Disable password login` |
| `OIDC_REQUIRE_EMAIL_VERIFIED` | `Require verified email for account linking` |
+### SSRF allowlist
+
+Wallos blocks webhook, SMTP, and OIDC endpoint URLs that resolve to private/link-local/loopback addresses unless the host is present in the Security Settings allowlist. Normally that allowlist is edited through the Admin UI, which requires a manual login before OIDC can be used against an identity provider on a private address (e.g. a self-hosted IdP at `auth.example.com`).
+
+Setting the `SSRF_ALLOWLIST` environment variable overrides the database value entirely (same full-override semantics as the `OIDC_*` variables above), so the allowlist can be provisioned on first boot with no manual UI step. It accepts a comma-separated list of hosts/IPs, optionally with a port (e.g. `SSRF_ALLOWLIST=auth.example.com,192.168.1.100:8123`). While set, the Security Settings field in the Admin UI is shown but disabled.
+
## API Documentation
Wallos provides a comprehensive API that allows you to interact with the application programmatically. The API documentation is available at [https://api.wallosapp.com/](https://api.wallosapp.com/).
diff --git a/admin.php b/admin.php
index 60350fa..46e5137 100644
--- a/admin.php
+++ b/admin.php
@@ -1,6 +1,7 @@
<?php
require_once 'includes/header.php';
require_once 'includes/oidc_settings.php';
+require_once 'includes/ssrf_helper.php';
if ($isAdmin != 1) {
header('Location: index.php');
@@ -17,6 +18,9 @@ $oidcSettings = $oidcConfiguration['settings'];
$oidcManagedFields = $oidcConfiguration['managed_fields'];
$oidcNotes = $oidcConfiguration['notes'];
+$ssrfConfiguration = wallos_get_effective_ssrf_allowlist($db);
+$ssrfManagedFields = $ssrfConfiguration['is_managed'] ? ['allowlist' => 'SSRF_ALLOWLIST'] : [];
+
function oidc_input_attrs($field, $managedFields)
{
return isset($managedFields[$field]) ? 'disabled data-managed-by="' . htmlspecialchars($managedFields[$field]) . '"' : '';
@@ -355,23 +359,29 @@ $loginDisabledAllowed = $userCount == 1 && $settings['registrations_open'] == 0;
<div class="admin-form">
<div class="form-group-inline">
<input type="text" name="local_webhook_notifications_allowlist" id="local_webhook_notifications_allowlist" autocomplete="off"
- placeholder="e.g., 192.168.1.5:8123, homeassistant.local" value="<?= htmlspecialchars($settings['local_webhook_notifications_allowlist'] ?? '', ENT_QUOTES, 'UTF-8') ?>" />
+ placeholder="e.g., 192.168.1.5:8123, homeassistant.local" value="<?= htmlspecialchars($ssrfConfiguration['raw'], ENT_QUOTES, 'UTF-8') ?>" <?= oidc_input_attrs('allowlist', $ssrfManagedFields) ?> />
</div>
-
+
<div class="buttons">
<input type="submit" class="thin mobile-grow" value="<?= translate('save', $i18n) ?>"
id="saveSecuritySettingsButton" onClick="saveSecuritySettingsButton()" />
</div>
-
+
<div class="settings-notes">
<p>
- <i class="fa-solid fa-circle-info"></i>
+ <i class="fa-solid fa-circle-info"></i>
<?= translate('ssrf_protection_info', $i18n) ?>
</p>
<p>
<i class="fa-solid fa-circle-info"></i>
<?= translate('local_webhook_info', $i18n) ?>
</p>
+ <?php if ($ssrfConfiguration['is_managed']): ?>
+ <p>
+ <i class="fa-solid fa-circle-info"></i>
+ <?= translate('ssrf_allowlist_env_managed', $i18n) ?>
+ </p>
+ <?php endif; ?>
</div>
</div>
</section>
diff --git a/api/admin/set_admin_settings.php b/api/admin/set_admin_settings.php
index 2f5ab3e..9215f18 100644
--- a/api/admin/set_admin_settings.php
+++ b/api/admin/set_admin_settings.php
@@ -181,6 +181,10 @@ $columnsMap = [
'local_webhook_notifications_allowlist' => SQLITE3_TEXT
];
+if (wallos_get_effective_ssrf_allowlist($db)['is_managed']) {
+ unset($columnsMap['local_webhook_notifications_allowlist']);
+}
+
foreach ($columnsMap as $postKey => $dataType) {
if (isset($_POST[$postKey])) {
$fields[] = "$postKey = :$postKey";
diff --git a/endpoints/admin/savesecuritysettings.php b/endpoints/admin/savesecuritysettings.php
index f3635b4..22cf751 100644
--- a/endpoints/admin/savesecuritysettings.php
+++ b/endpoints/admin/savesecuritysettings.php
@@ -2,6 +2,7 @@
require_once '../../includes/connect_endpoint.php';
require_once '../../includes/validate_endpoint_admin.php';
+require_once '../../includes/ssrf_helper.php';
$postData = file_get_contents("php://input");
$data = json_decode($postData, true);
@@ -14,6 +15,14 @@ if (!isset($data['local_webhook_notifications_allowlist'])) {
die();
}
+if (wallos_get_effective_ssrf_allowlist($db)['is_managed']) {
+ echo json_encode([
+ "success" => false,
+ "message" => translate('ssrf_allowlist_env_managed', $i18n)
+ ]);
+ die();
+}
+
// Basic cleanup: trim whitespace and strip any accidental HTML tags
$allowlist = trim(strip_tags($data['local_webhook_notifications_allowlist']));
diff --git a/includes/i18n/en.php b/includes/i18n/en.php
index 0615392..c8c6df0 100644
--- a/includes/i18n/en.php
+++ b/includes/i18n/en.php
@@ -444,6 +444,7 @@ $i18n = [
"security_settings" => "Security Settings",
"ssrf_protection_info" => "To prevent Server-Side Request Forgery (SSRF) attacks, Wallos blocks webhook notifications to private or internal network addresses by default.",
"local_webhook_info" => "If you need to send webhooks to local services (like Home Assistant, Gotify, or Node-RED), enter their IP addresses or hostnames above as a comma-separated list (e.g., <code>192.168.1.100,192.168.1.101</code>).",
+ "ssrf_allowlist_env_managed" => "Managed by the SSRF_ALLOWLIST environment variable.",
"maintenance_tasks" => "Maintenance Tasks",
"orphaned_logos" => "Orphaned Logos",
"update" => "Update",
diff --git a/includes/ssrf_helper.php b/includes/ssrf_helper.php
index 2457cef..cdf4821 100644
--- a/includes/ssrf_helper.php
+++ b/includes/ssrf_helper.php
@@ -1,5 +1,51 @@
<?php
+function wallos_get_ssrf_allowlist_env_value()
+{
+ $value = getenv('SSRF_ALLOWLIST');
+ if ($value !== false) {
+ return $value;
+ }
+
+ if (array_key_exists('SSRF_ALLOWLIST', $_ENV)) {
+ return $_ENV['SSRF_ALLOWLIST'];
+ }
+
+ if (array_key_exists('SSRF_ALLOWLIST', $_SERVER)) {
+ return $_SERVER['SSRF_ALLOWLIST'];
+ }
+
+ return null;
+}
+
+/**
+ * Returns the effective SSRF allowlist: SSRF_ALLOWLIST env var if set (full
+ * override, same semantics as the OIDC_* env vars), otherwise the DB-stored
+ * local_webhook_notifications_allowlist value.
+ *
+ * @param SQLite3 $db
+ * @return array{allowlist: string[], raw: string, is_managed: bool}
+ */
+function wallos_get_effective_ssrf_allowlist($db)
+{
+ $stmt = $db->prepare('SELECT local_webhook_notifications_allowlist FROM admin LIMIT 1');
+ $result = $stmt->execute();
+ $row = $result ? $result->fetchArray(SQLITE3_ASSOC) : false;
+ $dbValue = $row ? $row['local_webhook_notifications_allowlist'] : '';
+
+ $envValue = wallos_get_ssrf_allowlist_env_value();
+ $isManaged = $envValue !== null && trim((string) $envValue) !== '';
+ $rawValue = $isManaged ? $envValue : $dbValue;
+
+ $allowlist = array_filter(array_map('trim', explode(',', (string) $rawValue)));
+
+ return [
+ 'allowlist' => $allowlist,
+ 'raw' => (string) $rawValue,
+ 'is_managed' => $isManaged,
+ ];
+}
+
/**
* Checks if an IP falls in the RFC 6598 Carrier-Grade NAT range (100.64.0.0/10).
* PHP's FILTER_FLAG_NO_PRIV_RANGE does not cover this range.
@@ -62,18 +108,13 @@ function validate_webhook_url_for_ssrf($url, $db, $i18n, $userId = null) {
]));
}
- $stmt = $db->prepare("SELECT local_webhook_notifications_allowlist FROM admin LIMIT 1");
- $result = $stmt->execute();
- $row = $result->fetchArray(SQLITE3_ASSOC);
-
- $allowlist_str = $row ? $row['local_webhook_notifications_allowlist'] : '';
- $allowlist = array_filter(array_map('trim', explode(',', $allowlist_str)));
-
- if (!in_array($urlHost, $allowlist) &&
- !in_array($ip, $allowlist) &&
- !in_array($hostWithPort, $allowlist) &&
+ $allowlist = wallos_get_effective_ssrf_allowlist($db)['allowlist'];
+
+ if (!in_array($urlHost, $allowlist) &&
+ !in_array($ip, $allowlist) &&
+ !in_array($hostWithPort, $allowlist) &&
!in_array($ipWithPort, $allowlist)) {
-
+
die(json_encode([
"success" => false,
"message" => "Security Block: The target IP/Port is private and not present in the Webhook Allowlist."
@@ -111,12 +152,7 @@ function validate_smtp_host($host, $port, $db) {
|| is_cgnat_ip($ip);
if ($is_private) {
- $stmt = $db->prepare("SELECT local_webhook_notifications_allowlist FROM admin LIMIT 1");
- $result = $stmt->execute();
- $row = $result->fetchArray(SQLITE3_ASSOC);
-
- $allowlist_str = $row ? $row['local_webhook_notifications_allowlist'] : '';
- $allowlist = array_filter(array_map('trim', explode(',', $allowlist_str)));
+ $allowlist = wallos_get_effective_ssrf_allowlist($db)['allowlist'];
$hostWithPort = $host . ':' . $port;
$ipWithPort = $ip . ':' . $port;
@@ -163,12 +199,7 @@ function validate_oidc_endpoint_url($url, $db) {
|| is_cgnat_ip($ip);
if ($is_private) {
- $stmt = $db->prepare("SELECT local_webhook_notifications_allowlist FROM admin LIMIT 1");
- $result = $stmt->execute();
- $row = $result->fetchArray(SQLITE3_ASSOC);
-
- $allowlist_str = $row ? $row['local_webhook_notifications_allowlist'] : '';
- $allowlist = array_filter(array_map('trim', explode(',', $allowlist_str)));
+ $allowlist = wallos_get_effective_ssrf_allowlist($db)['allowlist'];
$hostWithPort = $host . ':' . $targetPort;
$ipWithPort = $ip . ':' . $targetPort;
@@ -225,12 +256,7 @@ function is_url_safe_for_ssrf($url, $db, $userId = null) {
return false; // private and user is not admin — skip silently
}
- $stmt = $db->prepare("SELECT local_webhook_notifications_allowlist FROM admin LIMIT 1");
- $result = $stmt->execute();
- $row = $result->fetchArray(SQLITE3_ASSOC);
-
- $allowlist_str = $row ? $row['local_webhook_notifications_allowlist'] : '';
- $allowlist = array_filter(array_map('trim', explode(',', $allowlist_str)));
+ $allowlist = wallos_get_effective_ssrf_allowlist($db)['allowlist'];
if (
!in_array($urlHost, $allowlist) &&