keycloak / keycloak-nodejs-connect

Apache License 2.0
676 stars 421 forks source link

Port number problem in post_logout_redirect_uri with ipv6 addresses #424

Open acerola1 opened 2 years ago

acerola1 commented 2 years ago

Describe the bug

In a corporate cloud environment we use ipv6 addresses. When the redirect uri is not defined keycloak-connect create a redirect-ui based on the request host for the logout. When the host is an ipv6 address, then parsing out the port number is not working right. It adds part of the ipv6 address instead of the real port number.

Version

19

Expected behavior

When the host of the request is an ipv6 address like [2001:db8:4006:812::200e]:8080 then the generated post_logout_redirect_uri should be [2001:db8:4006:812::200e]:8080

Actual behavior

Now the generated post_logout_redirect_uri is [2001:db8:4006:812::200e]:db8

How to Reproduce?

It is hard to reproduce, because it is not a normal use case that you use ipv6 ip address for a website. I think in out case it is caused by some kind of proxying inside the cloud environment. But it is a simple parsing problem. The port parsing for ipv6 should be different. Something like this.

let getPort = (url) => {
    let res;
    if (isIpv6Address(url)) {
        res = url.split(']');
        res = res[1].split(':');
    } else {
        res = url.split(':');
    }
    return res[1] || '';
} 

Anything else?

No response