Tutorials
GitHub OAuth Redirect URI Fragments: How to Fix Your Authentication Flow
GitHub is removing support for OAuth redirect URIs containing URL fragments. Learn how to update callback URLs, preserve hash-based routing, and prevent authentication failures before February 2027.
A React application uses GitHub for authentication and HashRouter for navigation. Its callback URL looks something like this:
const redirectUri =
"https://example.com/#/auth/github/callback";
The application has been using this configuration for some time. Nothing in its source code has changed, yet GitHub begins displaying a warning during authorization.
On November 30, 2026, GitHub announced the removal of support for OAuth redirect URIs containing URL fragments.
Starting February 1, 2027, authorization requests using such URLs will be rejected. Developers will also lose the ability to register callback URLs containing fragments.
The change affects both OAuth Apps and GitHub Apps on GitHub.com, including Free, Team, and Enterprise Cloud plans. GitHub Enterprise Server is excluded from this particular announcement.
For applications relying on hash-based routing, the solution requires a small but meaningful distinction between the OAuth callback and the page users visit after signing in.
Why URL fragments are a problem
Consider the following URL:
https://example.com/auth/callback?source=github#dashboard
It contains several components:
| Component | Value |
|---|---|
| Origin | https://example.com |
| Path | /auth/callback |
| Query | ?source=github |
| Fragment | #dashboard |
The fragment behaves differently from the path and query.
When the browser requests this URL, it sends the path and query to the server. The fragment remains on the browser side.
You can inspect these components using JavaScript:
const url = new URL(
"https://example.com/auth/callback?source=github#dashboard"
);
console.log(url.pathname);
// /auth/callback
console.log(url.search);
// ?source=github
console.log(url.hash);
// #dashboard
This behavior is particularly useful for client-side routing, where navigation does not necessarily require another request to the server.
OAuth redirect URIs, however, have different requirements.
RFC 6749, section 3.1.2, specifies that a redirection endpoint must not contain a fragment component.
The restriction has existed since the original OAuth 2.0 specification was published in 2012.
GitHub is now enforcing it, citing security risks involving the interception of authorization codes or tokens during redirects.
1. Find the affected callback URLs
Start by checking the callback URL registered in your application’s GitHub settings.
Open GitHub Developer Settings, select your OAuth App or GitHub App, and inspect its authorization callback configuration.
![CONTENT]: github dev setting oauth apps](/media/94b19b8c-7ed6-4884-8516-9d545cba26a8.webp)
The following examples illustrate which URLs are affected:
| Callback URL | Fragment restriction |
|---|---|
https://example.com/callback |
Passes |
https://example.com/auth/github |
Passes |
https://example.com/callback?source=github |
Passes |
https://example.com/#/callback |
Rejected |
https://example.com/callback#github |
Rejected |
https://example.com/callback# |
Contains an empty fragment |
Passing the fragment check does not guarantee that GitHub accepts the entire URL. Other callback registration and matching requirements still apply.
The application’s source code also needs inspection.
A registered callback URL might be correct while the application dynamically constructs an incompatible redirect_uri.
Search for references to:
redirect_uriredirectUricallbackUrlGITHUB_CALLBACK_URLwindow.location.hash
Environment variables and authentication-library configuration deserve attention as well.
2. Separate the callback from the application route
Suppose a React application currently uses this callback:
const redirectUri =
"https://example.com/#/auth/github/callback";
Replace it with a fragment-free endpoint:
const redirectUri =
"https://example.com/auth/github/callback";
Update the registered callback URL in GitHub and the corresponding application configuration.
If your application supplies redirect_uri during the authorization-code exchange, use the same callback URI that was sent in the initial authorization request.
There is one potential problem with this migration.
Removing the fragment changes where the browser actually sends its request.
Previously, the server may have received a request for /, allowing React to interpret the remaining fragment. Now the server receives a request for /auth/github/callback.
That endpoint must exist.
Otherwise, fixing the OAuth configuration may simply replace an authorization failure with an HTTP 404.
For a server-backed application, the callback can be handled directly by the backend. A static SPA may instead need a hosting rewrite and a dedicated mechanism for processing the callback securely.
3. Can React applications still use HashRouter?
Yes.
GitHub is restricting OAuth redirect URIs, not the URLs your application uses for internal navigation.
You can continue using HashRouter:
import {
HashRouter,
Route,
Routes,
} from "react-router-dom";
export function App() {
return (
<HashRouter>
<Routes>
<Route
path="/dashboard"
element={<Dashboard />}
/>
<Route
path="/settings"
element={<Settings />}
/>
</Routes>
</HashRouter>
);
}
The application can still display routes such as:
https://example.com/#/dashboard
The difference is when that URL is used.
GitHub should redirect the user to an ordinary callback endpoint. Once your application has validated the authorization response, exchanged the authorization code, and established its session, it can redirect the browser to the hash-based route.
flowchart TD
A["React application"] --> B["GitHub authorization"]
B --> C["/auth/github/callback"]
C --> D{"Valid state and code?"}
D -->|No| E["Reject authentication"]
D -->|Yes| F["Exchange authorization code"]
F --> G["Establish application session"]
G --> H["/#/dashboard"]
Notice where the fragment appears.
It belongs to the final application navigation, after OAuth processing has completed.
It is no longer part of the redirect URI registered with GitHub.
This means a project does not need to migrate its entire routing architecture merely to comply with the new restriction.
4. Validate redirect URIs with TypeScript
An incompatible callback URL can be detected before the application sends users to GitHub.
export function validateRedirectUri(uri: string): string {
const url = new URL(uri);
if (url.href.includes("#")) {
throw new Error(
"OAuth redirect URI must not contain a fragment."
);
}
return uri;
}
Why check url.href rather than url.hash?
Consider a URL ending with an empty fragment:
const url = new URL(
"https://example.com/callback#"
);
console.log(url.hash);
// ""
console.log(url.href.includes("#"));
// true
The hash property returns an empty string, even though the fragment delimiter remains present in the serialized URL.
Checking href detects that case as well.
An encoded hash is different:
const url = new URL(
"https://example.com/callback?value=%23"
);
console.log(url.href.includes("#"));
// false
Here, %23 represents data inside the query parameter. It does not introduce a URL fragment.
The distinction can be covered with a small Vitest test:
import { describe, expect, it } from "vitest";
import { validateRedirectUri } from "./oauth";
describe("OAuth redirect URI validation", () => {
it.each([
"https://example.com/callback",
"https://example.com/callback?value=%23",
])("accepts %s", (uri) => {
expect(validateRedirectUri(uri)).toBe(uri);
});
it.each([
"https://example.com/#/callback",
"https://example.com/callback#dashboard",
"https://example.com/callback#",
])("rejects %s", (uri) => {
expect(() => validateRedirectUri(uri)).toThrow();
});
});
This helper validates the specific fragment restriction. It is not a complete OAuth redirect URI security validator.
Production applications should use explicitly configured, trusted callback URLs rather than accepting arbitrary addresses from users.
5. Preserve the destination using OAuth state
What happens if a user begins authorization from a particular page?
For example:
https://example.com/#/settings
Previously, an application might have attempted to include that destination in its OAuth callback URL.
There is no need to do that.
The application can store the intended destination alongside its OAuth state value.
The state parameter should be an unpredictable value associated with the user’s authorization attempt. It helps the application establish that the callback belongs to the authentication flow it originally initiated.
A server-side implementation might represent that information as follows:
type OAuthAttempt = {
state: string;
returnTo: "dashboard" | "settings";
expiresAt: number;
};
The application stores this record in a session or another suitable temporary storage mechanism before redirecting the user to GitHub.
When GitHub returns the authorization response, the server checks the returned state against the stored value.
An invalid, expired, or previously consumed state should not be accepted.
GitHub also supports PKCE using the S256 challenge method. When implementing PKCE, retain the original code verifier securely until the authorization-code exchange.
Once authorization succeeds, the stored destination can be translated into a known application route:
const destinations = {
dashboard: "/#/dashboard",
settings: "/#/settings",
} as const;
type Destination = keyof typeof destinations;
export function getPostLoginUrl(
destination: Destination
): string {
return destinations[destination];
}
Using a fixed set of destinations avoids treating an arbitrary URL supplied by the browser as a trusted redirect target.
Simply storing an external URL in state and redirecting users to it afterward could introduce an open redirect vulnerability.
The authorization callback should also keep client secrets and token exchanges on the backend, rather than exposing confidential credentials in a React bundle.
The examples here illustrate destination handling, not a complete OAuth implementation.
6. Verify the migration before February 1
Changing the registered callback URL is only one part of the migration.
Check that the application sends the new URI to GitHub, that the callback endpoint responds correctly, and that the browser reaches its intended destination after authorization.
Test both successful authorization and cases where the user declines access.
An invalid state value should also be rejected without creating an authenticated session.
If the application uses separate development, staging, and production OAuth configurations, inspect each independently.
A production callback may be correct while a development environment still relies on hash-based routing.
Finally, check the GitHub App or OAuth App settings for the deprecation warning.
Applications already using fragment-free callback URLs do not need to change their routing solely because of this announcement.
The February 2027 restriction concerns the address GitHub uses during authorization. It does not prevent an authenticated application from using fragments afterward.
For most affected React applications, that is the central distinction.
The OAuth callback handles authorization. The application router handles navigation.
Both can remain part of the same authentication flow without sharing the same URL.