fix: a few inputs

This commit is contained in:
Andras Bacsai
2024-12-02 22:49:41 +01:00
parent 7f449c3b72
commit 58988d3686
10 changed files with 190 additions and 102 deletions

View File

@@ -179,7 +179,7 @@ class GetContainersStatus
})->first(); })->first();
if (! $foundTcpProxy) { if (! $foundTcpProxy) {
StartDatabaseProxy::run($database); StartDatabaseProxy::run($database);
// $this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server)); // $this->server->team?->notify(new ContainerRestarted("TCP Proxy for database", $this->server));
} }
} }
} else { } else {

View File

@@ -51,7 +51,6 @@ class ServerCheck
$containerReplicates = null; $containerReplicates = null;
$this->isSentinel = true; $this->isSentinel = true;
} else { } else {
['containers' => $this->containers, 'containerReplicates' => $containerReplicates] = $this->server->getContainers(); ['containers' => $this->containers, 'containerReplicates' => $containerReplicates] = $this->server->getContainers();
// ServerStorageCheckJob::dispatch($this->server); // ServerStorageCheckJob::dispatch($this->server);
@@ -148,7 +147,6 @@ class ServerCheck
} else { } else {
$labels = Arr::undot(data_get($container, 'Config.Labels')); $labels = Arr::undot(data_get($container, 'Config.Labels'));
} }
} }
$managed = data_get($labels, 'coolify.managed'); $managed = data_get($labels, 'coolify.managed');
if (! $managed) { if (! $managed) {
@@ -259,7 +257,7 @@ class ServerCheck
})->first(); })->first();
if (! $foundTcpProxy) { if (! $foundTcpProxy) {
StartDatabaseProxy::run($database); StartDatabaseProxy::run($database);
// $this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server)); // $this->server->team?->notify(new ContainerRestarted("TCP Proxy for database", $this->server));
} }
} }
} }

View File

@@ -1591,16 +1591,32 @@ class ApplicationsController extends Controller
} }
$domains = $request->domains; $domains = $request->domains;
if ($request->has('domains') && $server->isProxyShouldRun()) { if ($request->has('domains') && $server->isProxyShouldRun()) {
$errors = []; $uuid = $request->uuid;
$fqdn = $request->domains; $fqdn = $request->domains;
$fqdn = str($fqdn)->replaceEnd(',', '')->trim(); $fqdn = str($fqdn)->replaceEnd(',', '')->trim();
$fqdn = str($fqdn)->replaceStart(',', '')->trim(); $fqdn = str($fqdn)->replaceStart(',', '')->trim();
$application->fqdn = $fqdn; $errors = [];
if (! $application->settings->is_container_label_readonly_enabled) { $fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
$customLabels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n"); $domain = trim($domain);
$application->custom_labels = base64_encode($customLabels); if (filter_var($domain, FILTER_VALIDATE_URL) === false || !preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}/', $domain)) {
$errors[] = 'Invalid domain: '.$domain;
}
return $domain;
});
if (count($errors) > 0) {
return response()->json([
'message' => 'Validation failed.',
'errors' => $errors,
], 422);
}
if (checkIfDomainIsAlreadyUsed($fqdn, $teamId, $uuid)) {
return response()->json([
'message' => 'Validation failed.',
'errors' => [
'domains' => 'One of the domain is already used.',
],
], 422);
} }
$request->offsetUnset('domains');
} }
$dockerComposeDomainsJson = collect(); $dockerComposeDomainsJson = collect();
@@ -2811,3 +2827,30 @@ class ApplicationsController extends Controller
} }
} }
} }
$fqdn = str($fqdn)->replaceStart(',', '')->trim();
$errors = [];
$fqdn = str($fqdn)->trim()->explode(',')->map(function ($domain) use (&$errors) {
if (filter_var($domain, FILTER_VALIDATE_URL) === false) {
$errors[] = 'Invalid domain: ' . $domain;
}
return str($domain)->trim()->lower();
});
if (count($errors) > 0) {
return response()->json([
'message' => 'Validation failed.',
'errors' => $errors,
], 422);
}
if (checkIfDomainIsAlreadyUsed($fqdn, $teamId, $uuid)) {
return response()->json([
'message' => 'Validation failed.',
'errors' => [
'domains' => 'One of the domain is already used.',
],
], 422);
}
}
}
}

