Skip to content

Redis Cache not working with user and password (only work when user setted) #47303

@cedriclombardot

Description

@cedriclombardot

Symfony version(s) affected

6.0.*

Description

When we use a default_redis_provider with password

Like rediss://<user>:<pass>@<host>:<port>/<path>

The RedisTrait initializer will failed with a WRONGPASS because at line 214 the $redis->auth($auth) is only called with password instead of user and password

How to reproduce

See Description

Possible Solution

Change line 97

        $params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
            if (isset($m[2])) {
                $auth = $m[2];

                if ('' === $auth) {
                    $auth = null;
                }
            }

            return 'file:'.($m[1] ?? '');
        }, $dsn);

BY

$params = preg_replace_callback('#^'.$scheme.':(\/\/)?([^:@]*+)(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
            if (isset($m[2])) {
                $auth = $m[2];

                if ('' === $auth) {
                    $auth = null;
                }

                if (isset($m[3])) {
                    $auth = [ $auth, $m[3] ];
                }
            }

            return 'file:'.($m[1] ?? '');
        }, $dsn);

Additional Context

Warning the fix not working completly for other paths

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions