diff --git a/Config/config.php b/Config/config.php index f29a455..4fe6a2c 100644 --- a/Config/config.php +++ b/Config/config.php @@ -122,6 +122,7 @@ 'custom_css' => {{ MISP_CUSTOM_CSS | str }}, 'tmpdir' => '/tmp', 'log_client_ip_header' => 'HTTP_X_FORWARDED_FOR', + 'trusted_proxies' => {{ MISP_TRUSTED_PROXIES | str }}, 'thumbnail_in_redis' => true, 'self_update' => false, 'python_bin' => '/usr/bin/python3.12', diff --git a/README.md b/README.md index d573efc..c6c63a3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ For production usage, please: * change passwords for MariaDB and Redis, * modify environment variables to requested values, * deploy reverse proxy (for example `nginx`) before MISP to handle HTTPS connections. - * do not forget to send the proper `[X-Forwarded-For](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For)` header + * do not forget to send the proper [`X-Forwarded-For`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For) header + * you also have to set `MISP_TRUSTED_PROXIES` so MISP will accept `X-Forwarded-For` from that server ### Usage in air-gapped environment @@ -116,6 +117,7 @@ By default, MISP requires Redis. MISP will connect to Redis defined in `REDIS_HO * `MISP_MODULE_URL` (optional, string) - full URL to MISP modules * `MISP_DEBUG` (optional, boolean, default `false`) - enable debug mode (do not enable on production environment) * `MISP_OUTPUT_COMPRESSION` (optional, boolean, default `true`) - enable or disable gzip or brotli output compression +* `MISP_TRUSTED_PROXIES` (optional, string) - a comma-separated list of trusted IPv4 or IPv6 addresses or network ranges from which the `X-Forwarded-For` header is accepted. [Check more variables that allow MISP customization.](docs/CUSTOMIZATION.md) diff --git a/bin/misp_create_configs.py b/bin/misp_create_configs.py index a8c1295..1b50c0b 100644 --- a/bin/misp_create_configs.py +++ b/bin/misp_create_configs.py @@ -7,6 +7,7 @@ import json import hashlib import argparse +import ipaddress from urllib.parse import urlparse, quote_plus from typing import Optional, Type, Callable, Any, NoReturn, List, Union, Tuple from jinja2 import Environment @@ -101,6 +102,19 @@ def check_oidc_code_challenge(variable_name: str, value: str): raise ValueError(f"Environment variable '{variable_name}' value is not valid, must be one of {valid_methods}") +def check_is_list_ips(variable_name: str, value: str): + for item in value.split(","): + item = item.strip() + if not item: + continue + try: + ipaddress.ip_network(item) + except ValueError as e: + raise ValueError( + f"Environment variable '{variable_name}' contains " + f"an invalid IP address or network '{item}': {e}") + + def dict_parser(variable_name: str, value: str, seperator: str = ',', key_value_delimiter: str = '=', variable_description: str = "") -> dict: value = value.strip() if len(value) == 0: @@ -244,6 +258,7 @@ def parse_mysql_settings(variable_name: str, value: str) -> dict: "MISP_HOME_LOGO": Option(), "MISP_FOOTER_LOGO": Option(), "MISP_CUSTOM_CSS": Option(), + "MISP_TRUSTED_PROXIES": Option(validation=check_is_list_ips), # Security "GNUPG_SIGN": Option(typ=bool, default=False), "GNUPG_PRIVATE_KEY_PASSWORD": Option(sensitive=True),