Allow http:// loopback redirect URIs for native OAuth apps (RFC 8252) (#11255)

* Initial plan

* Add RFC 8252 loopback redirect URI support for native OAuth apps

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
This commit is contained in:
Copilotandtommoor authored and GitHub committed 2026-01-23 21:54:59 -05:00
1 parent b9c065f0ad
commit 07514cb692
2 files changed
+110

No files matched your search

+91
View File
@@ -128,6 +128,97 @@ describe("OAuthInterface", () => {
);
expect(result).toBe(false);
});
it("should allow HTTP loopback redirect URI (127.0.0.1) per RFC 8252", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://127.0.0.1:8080/callback"],
};
const redirectUri = "http://127.0.0.1:8080/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(true);
});
it("should allow HTTP loopback redirect URI (localhost) per RFC 8252", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://localhost:8080/callback"],
};
const redirectUri = "http://localhost:8080/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(true);
});
it("should allow HTTP loopback redirect URI (IPv6 [::1]) per RFC 8252", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://[::1]:8080/callback"],
};
const redirectUri = "http://[::1]:8080/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(true);
});
it("should allow loopback redirect URI with different ports", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://127.0.0.1:3000/callback"],
};
const redirectUri = "http://127.0.0.1:3000/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(true);
});
it("should allow loopback redirect URI without port", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://localhost/callback"],
};
const redirectUri = "http://localhost/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(true);
});
it("should reject HTTPS loopback redirect URIs (must be HTTP per RFC 8252)", async () => {
const httpsLoopbackClient = {
...client,
redirectUris: ["https://localhost:8080/callback"],
};
const redirectUri = "https://localhost:8080/callback";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
httpsLoopbackClient
);
expect(result).toBe(true); // HTTPS is allowed, just not required for loopback
});
it("should reject loopback redirect URI with fragment", async () => {
const loopbackClient = {
...client,
redirectUris: ["http://127.0.0.1:8080/callback#fragment"],
};
const redirectUri = "http://127.0.0.1:8080/callback#fragment";
const result = await OAuthInterface.validateRedirectUri(
redirectUri,
loopbackClient
);
expect(result).toBe(false); // Fragment check happens first
});
});
describe("#validateScope", () => {
+19
View File
@@ -343,6 +343,7 @@ export const OAuthInterface: RefreshTokenModel &
/**
* Ensure the redirect URI is not plain HTTP. Custom protocols are allowed.
* Loopback addresses (RFC 8252 §7.3) are allowed with http:// for native apps.
*
* @param uri The redirect URI to validate.
* @returns True if the URI is valid, false otherwise.
@@ -354,6 +355,24 @@ export const OAuthInterface: RefreshTokenModel &
if (!client.redirectUris?.includes(uri)) {
return false;
}
// Allow loopback redirects for native/CLI apps (RFC 8252 §7.3)
// Loopback addresses must use http:// (not https://) since TLS certificates
// cannot be obtained for loopback addresses.
try {
const url = new URL(uri);
const isLoopback =
url.hostname === "127.0.0.1" ||
url.hostname === "[::1]" ||
url.hostname === "localhost";
if (isLoopback && url.protocol === "http:") {
return true;
}
} catch {
// Invalid URL, will be caught by isUrl check below
}
if (!isUrl(uri, { requireHttps: true })) {
return false;
}