fix: harden input validation, redirect safety, and error resilience

This commit is contained in:
RhenCloud committed 2026-08-02 23:56:58 +08:00
1 parent d419b9c940
commit bd33fa6835
8 files changed
+208 -97

No files matched your search

+9 -1
View File
@@ -23,11 +23,19 @@ function generateRandomHex(length: number): string {
.join("");
}
function safeRedirectPath(value: string | undefined): string {
if (!value) return "/";
if (!value.startsWith("/")) return "/";
if (value.startsWith("//")) return "/";
if (/^\/\\/.test(value)) return "/";
return value;
}
export function createOAuthRoutes(): Hono<{ Bindings: Env }> {
const app = new Hono<{ Bindings: Env }>();
app.get("/github", async (c) => {
const redirectTo = c.req.query("redirect") ?? "/";
const redirectTo = safeRedirectPath(c.req.query("redirect"));
const state = generateRandomHex(16);
const pending: PendingState = {