Security Risks of Using Localhost for Callback URL in Auth0

Overview

Using localhost as a callback URL in Auth0 applications creates significant security vulnerabilities in development and production environments. Localhost does not provide a verifiable first-party origin, which exposes the application to Domain Name System (DNS) hijacking and port hijacking. Remove localhost from the allowed callback URLs and configure a secure backend for the authorization code flow.

Applies To

  • Auth0
  • Security best practices
  • Localhost configuration
  • Callback URL security
  • Production and development environments

Solution

Why does Auth0 consider localhost insecure?

The primary reason to exclude localhost from the allowed callback URLs involves the user consent implementation. The localhost origin is not a verifiable first-party because any malicious application can run on localhost for a user. Auth0 always displays the consent dialogue for applications running on localhost or when localhost exists in the allowed callback URLs.

Domain Name System hijacking occurs via the hosts file.

An attacker can modify the local machine /etc/hosts file to redirect localhost to an attacker-controlled IP address. For example, an application uses the callback URL "http://localhost:1234/callback?code=<authorization_code>", and a legitimate application runs on localhost at port 1234. The attacker adds a new line to the hosts file to redirect the localhost traffic to a malicious IP address.

127.0.0.1    localhost
# Attacker adds this line:
7.7.7.7      localhost

When a user attempts to log in, the application sends the authorization code to the attacker-controlled IP 7.7.7.7 instead of the loopback address 127.0.0.1. The attacker intercepts the authorization code and gains access to the user account.

Port hijacking allows malicious applications to intercept authorization codes.

An attacker can identify the process running on localhost at a specific port, terminate the process, and replace it with a malicious application listening on the same port. The attacker executes the following sequence of actions to hijack the port and intercept the authorization code.

  1. Discover or infer the port number through process monitoring or common port scanning.
  2. Terminate the legitimate application.
  3. Start a malicious application listening on 127.0.0.1:1234.

When a user logs in, the application sends the authorization code directly to the malicious application instead of the legitimate application. Furthermore, the authorization code flow requires a secure backend. Localhost does not provide a secure backend because it operates in the same environment as the frontend.

Related References

Recommended content

No recommended content found...