mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-08 12:23:24 +00:00
fix(validation): add input validation for port exposes and port mappings fields (#9240)
This commit is contained in:
@@ -201,6 +201,12 @@ class ValidationPatterns
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern for port mappings (e.g. 3000:3000, 8080:80, 8000-8010:8000-8010)
|
||||
* Each entry requires host:container format, where each side can be a number or a range (number-number)
|
||||
*/
|
||||
public const PORT_MAPPINGS_PATTERN = '/^(\d+(-\d+)?:\d+(-\d+)?)(,\d+(-\d+)?:\d+(-\d+)?)*$/';
|
||||
|
||||
/**
|
||||
* Get validation rules for container name fields
|
||||
*/
|
||||
@@ -209,6 +215,24 @@ class ValidationPatterns
|
||||
return ['string', 'max:'.$maxLength, 'regex:'.self::CONTAINER_NAME_PATTERN];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validation rules for port mapping fields
|
||||
*/
|
||||
public static function portMappingRules(): array
|
||||
{
|
||||
return ['nullable', 'string', 'regex:'.self::PORT_MAPPINGS_PATTERN];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validation messages for port mapping fields
|
||||
*/
|
||||
public static function portMappingMessages(string $field = 'portsMappings'): array
|
||||
{
|
||||
return [
|
||||
"{$field}.regex" => 'Port mappings must be a comma-separated list of port pairs or ranges (e.g. 3000:3000,8080:80,8000-8010:8000-8010).',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid Docker container name.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user