Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does OAuth RFC require the redirect_uri to be passed again to exchange code for token?

Assuming my redirect uri and authorization code request was valid, and I want to exchange the valid code for a token, what is the benefit of validating that the redirect URI I pass in access_code requests matches the same uri provided in the authorization code request?

like image 497
Sam Avatar asked Apr 15 '15 14:04

Sam


People also ask

What is the purpose of Redirect_uri?

A redirect URI, or reply URL, is the location where the authorization server sends the user once the app has been successfully authorized and granted an authorization code or access token.

Why do we need authorization code in OAuth?

The authorization code is a temporary code that the client will exchange for an access token. The code itself is obtained from the authorization server where the user gets a chance to see what the information the client is requesting, and approve or deny the request.

What is oauth2 RFC?

The OAuth 2.0 Core Framework (RFC 6749) defines roles and a base level of functionality, but leaves a lot of implementation details unspecified. Since the publication of the RFC, the OAuth Working Group has published many additional specs built on top of this framework to fill in the missing pieces.

What is oauth2 authentication and how it works?

OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user. It replaced OAuth 1.0 in 2012 and is now the de facto industry standard for online authorization.


1 Answers

It is to prevent an attacker from manipulating the Authentication Request and make the Authorization Server send the code to a URL under the attacker's control.

This attack is not be possible if there's only a single redirect URI that is registered with the Authorization Server (best practice) but when using a loose type of matching - e.g. any redirect URI on a specific domain is accepted - then it may very well be possible that some parts of that domain can be manipulated by the attacker (e.g. through open redirects, vulnerable wiki's, forums. etc.) to get a hold of the code and subsequently replay it against the legitimate client. With the mandatory redirect URI in place, there would now be a mismatch between the redirect URI that the Authorization Server saw in the Authorization Request and the one that the client uses towards the token endpoint. This attack is even more trivial if no redirect URI was pre-registered at all.

The reasoning is part of the security considerations of the spec here: https://www.rfc-editor.org/rfc/rfc6749#section-10.6

When requesting authorization using the authorization code grant
type, the client can specify a redirection URI via the "redirect_uri" parameter. If an attacker can manipulate the value of the
redirection URI, it can cause the authorization server to redirect
the resource owner user-agent to a URI under the control of the
attacker with the authorization code.

An attacker can create an account at a legitimate client and initiate the authorization flow. When the attacker's user-agent is sent to the authorization server to grant access, the attacker grabs the authorization URI provided by the legitimate client and replaces the

client's redirection URI with a URI under the control of the
attacker. The attacker then tricks the victim into following the
manipulated link to authorize access to the legitimate client.

Once at the authorization server, the victim is prompted with a
normal, valid request on behalf of a legitimate and trusted client,
and authorizes the request. The victim is then redirected to an
endpoint under the control of the attacker with the authorization
code. The attacker completes the authorization flow by sending the
authorization code to the client using the original redirection URI
provided by the client. The client exchanges the authorization code
with an access token and links it to the attacker's client account,
which can now gain access to the protected resources authorized by
the victim (via the client).

In order to prevent such an attack, the authorization server MUST
ensure that the redirection URI used to obtain the authorization code is identical to the redirection URI provided when exchanging the
authorization code for an access token. The authorization server
MUST require public clients and SHOULD require confidential clients
to register their redirection URIs. If a redirection URI is provided in the request, the authorization server MUST validate it against the registered value.

like image 136
Hans Z. Avatar answered Sep 23 '22 10:09

Hans Z.