thadeusb / flask-cache

Cache extension for Flask
http://packages.python.org/Flask-Cache/
Other
700 stars 185 forks source link

Passwords that contain "/" character cause problems in Redis URLs #190

Closed martinpeck closed 6 years ago

martinpeck commented 6 years ago

If I try and use a REDIS_CACHE_URL, and within that url I have a password that looks like this...

redis_url = 'rediss://:F6tM/t41SZ/c57sr2KFt0=@myredis.example.com:6380/0'

... (notice that it has two / characters) then I see a connection error as the url is not parsed correctly.

The underlying package redis-py supports URLEncoding/Decoding of connection urls, but it's something that requires code changes (it requires an additional parameter when making the connection). e.g...

client = redis.Redis.from_url(redis_url, decode_components = True)

To make use of this ability, this code would need to be alterered to use this decode_components parameter:

https://github.com/thadeusb/flask-cache/blob/1c60076b6d4c2df0ac1de54c59e63b4f780cecbc/flask_cache/backends.py#L79-L81

Is it reasonable that flash-cache should make a change so that it uses decode_components = True in all situations or, to preserve the current behaviour, is is reasonable to add an additional ENV variable (e.g. CACHE_REDIS_ENCODED_URL to specify an encoded URL, or CACHE_REDIS_DECODE_URL set to True if decoding should occur)? If so, I'm happy to provide a PR.

TimLovellSmith commented 6 years ago

@martinpeck would it work for you to just use the configuration options CACHE_REDIS_HOST, CACHE_REDIS_PASSWORD, CACHE_REDIS_PORT and CACHE_REDIS_DB instead of CACHE_REDIS_URL?

martinpeck commented 6 years ago

Those are options for sure, but do any of these then force use of SSL? I know you can set the CACHE_REDIS_PORT, but does this then set the connection to use SSL?

martinpeck commented 6 years ago

that said....I still think it would make sense to allow Flask-Cache to pass through something to the underlying redis-py to say "my url is urlencoded"

TimLovellSmith commented 6 years ago

I wonder if CACHE_REDIS_URL and CACHE_REDIS_PASSWORD can work in combination... (redis-py noob)

martinpeck commented 6 years ago

Having scanned through the code of Flask-Cache and Redis-Py, I'm not sure that'll work. I'll take another look, but pretty sure I looked for this.

martinpeck commented 6 years ago

This hasn't got traction, and the related issue has been resolved, so I'm going to close this now.