feat(ui): add agent-configs page backed by SGP#274
Open
declan-scale wants to merge 1 commit into
Open
Conversation
Adds an agent-configs page that lists/creates SGP agent configs through a server-side Next.js route handler and a thin SGP REST client, plus a sidebar nav entry to reach it. The route forwards SGP auth headers from the request and falls back to server-side SGP_API_KEY / SGP_ACCOUNT_ID env vars when the browser supplies none, so the UI-driven flow authenticates without a logged-in SGP session. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines
+19
to
+28
|
|
||
| export async function GET(request: Request) { | ||
| if (!isSGPConfigured()) return notConfigured(); | ||
| try { | ||
| const data = await listAgentConfigs(request); | ||
| return NextResponse.json(data); | ||
| } catch (error) { | ||
| return forwardError(error); | ||
| } | ||
| } |
There was a problem hiding this comment.
Unauthenticated access uses server-side SGP credentials
sgpHeadersFromRequest falls back to SGP_API_KEY / SGP_ACCOUNT_ID when no browser credentials are forwarded, so any unauthenticated request to this route (GET or POST) will silently execute against SGP under the server's API key. If this Next.js server is reachable by more than one person (a shared dev box, a staging deploy), any visitor can enumerate or create agent configs without holding their own SGP session. Consider adding a minimal check — e.g. 401 when both the forwarded x-api-key/authorization/cookie are absent AND SGP_API_KEY is set — so the fallback only activates for explicitly allowed callers.
Prompt To Fix With AI
This is a comment left during a code review.
Path: agentex-ui/app/api/agent-configs/route.ts
Line: 19-28
Comment:
**Unauthenticated access uses server-side SGP credentials**
`sgpHeadersFromRequest` falls back to `SGP_API_KEY` / `SGP_ACCOUNT_ID` when no browser credentials are forwarded, so any unauthenticated request to this route (GET or POST) will silently execute against SGP under the server's API key. If this Next.js server is reachable by more than one person (a shared dev box, a staging deploy), any visitor can enumerate or create agent configs without holding their own SGP session. Consider adding a minimal check — e.g. 401 when both the forwarded `x-api-key`/`authorization`/`cookie` are absent AND `SGP_API_KEY` is set — so the fallback only activates for explicitly allowed callers.
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an agent-configs page that lists/creates SGP agent configs through a server-side Next.js route handler and a thin SGP REST client, plus a sidebar nav entry to reach it. The route forwards SGP auth headers from the request and falls back to server-side SGP_API_KEY / SGP_ACCOUNT_ID env vars when the browser supplies none, so the UI-driven flow authenticates without a logged-in SGP session.
Greptile Summary
Adds an
/agent-configsUI page backed by a new thin SGP REST client and a Next.js route handler that forwards browser auth headers to SGP, falling back to server-side env-var credentials when none are present. A sidebar button inTaskSidebarHeaderprovides navigation to the new page.sgp-client.ts: New server-side wrapper around/v5/agent_configs; exposes list, create, get, update, delete — only list and create are wired to the route handler today./api/agent-configsroute: Proxies SGP requests and validates required POST fields; the credential fallback toSGP_API_KEYhas no caller authentication gate, so any network-reachable request executes under the server's identity.agent-configs/page.tsx: Client-side page with per-card launch state (message + agent name), a collapsible create form, and post-launch redirect to the main task view.Confidence Score: 3/5
The route handler's credential-fallback design lets any unauthenticated caller act under the server's SGP API key; worth resolving before deploying to any shared environment.
The core logic is straightforward and the client-side page is well-structured. The main concern is the route handler: with SGP_API_KEY set, unauthenticated GET and POST requests to /api/agent-configs will execute against SGP under the server's credentials, with no check on the caller's identity.
agentex-ui/app/api/agent-configs/route.ts — the credential fallback path needs a caller-identity check before this is deployed to any shared server.
Security Review
agentex-ui/app/api/agent-configs/route.ts): When no browser auth headers are present, both the GET and POST handlers fall back to the server'sSGP_API_KEYwithout any check on who the caller is. Any user who can reach the Next.js server can list or create SGP agent configs under the server's identity.Important Files Changed
Sequence Diagram
sequenceDiagram participant Browser participant NextRoute as /api/agent-configs (Next.js) participant SGPClient as sgp-client.ts participant SGP as SGP API Browser->>NextRoute: GET /api/agent-configs (with or without auth cookies) NextRoute->>SGPClient: listAgentConfigs(request) SGPClient->>SGPClient: sgpHeadersFromRequest() forward cookie/auth if present else use SGP_API_KEY env var SGPClient->>SGP: GET /v5/agent_configs SGP-->>SGPClient: "{ items: [...] }" SGPClient-->>NextRoute: AgentConfigListResponse NextRoute-->>Browser: JSON response Browser->>NextRoute: POST /api/agent-configs (config body) NextRoute->>SGPClient: createAgentConfig(request, body) SGPClient->>SGP: POST /v5/agent_configs SGP-->>SGPClient: AgentConfig SGPClient-->>NextRoute: created config NextRoute-->>Browser: 201 JSON Browser->>Browser: launchWithConfig() Browser->>AgentexAPI: agentRPCNonStreaming task/create AgentexAPI-->>Browser: "{ id: taskId }" Browser->>AgentexAPI: agentRPCNonStreaming event/send AgentexAPI-->>Browser: ok Browser->>Browser: "router.push(/?agent_name=...&task_id=...)"Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "feat(ui): add agent-configs page backed ..." | Re-trigger Greptile