|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import logging |
15 | 16 | import os |
16 | 17 | from collections import namedtuple |
17 | 18 | from typing import Dict, List |
| 19 | +from urllib.request import getproxies_environment # type: ignore |
18 | 20 |
|
19 | 21 | from synapse.config.server import DEFAULT_IP_RANGE_BLACKLIST, generate_ip_set |
20 | 22 | from synapse.python_dependencies import DependencyException, check_requirements |
21 | 23 | from synapse.util.module_loader import load_module |
22 | 24 |
|
23 | 25 | from ._base import Config, ConfigError |
24 | 26 |
|
| 27 | +logger = logging.getLogger(__name__) |
| 28 | + |
25 | 29 | DEFAULT_THUMBNAIL_SIZES = [ |
26 | 30 | {"width": 32, "height": 32, "method": "crop"}, |
27 | 31 | {"width": 96, "height": 96, "method": "crop"}, |
|
36 | 40 | # method: %(method)s |
37 | 41 | """ |
38 | 42 |
|
| 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 | + |
39 | 46 | ThumbnailRequirement = namedtuple( |
40 | 47 | "ThumbnailRequirement", ["width", "height", "method", "media_type"] |
41 | 48 | ) |
@@ -180,12 +187,17 @@ def read_config(self, config, **kwargs): |
180 | 187 | e.message # noqa: B306, DependencyException.message is a property |
181 | 188 | ) |
182 | 189 |
|
| 190 | + proxy_env = getproxies_environment() |
183 | 191 | 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)) |
189 | 201 |
|
190 | 202 | # we always blacklist '0.0.0.0' and '::', which are supposed to be |
191 | 203 | # unroutable addresses. |
@@ -292,6 +304,8 @@ def generate_config_section(self, data_dir_path, **kwargs): |
292 | 304 | # This must be specified if url_preview_enabled is set. It is recommended that |
293 | 305 | # you uncomment the following list as a starting point. |
294 | 306 | # |
| 307 | + # Note: The value is ignored when an HTTP proxy is in use |
| 308 | + # |
295 | 309 | #url_preview_ip_range_blacklist: |
296 | 310 | %(ip_range_blacklist)s |
297 | 311 |
|
|
0 commit comments