mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
security/crowdsec(fix): IPv6 validation for LAPI listen address broken (#4822)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user