security/crowdsec(fix): IPv6 validation for LAPI listen address broken (#4822)

This commit is contained in:
BPplays
2025-07-21 23:49:20 +02:00
committed by GitHub
parent f9c9cf9a1e
commit 61ef64fa13
2 changed files with 7 additions and 2 deletions
@@ -24,10 +24,10 @@
<Required>Y</Required>
</lapi_manual_configuration>
<lapi_listen_address type="TextField">
<lapi_listen_address type="NetworkField">
<Default>127.0.0.1</Default>
<Required>Y</Required>
<Mask>((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))</Mask>
<NetMaskAllowed>N</NetMaskAllowed>
</lapi_listen_address>
<lapi_listen_port type="PortField">
@@ -10,6 +10,9 @@ import yaml
logging.basicConfig(level=logging.INFO)
def is_ipv6(ip: str) -> bool:
return ":" in ip
def load_config(filename: str) -> dict[str, Any]:
with open(filename) as fin:
return yaml.safe_load(fin)
@@ -27,6 +30,8 @@ def get_netloc(settings: dict[str, str]):
# defaults if config has not been saved yet
listen_address = settings.get('lapi_listen_address', '127.0.0.1')
listen_port = settings.get('lapi_listen_port', '8080')
if is_ipv6(listen_address):
listen_address = '[{}]'.format(listen_address)
return '{}:{}'.format(listen_address, listen_port)