mongkok / fastapi-debug-toolbar

A debug toolbar for FastAPI.
https://fastapi-debug-toolbar.domake.io
BSD 3-Clause "New" or "Revised" License
138 stars 14 forks source link

IP restrictions via ALLOWED_IPS not working #39

Closed MartinSchmidt123 closed 8 months ago

MartinSchmidt123 commented 9 months ago

I tried to get ALLOWED_IPS to work and found that the test

remote_addr in settings.ALLOWED_IPS

in https://github.com/mongkok/fastapi-debug-toolbar/blob/main/debug_toolbar/middleware.py#L25 always returns False because remote_addr is of type str and ALLOWED_IPS is a list of type IPv4Address.

Printing the variables in question returns for

print(f"{remote_addr} in {settings.ALLOWED_IPS}: {remote_addr in settings.ALLOWED_IPS}")
print(f"{type(remote_addr)} {type(settings.ALLOWED_IPS[0])}")

the results

127.0.0.1 in [IPv4Address('127.0.0.1'), IPv4Address('1.2.3.4')]: False
<class 'str'> <class 'ipaddress.IPv4Address'>
mongkok commented 8 months ago

Thanks for the details @MartinSchmidt123 , please check the new release, ALLOWED_IPS settings was removed in favor of ALLOWED_HOSTS: Sequence[str] | None.