mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix: harden input validation, redirect safety, and error resilience
This commit is contained in:
8 files changed
+208
-97
No files matched your search
+9
-1
@@ -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 = {
|
||||
|
||||
Reference in new issue
Block a user