Repository: matrix-org/synapse

Issue:
During config parsing, when `federation_certificate_verification_whitelist` is specified as an empty value, the server crashes
<!--

**IF YOU HAVE SUPPORT QUESTIONS ABOUT RUNNING OR CONFIGURING YOUR OWN HOME SERVER**:
You will likely get better support more quickly if you ask in ** #synapse:matrix.org ** ;)


This is a bug report template. By following the instructions below and
filling out the sections with your information, you will help the us to get all
the necessary data to fix your issue.

You can also preview your report before submitting it. You may remove sections
that aren't relevant to your particular case.

Text between <!-- and --​> marks will be invisible in the report.

-->

### Description

<!-- Describe here the problem that you are experiencing -->

During config parsing, when federation_certificate_verification_whitelist is specified as an empty value, the server crashes.

Ideally the empty value would be interpreted as [] and continue merrily along.

This is the same bug as #4550 just for federation_certificate_verification_whitelist.

### Steps to reproduce

- Configure synapse with the line: 
`federation_certificate_verification_whitelist:`
- Start server
- server crashes

```
synapse_1   | Traceback (most recent call last):
synapse_1   |   File "/usr/local/lib/python3.8/runpy.py", line 192, in _run_module_as_main
synapse_1   |     return _run_code(code, main_globals, None,
synapse_1   |   File "/usr/local/lib/python3.8/runpy.py", line 85, in _run_code
synapse_1   |     exec(code, run_globals)
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/app/homeserver.py", line 639, in <module>
synapse_1   |     main()
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/app/homeserver.py", line 634, in main
synapse_1   |     hs = setup(sys.argv[1:])
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/app/homeserver.py", line 318, in setup
synapse_1   |     config = HomeServerConfig.load_or_generate_config(
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/config/_base.py", line 616, in load_or_generate_config
synapse_1   |     obj.parse_config_dict(
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/config/_base.py", line 635, in parse_config_dict
synapse_1   |     self.invoke_all(
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/config/_base.py", line 254, in invoke_all
synapse_1   |     res[name] = getattr(config, func_name)(*args, **kwargs)
synapse_1   |   File "/usr/local/lib/python3.8/site-packages/synapse/config/tls.py", line 115, in read_config
synapse_1   |     for entry in fed_whitelist_entries:
synapse_1   | TypeError: 'NoneType' object is not iterable
```

<!--
Describe how what happens differs from what you expected.

If you can identify any relevant log snippets from _homeserver.log_, please include
those (please be careful to remove any personal or private data). Please surround them with
``` (three backticks, on a line on their own), so that they are formatted legibly.
-->

### Version information

<!-- IMPORTANT: please answer the following questions, to help us narrow down the problem -->

<!-- Was this issue identified on matrix.org or another homeserver? -->
- **Homeserver**:

If not matrix.org:

<!--
 What version of Synapse is running?

You can find the Synapse version with this command:

$ curl http://localhost:8008/_synapse/admin/v1/server_version

(You may need to replace `localhost:8008` if Synapse is not configured to
listen on that port.)
-->
- **Version**:v1.9.1

- **Install method**: docker-compose build from source

- **Platform**: raspberry pi 4
<!--
Tell us about the environment in which your homeserver is operating
distro, hardware, if it's running in a vm/container, etc.
-->



Discussion:
Thanks for the clear bug report!
Hi, I'd like to pick this as a first issue!
@timfi : great! I suggest joining #synapse-dev:matrix.org where we can help get you started if you need a hand.

Resolving patch:
diff --git a/synapse/config/tls.py b/synapse/config/tls.py
--- a/synapse/config/tls.py
+++ b/synapse/config/tls.py
@@ -109,6 +109,8 @@ def read_config(self, config: dict, config_dir_path: str, **kwargs):
         fed_whitelist_entries = config.get(
             "federation_certificate_verification_whitelist", []
         )
+        if fed_whitelist_entries is None:
+            fed_whitelist_entries = []
 
         # Support globs (*) in whitelist values
         self.federation_certificate_verification_whitelist = []  # type: List[str]


Test patch: