0Pricing
OAuth2 & OpenID Connect Deep Dive · Aula

Protegendo URIs de redirecionamento

Aprenda por que a validação de URI de redirecionamento é fundamental para a segurança do OAuth2 e como impedir ataques de redirecionamento aberto e interceptação de códigos.

Protegendo URIs de redirecionamento é uma aula grátis de OAuth2 & OpenID Connect Deep Dive no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de OAuth2 & OpenID Connect Deep Dive, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de OAuth2 & OpenID Connect Deep Dive inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

The redirect_uri Is Critical

After the user authorizes, the authorization server sends the code (or token) back to the client by redirecting the browser to the redirect_uri. If an attacker can influence that URI, they can steal the code.

Redirect URI validation is therefore one of the highest-impact security controls in OAuth2.

Exact Matching

The single most important rule: the authorization server must compare the supplied redirect_uri against pre-registered values using exact string matching, not pattern or prefix matching.

Registered: https://app.example.com/callback
Request:    https://app.example.com/callback   (OK)
Request:    https://app.example.com/callback/x (REJECT)

Open Redirector Abuse

Loose matching enables open redirector attacks. If https://app.example.com/* is allowed, an attacker may target a page that bounces to an evil host, smuggling the authorization code out.

Wildcards Are Dangerous

Avoid wildcard subdomains and ports. Something like https://*.example.com/cb lets an attacker who controls any subdomain (including user-content subdomains) receive codes.

Always Require HTTPS

Redirect URIs must use https, except for native loopback (http://127.0.0.1) during local development. Plain http over the network exposes the code to interception.

Fragments and Query Tricks

Attackers add fragments (#) or extra query parameters to confuse parsers. Normalize and compare the full registered URI, and reject requests whose redirect_uri carries unexpected components.

Native App Schemes

Native apps often use custom schemes like myapp://callback, but these can be hijacked by another app registering the same scheme. Prefer claimed HTTPS redirects (Universal Links / App Links) which the OS verifies against your domain.

Validating on Both Requests

If a redirect_uri was sent in the authorization request, the same value must be sent at the token request and the server must verify they match. This binds the code to the original client and redirect.

POST /token
grant_type=authorization_code
&code=SplxlOBeZ
&redirect_uri=https://app.example.com/callback   <-- must equal the one used earlier

A Validation Helper

Server-side exact-match check, no normalization shortcuts:

function isAllowed(requested, registeredList) {
  return registeredList.includes(requested);
}
// Reject anything not an exact, literal match.

Combine With PKCE and State

Strict redirect validation pairs with PKCE (so a stolen code is useless without the verifier) and the state parameter (to bind the response to the session). Defense in depth keeps codes safe even if one control slips.

Operational Tips

Keep the registered redirect list short and reviewed. Remove staging URLs from production clients, audit them regularly, and never let users dynamically add arbitrary redirect URIs.

Quick Check

Test your redirect URI security knowledge.

Recap

Securing redirect URIs is foundational:

  • Use exact-match registration; avoid wildcards and prefix matching.
  • Require HTTPS (loopback excepted) and reject odd fragments/params.
  • Re-validate redirect_uri at the token request.
  • Combine with PKCE and state for defense in depth.

Perguntas Frequentes

A aula “Protegendo URIs de redirecionamento” é grátis?

Sim — o texto completo de “Protegendo URIs de redirecionamento” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de OAuth2 & OpenID Connect Deep Dive, atualize para CoddyKit PRO. O curso de OAuth2 & OpenID Connect Deep Dive inclui 4 aulas no total.

O que vou aprender em “Protegendo URIs de redirecionamento”?

Aprenda por que a validação de URI de redirecionamento é fundamental para a segurança do OAuth2 e como impedir ataques de redirecionamento aberto e interceptação de códigos. Você pratica OAuth2 & OpenID Connect Deep Dive com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar OAuth2 & OpenID Connect Deep Dive?

Nenhuma experiência prévia é necessária. OAuth2 & OpenID Connect Deep Dive no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Protegendo URIs de redirecionamento”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de OAuth2 & OpenID Connect Deep Dive?

Sim. Cada aula de OAuth2 & OpenID Connect Deep Dive inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Segurança de Tokens de Acesso e Atualização
  2. Parâmetro State e CSRF
  3. Práticas Recomendadas para Tipos de Concessão
  4. Protegendo URIs de redirecionamento
← Voltar para OAuth2 & OpenID Connect Deep Dive