GitHub Is Rejecting `#` in Redirect URIs: Test Your Callback Before February 1

GitHub Is Rejecting `#` in Redirect URIs: Test Your Callback Before February 1

If your GitHub sign-in sends users back to something like https://app.example.com/#/callback, you have a deadline. From February 1, 2027, GitHub will reject OAuth authorization requests whose redirect URI contains a URL fragment. You also won't be able to register a callback URL that has one.

The fix is usually small: give OAuth a real path, handle it on your server, then send the user back into your hash-routed app. This guide shows how, and how to test it before production.

What GitHub is changing

GitHub announced the deprecation in its changelog on November 30, 2026. The essentials:

Question Answer
When is enforcement? February 1, 2027
Which apps? OAuth apps and GitHub Apps
What is rejected? Authorization requests with a # fragment in the redirect URI
What about registration? Callback URLs with fragments can no longer be registered
Which GitHub? github.com on Free, Team and Enterprise Cloud
Is GitHub Enterprise Server affected? No, it is outside this change

Until enforcement, GitHub shows a warning in the settings of affected apps and a caution message to users signing in through them.

Note that both the registered URL and the URL you send matter. A clean registration does not help if your code still appends a fragment to the redirect_uri parameter at runtime.

Why fragments are a problem in OAuth

A fragment is everything after the # in a URL. Browsers keep it on the client side and do not include it in the HTTP request. Your server never sees #/callback.

The OAuth 2.0 specification already ruled this out: RFC 6749, section 3.1.2 says the redirection endpoint URI must not include a fragment component. GitHub also cites a security reason: a fragment can be used to intercept an authorization code or token during a redirect.

Hash routing is why the pattern exists. Single-page apps on static hosting often use URLs like /#/settings so the server only ever has to serve index.html. That habit doesn't belong in an OAuth redirect URI.

You do not have to abandon hash routing. Only the OAuth redirect URI must be fragment-free. Your app can keep using /#/dashboard for its own screens.

Step 1: Find every affected redirect URI

Check three places.

GitHub settings. Under Settings → Developer settings, open each OAuth app and GitHub App and read every callback URL. Do this for your personal account and for each organization that owns apps. Include development, staging and forgotten preview apps.

Source and configuration. Search for the places that build the authorize URL or configure an auth library:

git grep -nE "redirect_uri|redirectUri|callbackURL|callbackUrl|CALLBACK_URL|REDIRECT_URI"

Also check what the repository does not contain: deployment environment variables, secrets managers, CI settings, and mobile or desktop builds already in users' hands.

Real traffic. Copy an authorize URL from your browser's network tab or your logs. Inside it, a fragment appears percent-encoded as %23. This script decodes the value for you:

// check-redirect.mjs
// Usage: node check-redirect.mjs "<authorize URL or redirect URI>"
const input = new URL(process.argv[2]);
const redirect = input.searchParams.get("redirect_uri") ?? input.href;

if (redirect.includes("#")) {
  console.error(`FAIL: fragment found in ${redirect}`);
  process.exit(1);
}
console.log(`OK: no fragment in ${redirect}`);

Quote the argument in your shell. A passing result covers only the URL you gave it, so run it for every sign-in entry point: login, account linking, "reconnect GitHub" buttons and CLI helpers. If an authorize URL has no redirect_uri at all, the script checks the authorize URL itself, and you need to inspect the registered callback instead. GitHub uses the first one by default.

Step 2: Move the callback to a real path

The goal looks like this:

URL
Before https://app.example.com/#/callback
After (OAuth redirect URI) https://app.example.com/auth/github/callback
After (where the user lands) https://app.example.com/#/dashboard

Handle the new path on the server. The token exchange needs your client secret, which must never ship in browser code, so a purely static front end needs a backend or serverless function here anyway.

Below is a compact Express example with state and PKCE, both of which GitHub's OAuth documentation strongly recommends. It requires Node.js 18 or later and npm install express.

// server.mjs
import express from "express";
import crypto from "node:crypto";

const { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, PUBLIC_ORIGIN } = process.env;
const REDIRECT_URI = `${PUBLIC_ORIGIN}/auth/github/callback`;
const pending = new Map(); // demo only: use a shared session store in production

const random = () => crypto.randomBytes(32).toString("base64url");
const sha256 = (v) => crypto.createHash("sha256").update(v).digest("base64url");
const cookie = (req, name) =>
  req.headers.cookie?.split("; ")
    .find((c) => c.startsWith(`${name}=`))?.slice(name.length + 1);

const app = express();

