fix(validation): add input validation for port exposes and port mappings fields (#9240)

This commit is contained in:
Andras Bacsai
2026-03-30 21:02:50 +02:00
committed by GitHub
10 changed files with 74 additions and 10 deletions
+24
View File
@@ -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.
*/