Skip to content

Commit 7e98d98

Browse files
authored
Fix Redis limiter (#885)
## Description ### Summary When using multiple IPs in FORWARDED_ALLOW_IPS variable, request.client.host can be something else than an IP address string and will be wrongly parsed by Redis, implying an error and refusing the connection. ### Changes Made - [x] Force input data type to string ### Type of Change - [x] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 🔨 Refactor (non-breaking change that neither fixes a bug nor adds a feature) - [ ] 🔧 Infra CI/CD (changes to configs of workflows) - [ ] 💥 BREAKING CHANGE (fix or feature that require a new minimal version of the front-end) - [ ] 😶‍🌫️ No impact for the end-users ### Impact & Scope - [x] Core functionality changes - [ ] Single module changes - [ ] Multiple modules changes - [ ] Database migrations required - [ ] Other: <!--not module-oriented--> ### Testing - [ ] 1. Tested this locally - [ ] 2. Added/modified tests that pass the CI - [ ] 3. Tested in a pre-prod - [x] 0. Untestable (exceptionally), will be tested in prod directly Error condition are uncertain and can't be reproduced ### Documentation - [ ] Updated [the docs](docs.myecl.fr) accordingly : <!--[Docs#0 - Title](https://github.com/aeecleclair/myecl-documentation/pull/0)--> - [ ] `"` Docstrings - [x] `#` Inline comments - [ ] No documentation needed </details>
1 parent 81b6e15 commit 7e98d98

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ async def logging_middleware(
673673
)
674674
raise HTTPException(status_code=400, detail="No client information")
675675

676-
ip_address = request.client.host
676+
ip_address = str(
677+
request.client.host,
678+
) # host can be an Object of type IPv4Address or IPv6Address and would be refused by redis
677679
port = request.client.port
678680
client_address = f"{ip_address}:{port}"
679681

0 commit comments

Comments
 (0)