app.get("/auth/github/login", (req, res) => {
  const sid = random();
  const state = random();
  const verifier = random();
  pending.set(sid, { state, verifier, expires: Date.now() + 600_000 });

  res.cookie("oauth_sid", sid, {
    httpOnly: true, secure: true, sameSite: "lax", maxAge: 600_000,
  });

  const url = new URL("https://github.com/login/oauth/authorize");
  url.search = new URLSearchParams({
    client_id: GITHUB_CLIENT_ID,
    redirect_uri: REDIRECT_URI,
    state,
    code_challenge: sha256(verifier),
    code_challenge_method: "S256",
  });
  res.redirect(url.href);
});

app.get("/auth/github/callback", async (req, res) => {
  const { code, state, error } = req.query;
  if (error) return res.status(400).type("text").send(`GitHub error: ${error}`);

  const sid = cookie(req, "oauth_sid");
  const attempt = pending.get(sid);
  pending.delete(sid); // one attempt, one use

  if (!code || !attempt || attempt.state !== state || attempt.expires < Date.now()) {
    return res.status(400).type("text").send("Invalid or expired sign-in attempt");
  }

  const tokenRes = await fetch("https://github.com/login/oauth/access_token", {
    method: "POST",
    headers: { Accept: "application/json" },
    body: new URLSearchParams({
      client_id: GITHUB_CLIENT_ID,
      client_secret: GITHUB_CLIENT_SECRET,
      code,
      redirect_uri: REDIRECT_URI,
      code_verifier: attempt.verifier,
    }),
  });
  const token = await tokenRes.json();
  if (!token.access_token) {
    return res.status(502).type("text").send(`Token exchange failed: ${token.error}`);
  }

  const userRes = await fetch("https://api.github.com/user", {
    headers: {
      Authorization: `Bearer ${token.access_token}`,
      "User-Agent": "oauth-callback-demo",
    },
  });
  if (!userRes.ok) return res.status(502).type("text").send("User lookup failed");
  const user = await userRes.json();

  // Create your own application session for user.id here.
  console.log(`Signed in GitHub user ${user.id}`);
  res.redirect("/#/dashboard");
});

// Used by the wildcard test below. Never exchanges the code.
app.get("/auth/github/callback/probe", (req, res) => {
  res.type("text").send("Wildcard matching is ON for this callback URL");
});

app.get("/", (req, res) => res.type("text").send("App is running"));

app.listen(3000, "127.0.0.1", () => console.log("Listening on :3000"));

Replace the / route with your static front end. For a GitHub App, the same web flow applies, but permissions come from the app registration and not from OAuth scopes.

Three details matter:

  • Use one constant for the redirect URI. The authorize request and the token exchange should send the same value.
  • Redirect after the exchange. This takes code and state out of the address bar before your front end loads.
  • Keep the destination server-side. An unvalidated return URL creates an open redirect.

If your old front-end callback route read code from window.location, delete that logic. Otherwise two handlers may compete for a single-use code.

Check your static host and router

