Repository navigation
fix: fix bugs #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix bugs #62
Changes from all commits
ee6bc0e
850bf5b
34a8638
31cbea0
61266c5
b7581b7
211d0f6
91e928b
e70a76c
7b6e78c
41b07b7
7416cd0
81ea4b0
6ebfde7
87b1486
d5797ac
cdfb812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { Elysia } from "elysia"; | ||
| import { fail } from "./response"; | ||
|
|
||
| const BYPASS_PATHS = new Set([ | ||
| "/api/auth/login", | ||
| "/api/auth/logout", | ||
| "/api/auth/refresh", | ||
| "/api/auth/me", | ||
| "/api/health", | ||
| "/api/github/callback", | ||
| "/api/github/webhook", | ||
| "/api/agents/register", | ||
| "/api/agents/p2p-sync", | ||
| ]); | ||
|
|
||
| export const authMiddleware = (app: Elysia) => | ||
| app.onBeforeHandle(async ({ request, set, path }) => { | ||
| if (BYPASS_PATHS.has(path)) return; | ||
|
|
||
| const cookie = request.headers.get("cookie") || ""; | ||
| const match = cookie.match(/(?:^|;\s*)dequel_session=([^;]+)/); | ||
| if (match) { | ||
| const { verifyAccessToken } = await import("../utils/auth"); | ||
| const payload = await verifyAccessToken(match[1]); | ||
| if (payload) return; | ||
| } | ||
|
|
||
| const authHeader = request.headers.get("authorization"); | ||
| if (authHeader?.startsWith("Bearer ")) { | ||
| const token = authHeader.slice(7); | ||
| if (token) { | ||
| const { validateApiKey } = await import("../db/repo"); | ||
| const { canPerformMethod, parsePermissions, requiredPermissionForMethod } = await import( | ||
| "../utils/permissions" | ||
| ); | ||
| const key = await validateApiKey(token); | ||
| if (!key) { | ||
| set.status = 401; | ||
| return fail("Invalid API key"); | ||
| } | ||
| if (!canPerformMethod(parsePermissions(key.permissions), request.method)) { | ||
| set.status = 403; | ||
| return fail(`API key is missing the ${requiredPermissionForMethod(request.method)} scope`); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| set.status = 401; | ||
| return fail("Authentication required"); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ import { | |
| setGithubIntegration, | ||
| } from "../../db/repo"; | ||
| import { orchestrator } from "../../orchestrator"; | ||
| import { config } from "../../utils/config"; | ||
| import { fail, ok } from "../response"; | ||
|
|
||
| const validateToken = async (token: string): Promise<boolean> => { | ||
|
|
@@ -249,7 +248,11 @@ export const githubRoutes = new Elysia({ prefix: "/github" }) | |
| } | ||
| const webhookUrl = `${publicUrl(request).origin}/api/github/webhook`; | ||
| const integration = await getGithubIntegration(); | ||
| const secret = integration?.webhookSecret || config.githubWebhookSecret; | ||
| const secret = integration?.webhookSecret || ""; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Reject hook creation when no webhook secret is configured. If the integration has no Return a 400 error with a clear message before creating the hook. Proposed fix--- "a/apps/api/src/api/github/index.ts"
+++ "b/apps/api/src/api/github/index.ts"
@@ -248,7 +248,11 @@
}
const webhookUrl = `${publicUrl(request).origin}/api/github/webhook`;
const integration = await getGithubIntegration();
- const secret = integration?.webhookSecret || "";
+ const secret = integration?.webhookSecret;
+ if (!secret) {
+ set.status = 400;
+ return fail("GitHub webhook secret is not configured");
+ }
try {
const hooks = await fetchGitHub(`/repos/${params.owner}/${params.repo}/hooks`, token);🤖 Prompt for AI Agents |
||
| if (!secret) { | ||
| set.status = 400; | ||
| return fail("Set a webhook secret in Settings before registering a webhook"); | ||
| } | ||
|
|
||
| try { | ||
| const hooks = await fetchGitHub(`/repos/${params.owner}/${params.repo}/hooks`, token); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Store and stop the Docker log follower.
stop()terminateschildProcess, but this spawn never assignschildProcess. After a client closes the runtime-log stream,docker logs --followcan continue running and retaining pipes. Assign the spawned child tochildProcess. If the request closed whileruntimeLogFollowerArgswas pending, stop the child immediately after spawning it.🤖 Prompt for AI Agents