-
Notifications
You must be signed in to change notification settings - Fork 0
fix: PR-review findings cleanup (security, cost, UX guards) #50
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
Changes from 14 commits
4023d3a
40c9d7b
99843e0
c107668
4b48433
6285ee3
5d06536
36e3d27
b503314
b77fb40
bb572e2
656e372
64a7624
c1488e9
779c5b1
e319a30
0fe7c44
19a9f89
792337f
52a3a45
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,36 @@ | ||
| import { describe, test, expect, vi } from "vitest"; | ||
| import { NextRequest } from "next/server"; | ||
|
|
||
| vi.mock("@/lib/csrf", () => ({ | ||
| getCsrfToken: vi.fn(() => "test-csrf-token"), | ||
| })); | ||
|
|
||
| import { POST } from "@/app/api/reports/[id]/deep-audit/route"; | ||
|
|
||
| describe("POST /api/reports/[id]/deep-audit β loopback + CSRF guard", () => { | ||
| test("rejects POST from spoofed Host header (uses nextUrl.hostname instead)", async () => { | ||
| const req = new NextRequest(new URL("http://203.0.113.5:3000/api/reports/1/deep-audit"), { | ||
| method: "POST", | ||
| headers: { host: "localhost", "x-checkapp-csrf": "test-csrf-token" }, | ||
| }); | ||
| const res = await POST(req, { params: Promise.resolve({ id: "1" }) }); | ||
| expect(res.status).toBe(403); | ||
| }); | ||
|
|
||
| test("rejects POST without CSRF token", async () => { | ||
| const req = new NextRequest(new URL("http://localhost:3000/api/reports/1/deep-audit"), { | ||
| method: "POST", | ||
| }); | ||
| const res = await POST(req, { params: Promise.resolve({ id: "1" }) }); | ||
| expect(res.status).toBe(403); | ||
| }); | ||
|
|
||
| test("rejects POST with wrong CSRF token", async () => { | ||
| const req = new NextRequest(new URL("http://localhost:3000/api/reports/1/deep-audit"), { | ||
| method: "POST", | ||
| headers: { "x-checkapp-csrf": "wrong" }, | ||
| }); | ||
| const res = await POST(req, { params: Promise.resolve({ id: "1" }) }); | ||
| expect(res.status).toBe(403); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ export function ClaimDrillDown({ finding }: Props) { | |
| > | ||
| {sanitizeText(s.title) || safeHref(s.url)} | ||
| </a> | ||
| {s.publishedDate && ( | ||
| {s.publishedDate && formatShortDate(s.publishedDate) && ( | ||
| <Badge variant="secondary" className="ml-2"> | ||
| {formatShortDate(s.publishedDate)} | ||
| </Badge> | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ export class FactCheckGroundedSkill implements Skill { | |
| } | ||
|
|
||
| const findings: Finding[] = []; | ||
| const perClaimCost = resolved.metadata?.costPerCheckUsd ?? 0.01; | ||
| const perClaimCost = resolved.metadata?.costPerCheckUsd ?? 0.04; | ||
| let costUsd = 0.001; | ||
|
|
||
| const groundedResults: GroundedClaimResult[] = []; | ||
|
|
@@ -233,14 +233,14 @@ async function fetchGroundedAssessment( | |
| model, | ||
| claimPreview: claim.slice(0, 160), | ||
| retriesLeft, | ||
| costUsd: 0.01, | ||
| costUsd: 0.04, | ||
| ...payload, | ||
|
Comment on lines
235
to
243
|
||
| }); | ||
|
|
||
| let response: Response; | ||
| try { | ||
| response = await fetch( | ||
| `${GEMINI_BASE_URL}/${model}:generateContent?key=${apiKey}`, | ||
| `${GEMINI_BASE_URL}/${model}:generateContent?key=${encodeURIComponent(apiKey)}`, | ||
| { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
|
|
||
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.
CI installs
agent-browserglobally without a version pin. This can make CI non-reproducible (sudden upstream releases breaking the lane) and increases supply-chain risk. Prefer pinning the version (e.g. installagent-browser@<known-good>), or add it as a devDependency and run it via a lockfile-managed runner (bunx/npx).