If one host serves both your SPA and your API, make sure /auth/* reaches the server before any catch-all rule. A fallback that returns index.html can produce a 200 OK that looks healthy while no exchange happens. Service workers can do the same thing by answering navigation requests from cache, so exclude /auth/ from your navigation fallback.

Step 3: Test on a stable HTTPS subdomain

A tunnel gives your local server a public HTTPS address, so you can exercise the real redirect, Secure cookies and proxy path without deploying.

Stability matters. If the hostname changes on every restart, you have to edit the GitHub registration each time. With InstaTunnel, you sign in and choose a subdomain on the free plan, and the URL stays the same between restarts. Free tunnel sessions last 24 hours.

Create a separate GitHub app for development so test settings never touch production. Register this callback URL, replacing acme-oauth with your own subdomain:

https://acme-oauth.instatunnel.my/auth/github/callback

Disable wildcard matching for it. Then start the app:

export GITHUB_CLIENT_ID="your_dev_client_id"
export GITHUB_CLIENT_SECRET="your_dev_client_secret"
export PUBLIC_ORIGIN="https://acme-oauth.instatunnel.my"
node server.mjs

In a second terminal, install the CLI, sign in and open the tunnel:

npm install -g instatunnel
instatunnel auth login -e you@example.com
instatunnel auth set-key "it_your_api_key"
instatunnel 3000 --subdomain acme-oauth

Now visit https://acme-oauth.instatunnel.my/auth/github/login. Start on the tunnel hostname, not localhost. The cookie set at login belongs to the host that set it, so beginning on localhost and returning to the tunnel fails the state check.

A tunnel URL is public. Use development credentials and test data, and stop the tunnel when you finish. Keep authorization codes, tokens and cookies out of screenshots and shared logs.

The test matrix

Test How to run it Expected result
Fresh sign-in Private window, start at /auth/github/login Lands on /#/dashboard
Clean redirect URI Run check-redirect.mjs on the authorize URL OK
Server route wins Open /auth/github/callback with no parameters 400 from your handler, not your SPA
Wrong state Open the callback with ?code=x&state=wrong 400, no token exchange
User cancels Click Cancel on the consent screen (not yet authorized) Handled access_denied error
Replay Request the used callback URL again 400
Other entry points Account linking, reconnect, app installation Same fragment-free callback behavior

To see the consent screen again, revoke the app's authorization in your GitHub account settings.

The installation case is easy to miss. If a GitHub App has Request user authorization (OAuth) during installation enabled, GitHub sends users to the first callback URL in the list. A passing login button proves nothing about that path. Install-initiated redirects also do not carry the state your login route created, so the strict handler above rejects them. Handle that flow deliberately, for example by sending the user through your normal login route to start a verifiable attempt.

Step 4: Check wildcard matching

This is a separate setting from the fragment change, but you should review it while you have the page open.

On August 14, 2026, GitHub announced support for up to 10 redirect URIs on OAuth apps, plus per-URL wildcard matching for OAuth apps and GitHub Apps. The announcement warned that apps with only one registered redirect URI had been wildcard-enabled since creation.

The current documentation is more precise: apps that had a single callback URL before August 3, 2026 have wildcard matching enabled for that URL. According to GitHub, this includes all OAuth apps created before that date and some GitHub Apps.

With wildcard matching on, subdomains and subdirectories of the callback URL are accepted. The port must still match, and the path must be the registered path or below it. For a registered https://example.com/path:

Redirect URI Result
https://example.com/path/subdir/other Match
https://oauth.example.com/path Match
https://example.com/bar Fail
https://example.com:8080/path Fail
https://example.org Fail

The danger is that an authorization code can be delivered to any matching location. An abandoned subdomain or an open redirect under your callback path becomes much more serious. Turn wildcard matching off unless you truly need it and control every possible subdomain and path.

Be especially careful if your migration leaves a broad registration such as https://app.example.com/ with wildcard matching on. Register the full callback path.

Prove the setting with a negative test

Do not rely on memory. With the server and tunnel running, paste this into your browser, using your development client ID:

https://github.com/login/oauth/authorize?client_id=YOUR_CLIENT_ID&state=probe&redirect_uri=https%3A%2F%2Facme-oauth.instatunnel.my%2Fauth%2Fgithub%2Fcallback%2Fprobe
  • If you reach the probe page, wildcard matching is on.
  • If you return to your registered callback with redirect_uri_mismatch, the subdirectory was rejected, as it should be with wildcard matching off.

The probe stays on a hostname and server you are already using. Avoid probing with a subdomain you don't control. In multi-callback apps, remember that the error goes to a registered callback, which may not be the one you are testing.

Step 5: Roll out without breaking sign-in

Because apps can hold several callback URLs, you can usually migrate without a hard cutover:

  1. Deploy the new server route.
  2. Add the fragment-free URL in GitHub, with wildcard matching off.
  3. Update your code to send the new URL explicitly as redirect_uri.
  4. Verify production sign-in from a fresh browser session.
  5. Make the new URL first in the list if any flow relies on the default. If you cannot reorder, edit the first entry.
  6. Watch for requests that still use the old value.
  7. Remove the old fragment URL before February 1.

Installed clients need extra time. If a desktop or mobile release has the old redirect URI built in, it needs an update before enforcement. Ship early and tell users.

Avoid a rollback that restores the fragment URL. It would stop working on February 1. Keep your recovery build on the new path instead.

If sign-in fails with redirect_uri_mismatch, compare scheme, host, port and path with the registration. GitHub's temporary code expires after 10 minutes, so restart the flow instead of refreshing an old callback.

FAQ

Do I have to remove hash routing from my app?

No. Only the OAuth redirect URI must have no fragment. After the server completes sign-in, it can redirect to a hash route.

Will existing access tokens stop working?

The announcement describes rejecting authorization requests and fragment registrations. It does not announce revocation of existing tokens. Users who need to authorize again will hit the new rule.

Does removing the fragment disable wildcard matching?

Don't assume so. Check the toggle on every callback URL and run the negative test.

Don't wait for the deadline

February 1, 2027 is a Monday. Aim to finish in early January, so a missed environment variable or slow client release doesn't become a start-of-week sign-in outage.

Sources


Originally published at https://instatunnel.my/blog/github-is-rejecting-in-redirect-uris-test-your-callback-before-february-1

Comments