fix(security): SSRF guard on search baseUrl, default-password remote login, and request-details redaction

- resolveBaseUrl() rejects client-supplied non-public baseUrls via assertPublicUrl (SSRF guard on /v1/search)
- fresh-install remote login with default password returns 403 without issuing a JWT
- /api/usage/request-details redacts request/providerRequest/providerResponse/response payloads
- declare chalk and prop-types in package.json (used but previously undeclared)
This commit is contained in:
zmf
2026-08-13 11:50:00 +07:00
committed by decolua
parent 70ba0024b0
commit 8a527fec91
6 changed files with 167 additions and 5 deletions

View File

@@ -54,15 +54,36 @@ export async function POST(request) {
if (isValid) {
recordSuccess(ip);
const cookieStore = await cookies();
await setDashboardAuthCookie(cookieStore, request);
// Default password still in use on a remote client → force a password
// change before the dashboard is exposed remotely (keeps local UX intact).
const mustChangePassword =
!storedHash && !process.env.INITIAL_PASSWORD && !isLocalRequest(request);
return NextResponse.json({ success: true, mustChangePassword }, { headers: NO_STORE_HEADERS });
if (mustChangePassword) {
// Do NOT issue a session token: a fresh install's default password is
// public knowledge ("123456"), so handing out a valid JWT would let any
// remote attacker authenticate and (e.g.) PATCH /api/settings to disable
// authentication entirely (CVE-2026-56679 class). Require the password
// to be changed first.
//
// NOTE: this intentionally leaves no remote self-service password-change
// path — the change-password flow (PATCH /api/settings) requires a JWT,
// which we deliberately withhold. A remote fresh-install user must either
// change the password from the local machine or set INITIAL_PASSWORD
// before first launch. This is a deliberate security trade-off, not an
// oversight: issuing any credential before the default password is
// rotated re-opens the exact attack chain this branch closes.
return NextResponse.json(
{ success: false, error: "Default password must be changed before remote access. Change it from the local machine (or set INITIAL_PASSWORD).", mustChangePassword },
{ status: 403, headers: NO_STORE_HEADERS }
);
}
const cookieStore = await cookies();
await setDashboardAuthCookie(cookieStore, request);
return NextResponse.json({ success: true, mustChangePassword: false }, { headers: NO_STORE_HEADERS });
}
const { remainingBeforeLock } = recordFail(ip);

View File

@@ -47,8 +47,23 @@ export async function GET(request) {
if (endDate) filter.endDate = endDate;
const result = await getRequestDetails(filter);
return NextResponse.json(result);
// Redact conversation payloads: the stored details include full request
// bodies (user prompts, tool calls) and provider responses. Returning them
// wholesale lets any dashboard-authenticated user (or, if requireLogin is
// disabled, anyone) read every user's conversation history. Keep the
// metadata (model, tokens, latency, status) but drop message content.
const redactedDetails = (result.details || []).map((d) => {
const redacted = { ...d };
for (const key of ["request", "providerRequest", "providerResponse", "response"]) {
if (redacted[key] !== undefined) {
redacted[key] = { redacted: true };
}
}
return redacted;
});
return NextResponse.json({ ...result, details: redactedDetails });
} catch (error) {
console.error("[API] Failed to get request details:", error);
return NextResponse.json(