mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 06:15:20 +00:00
fix(security): gate AI tools by user ability and block admin-URL SSRF
The AI chat assistant scoped tool queries by company but ignored the per-user Bouncer abilities the rest of the app enforces, so any `use ai` holder could read customers, invoices, payments, and company financials their role couldn't otherwise see. Each AiTool now declares a required ability (entity-aligned); the registry hides unauthorized tools from the model and refuses to execute them as a backstop. Separately, admin/owner-supplied URLs were fetched server-side with no guard against private/reserved targets (SSRF): the AI base URL, the CurrencyConverter "DEDICATED" exchange-rate URL, and S3/Spaces file-disk endpoints. A shared PrivateNetworkGuard now backs a PublicHttpUrl validation rule (save-time) and runtime guards in each driver. - AiTool::requiredAbility() + mapping across all 12 tools - AiToolRegistry filters schemas() by ability and re-checks in execute() - PrivateNetworkGuard / BlockedUrlException / PublicHttpUrl rule (new) - Rule wired into AI config (service + 3 controllers), exchange-rate, and file-disk endpoints; runtime guards in OpenRouterDriver, CurrencyConverterDriver, and FileDiskService - Tests for ability filtering, the guard, the rule, and 422 rejections
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Rules\PublicHttpUrl;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ExchangeRateProviderRequest extends FormRequest
|
||||
@@ -35,6 +36,14 @@ class ExchangeRateProviderRequest extends FormRequest
|
||||
'driver_config' => [
|
||||
'nullable',
|
||||
],
|
||||
// Only the CurrencyConverter "DEDICATED" plan reads a custom URL from
|
||||
// driver_config; guard it against SSRF (private/reserved targets).
|
||||
'driver_config.url' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'url',
|
||||
new PublicHttpUrl,
|
||||
],
|
||||
'active' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
|
||||
Reference in New Issue
Block a user