View File

@@ -1557,7 +1557,8 @@ class DatabasesController extends Controller
] ]
) )
), ),
]), ]
),
new OA\Response( new OA\Response(
response: 401, response: 401,
ref: '#/components/responses/401', ref: '#/components/responses/401',
@@ -1632,9 +1633,11 @@ class DatabasesController extends Controller
type: 'object', type: 'object',
properties: [ properties: [
'message' => ['type' => 'string', 'example' => 'Database starting request queued.'], 'message' => ['type' => 'string', 'example' => 'Database starting request queued.'],
]) ]
)
),
]
), ),
]),
new OA\Response( new OA\Response(
response: 401, response: 401,
ref: '#/components/responses/401', ref: '#/components/responses/401',
@@ -1708,9 +1711,11 @@ class DatabasesController extends Controller
type: 'object', type: 'object',
properties: [ properties: [
'message' => ['type' => 'string', 'example' => 'Database stopping request queued.'], 'message' => ['type' => 'string', 'example' => 'Database stopping request queued.'],
]) ]
)
),
]
), ),
]),
new OA\Response( new OA\Response(
response: 401, response: 401,
ref: '#/components/responses/401', ref: '#/components/responses/401',
@@ -1784,9 +1789,11 @@ class DatabasesController extends Controller
type: 'object', type: 'object',
properties: [ properties: [
'message' => ['type' => 'string', 'example' => 'Database restaring request queued.'], 'message' => ['type' => 'string', 'example' => 'Database restaring request queued.'],
]) ]
)
),
]
), ),
]),
new OA\Response( new OA\Response(
response: 401, response: 401,
ref: '#/components/responses/401', ref: '#/components/responses/401',

View File

@@ -280,7 +280,7 @@ class PushServerUpdateJob implements ShouldBeEncrypted, ShouldQueue
})->first(); })->first();
if (! $tcpProxyContainerFound) { if (! $tcpProxyContainerFound) {
StartDatabaseProxy::dispatch($database); StartDatabaseProxy::dispatch($database);
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server)); $this->server->team?->notify(new ContainerRestarted("TCP Proxy for database", $this->server));
} else { } else {
} }
} }

View File

@@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Visus\Cuid2\Cuid2; use Visus\Cuid2\Cuid2;
@@ -18,4 +19,16 @@ abstract class BaseModel extends Model
} }
}); });
} }
public function name(): Attribute
{
return new Attribute(
get: fn() => sanitize_string($this->getRawOriginal('name')),
);
}
public function image(): Attribute
{
return new Attribute(
get: fn() => sanitize_string($this->getRawOriginal('image')),
);
}
} }

View File

@@ -127,6 +127,13 @@ class Team extends Model implements SendsDiscord, SendsEmail
]; ];
} }
public function name(): Attribute
{
return new Attribute(
get: fn() => sanitize_string($this->getRawOriginal('name')),
);
}
public function getRecepients($notification) public function getRecepients($notification)
{ {
$recipients = data_get($notification, 'emails', null); $recipients = data_get($notification, 'emails', null);

View File

@@ -90,8 +90,28 @@ function metrics_dir(): string
return base_configuration_dir() . '/metrics'; return base_configuration_dir() . '/metrics';
} }
function sanitize_string(string $input): string
{
// Remove any HTML/PHP tags
$sanitized = strip_tags($input);
// Convert special characters to HTML entities
$sanitized = htmlspecialchars($sanitized, ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Remove any control characters
$sanitized = preg_replace('/[\x00-\x1F\x7F]/u', '', $sanitized);
// Trim whitespace
$sanitized = trim($sanitized);
return $sanitized;
}
function generate_readme_file(string $name, string $updated_at): string function generate_readme_file(string $name, string $updated_at): string
{ {
$name = sanitize_string($name);
$updated_at = sanitize_string($updated_at);
return "Resource name: $name\nLatest Deployment Date: $updated_at"; return "Resource name: $name\nLatest Deployment Date: $updated_at";
} }