Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 72935b7

Browse files
authored
Add warnings to ip_range_blacklist usage with proxies (#10129)
Per issue #9812 using `url_preview_ip_range_blacklist` with a proxy via `HTTPS_PROXY` or `HTTP_PROXY` environment variables has some inconsistent bahavior than mentioned. This PR changes the following: - Changes the Sample Config file to include a note mentioning that `url_preview_ip_range_blacklist` and `ip_range_blacklist` is ignored when using a proxy - Changes some logic in synapse/config/repository.py to send a warning when both `*ip_range_blacklist` configs and a proxy environment variable are set and but no longer throws an error. Signed-off-by: Kento Okamoto <[email protected]>
1 parent 951648f commit 72935b7

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

changelog.d/10129.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some clarification to the sample config file. Contributed by @Kentokamoto.

docs/sample_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ presence:
210210
#
211211
# This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
212212
#
213+
# Note: The value is ignored when an HTTP proxy is in use
214+
#
213215
#ip_range_blacklist:
214216
# - '127.0.0.0/8'
215217
# - '10.0.0.0/8'
@@ -972,6 +974,8 @@ media_store_path: "DATADIR/media_store"
972974
# This must be specified if url_preview_enabled is set. It is recommended that
973975
# you uncomment the following list as a starting point.
974976
#
977+
# Note: The value is ignored when an HTTP proxy is in use
978+
#
975979
#url_preview_ip_range_blacklist:
976980
# - '127.0.0.0/8'
977981
# - '10.0.0.0/8'

synapse/config/repository.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import logging
1516
import os
1617
from collections import namedtuple
1718
from typing import Dict, List
19+
from urllib.request import getproxies_environment # type: ignore
1820

1921
from synapse.config.server import DEFAULT_IP_RANGE_BLACKLIST, generate_ip_set
2022
from synapse.python_dependencies import DependencyException, check_requirements
2123
from synapse.util.module_loader import load_module
2224

2325
from ._base import Config, ConfigError
2426

27+
logger = logging.getLogger(__name__)
28+
2529
DEFAULT_THUMBNAIL_SIZES = [
2630
{"width": 32, "height": 32, "method": "crop"},
2731
{"width": 96, "height": 96, "method": "crop"},
@@ -36,6 +40,9 @@
3640
# method: %(method)s
3741
"""
3842

43+
HTTP_PROXY_SET_WARNING = """\
44+
The Synapse config url_preview_ip_range_blacklist will be ignored as an HTTP(s) proxy is configured."""
45+
3946
ThumbnailRequirement = namedtuple(
4047
"ThumbnailRequirement", ["width", "height", "method", "media_type"]
4148
)
@@ -180,12 +187,17 @@ def read_config(self, config, **kwargs):
180187
e.message # noqa: B306, DependencyException.message is a property
181188
)
182189

190+
proxy_env = getproxies_environment()
183191
if "url_preview_ip_range_blacklist" not in config:
184-
raise ConfigError(
185-
"For security, you must specify an explicit target IP address "
186-
"blacklist in url_preview_ip_range_blacklist for url previewing "
187-
"to work"
188-
)
192+
if "http" not in proxy_env or "https" not in proxy_env:
193+
raise ConfigError(
194+
"For security, you must specify an explicit target IP address "
195+
"blacklist in url_preview_ip_range_blacklist for url previewing "
196+
"to work"
197+
)
198+
else:
199+
if "http" in proxy_env or "https" in proxy_env:
200+
logger.warning("".join(HTTP_PROXY_SET_WARNING))
189201

190202
# we always blacklist '0.0.0.0' and '::', which are supposed to be
191203
# unroutable addresses.
@@ -292,6 +304,8 @@ def generate_config_section(self, data_dir_path, **kwargs):
292304
# This must be specified if url_preview_enabled is set. It is recommended that
293305
# you uncomment the following list as a starting point.
294306
#
307+
# Note: The value is ignored when an HTTP proxy is in use
308+
#
295309
#url_preview_ip_range_blacklist:
296310
%(ip_range_blacklist)s
297311

synapse/config/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,8 @@ def generate_config_section(
960960
#
961961
# This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
962962
#
963+
# Note: The value is ignored when an HTTP proxy is in use
964+
#
963965
#ip_range_blacklist:
964966
%(ip_range_blacklist)s
965967

0 commit comments

Comments
 (0)