Skip to content

KEYCLOAK-14071 Valid Redirect URI for review apps (wildcard in hostname?)#8187

Closed
DorianMazur wants to merge 4 commits intokeycloak:mainfrom
DorianMazur:master
Closed

KEYCLOAK-14071 Valid Redirect URI for review apps (wildcard in hostname?)#8187
DorianMazur wants to merge 4 commits intokeycloak:mainfrom
DorianMazur:master

Conversation

@DorianMazur
Copy link
Copy Markdown

https://issues.redhat.com/projects/KEYCLOAK/issues/KEYCLOAK-14071

Compare with wildcard algorithm based on https://www.geeksforgeeks.org/wildcard-pattern-matching

m = length of string, n = length of wildcard filter
Time complexity: O(m x n)
Auxillary space: O(m x n)

@BuuBux
Copy link
Copy Markdown

BuuBux commented Jun 21, 2021

Good job

@mposolda
Copy link
Copy Markdown
Contributor

@DorianMazur Thanks for the PR.

IMO this requires a bit more work to be secure by default and flexible at the same time. Few considerations regarding this PR:

IMO, the possible solution for this might be to add the option on the SecureClientUrisExecutor. The option might be like "Wildcards in Redirect URI" with the values like:

  • no wildcard supported (Default value)
  • Wildcards at the end (Will allow stuff like "https//www.myhost.com/foo/*" similarly like now)
  • Wildcards at the end and in subdomains (Will allow stuff like "https://.myhost.com/foo" or "https://.myhost.com/foo/", but not "https:///foo")

The alternative, which will be more flexible, is to use option like "Allowed Redirect URI regex pattern", which will allow more flexibility to specify both wildcards and protocol. This might be even better approach probably, however a bit harder for administrators to setup as not everyone is familiar with regexes. So we would need to document examples with the common use-cases (EG. Example for wildcards in the subdomain, wildcards at the end of the path etc).

@mposolda mposolda self-assigned this Jun 22, 2021
@mposolda mposolda added area/oidc Indicates an issue on OIDC area status/needs-discussion PR needs discussion on developer mailing list status/in-review and removed status/needs-discussion PR needs discussion on developer mailing list labels Jun 22, 2021
@ArbitraryCritter
Copy link
Copy Markdown

One thing to note when comparing this to the current capability, especially seen from a security angle, is that you can actually set just a lone wildcard currently, eg: valid_request_uri: "*". Ofcourse from a security point of view this is quite abhorrent, but it's just to say that while this flexible wildcard capability does add more refined ways to shoot oneself in the foot, the current approach has exactly the same potential for the same. And there are actually usecases (like those mentioned in the issue) that invite it.

I believe the patch should considered as-is, perhaps with the addition of an interface warning when a wildcard is used anywhere in a redirect string.

@thomasdarimont
Copy link
Copy Markdown
Contributor

How about using * as a strict wildcard that preserves the current behavior
and introducing ** as dynamic wildcard that behaves as proposed in this PR?

@kristianbendren
Copy link
Copy Markdown

Is this something that will be merged? Really need this implementation

Copy link
Copy Markdown
Contributor

@stianst stianst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I appreciate we already have support for wildcards in Keycloak we should not extend on it unless we make it configurable and can improve on recommended settings in production use-cases. To make it clear we have support for '*' as a redirect-uri in KC only as a convenience for development, and this should never be used in production.

In production wildcards should really be avoided completely, especially in the domain as that can lead to insecure setup and also bad practice in terms of multiple applications (as observed from the users perspective) using the same client.

What I'd like to see is client policies that allow setting what level of wildcards are supported. With Keycloak.X we have two different modes of the server, where we can by default allow wildcards in dev, and disallow in prod.

In it's current form I'm not okay with having this PR merged, to progress on this please open a discussion around it in GitHub Discussions.

@mposolda
Copy link
Copy Markdown
Contributor

I am closing for now. Anyone is welcome to open the discussions with more details. Please add the discussion link as a comment here to this PR when you do it. Bottom line is that we won't allow more wildcards by default, but we may need to drive this with client policies if better flexibility is needed (for example with wildcard in subdomains).

@mposolda mposolda closed this Nov 16, 2021
@oliverabclabs
Copy link
Copy Markdown

oliverabclabs commented Nov 25, 2021

I vote for reopening this issue.

Why cant we implement like others already proposed:
https://*.foo.com/*
which would allow https://preview-1.foo.com but not https://evilpage.com/evil.foo.com

Is it just a question of security for the Keycloak team? I dont understand how such a feature would introduce any problems. As long as the wildcard is limited to the root domain foo.com

@oliverabclabs
Copy link
Copy Markdown

For someone that uses deploy preview urls that are dynamically created for each pull request for the application, keycloak is rendered completely unuseable without this feature

@stianst
Copy link
Copy Markdown
Contributor

stianst commented Nov 25, 2021

Wildcards in subdomains may be perfectly fine in some environments, but not in others. As previously mentioned we are happy to have this included, but not as a default. We are moving towards not allowing wildcards at all by default, and using client policies to opt-in to allow wildcards for all or some clients.

@navrocky
Copy link
Copy Markdown

navrocky commented Dec 6, 2021

For now you can use simple "*" for redirect uri instead of "https://*.review.example.com". It just works for me.

@jputney
Copy link
Copy Markdown

jputney commented Dec 10, 2021

I'm wondering what exactly is this attack vector that allows someone to add dns entries to match *.example.com, but prevents them from hijacking the foo.example.com record that's specified in your redirect URI?

@navrocky
Copy link
Copy Markdown

I think that for review deployments any kind of attack don't make sense, so i don't care about it.

@stianst
Copy link
Copy Markdown
Contributor

stianst commented Dec 21, 2021

See here for a follow-up discussion on this topic:
#9278

@stianst
Copy link
Copy Markdown
Contributor

stianst commented Dec 21, 2021

@jputney there are plenty of situations where a sub-domain is not fully owned by an individual application, and where subdomains are created dynamically on-behalf of other users (AWS for example).

@stianst
Copy link
Copy Markdown
Contributor

stianst commented Dec 21, 2021

@navrocky * is a terrible thing to use or advocate, and leads to a magnitude of vulnerabilities. I would suggest you refer to OAuth 2.0 best practices to read up on the various vulnerabilities that are associated with insufficient redirect-uri validation.

@to-bee
Copy link
Copy Markdown

to-bee commented Dec 21, 2021

@navrocky * is a terrible thing to use or advocate, and leads to a magnitude of vulnerabilities. I would suggest you refer to OAuth 2.0 best practices to read up on the various vulnerabilities that are associated with insufficient redirect-uri validation.

At least "https://*.review.example.com" is something that is needed for every feature branch based test environment.

@don4of4
Copy link
Copy Markdown

don4of4 commented Oct 18, 2022

I also support this for the reason @to-bee cites.

@antoine-habran
Copy link
Copy Markdown

Hi @stianst

Real question: if this is a "terrible thing to use or advocate, and leads to a magnitude of vulnerabilities", why the simple * is allowed in 'redirect_urls' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/oidc Indicates an issue on OIDC area

Projects

None yet

Development

Successfully merging this pull request may close these issues.