fix(security): re-auth on DB export/import + SSRF guard on web fetch
- /api/settings/database now requires current password (header for GET, body for POST) in addition to session; CLI-token requests exempt - add verifyDashboardPassword helper reusing login bcrypt check - profile UI prompts password via modal before export/import - /v1/web/fetch rejects internal/private/metadata targets via assertPublicUrl Refs GHSA-qvfm-67h2-2qfx, GHSA-qj3v-64wj-q825 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e6bac77696
commit
0c7c9de00a
5 files changed
+150
-13
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Card, Button, Toggle, Input } from "@/shared/components";
|
||||
import { ConfirmModal } from "@/shared/components/Modal";
|
||||
import Modal, { ConfirmModal } from "@/shared/components/Modal";
|
||||
import LanguageSwitcher from "@/shared/components/LanguageSwitcher";
|
||||
import { useTheme } from "@/shared/hooks/useTheme";
|
||||
import { cn } from "@/shared/utils/cn";
|
||||
@@ -34,6 +34,8 @@ export default function ProfilePage() {
|
||||
const [passLoading, setPassLoading] = useState(false);
|
||||
const [dbLoading, setDbLoading] = useState(false);
|
||||
const [dbStatus, setDbStatus] = useState({ type: "", message: "" });
|
||||
const [dbAuth, setDbAuth] = useState({ open: false, mode: "", password: "" });
|
||||
const pendingImportRef = useRef(null);
|
||||
const [oidcForm, setOidcForm] = useState({
|
||||
authMode: "password",
|
||||
oidcIssuerUrl: "",
|
||||
@@ -471,11 +473,13 @@ export default function ProfilePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportDatabase = async () => {
|
||||
const handleExportDatabase = async (password) => {
|
||||
setDbLoading(true);
|
||||
setDbStatus({ type: "", message: "" });
|
||||
try {
|
||||
const res = await fetch("/api/settings/database");
|
||||
const res = await fetch("/api/settings/database", {
|
||||
headers: { "x-9r-password": password },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || "Failed to export database");
|
||||
@@ -502,13 +506,19 @@ export default function ProfilePage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportDatabase = async (event) => {
|
||||
const handleImportDatabase = (event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (importFileRef.current) importFileRef.current.value = "";
|
||||
if (!file) return;
|
||||
|
||||
setDbLoading(true);
|
||||
pendingImportRef.current = file;
|
||||
setDbStatus({ type: "", message: "" });
|
||||
setDbAuth({ open: true, mode: "import", password: "" });
|
||||
};
|
||||
|
||||
const runImportDatabase = async (password) => {
|
||||
const file = pendingImportRef.current;
|
||||
if (!file) return;
|
||||
setDbLoading(true);
|
||||
try {
|
||||
const raw = await file.text();
|
||||
const payload = JSON.parse(raw);
|
||||
@@ -516,7 +526,7 @@ export default function ProfilePage() {
|
||||
const res = await fetch("/api/settings/database", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
body: JSON.stringify({ ...payload, password }),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
@@ -529,13 +539,19 @@ export default function ProfilePage() {
|
||||
} catch (err) {
|
||||
setDbStatus({ type: "error", message: err.message || "Invalid backup file" });
|
||||
} finally {
|
||||
if (importFileRef.current) {
|
||||
importFileRef.current.value = "";
|
||||
}
|
||||
pendingImportRef.current = null;
|
||||
setDbLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Confirm password modal, then run export or import.
|
||||
const handleDbAuthConfirm = async () => {
|
||||
const { mode, password } = dbAuth;
|
||||
setDbAuth({ open: false, mode: "", password: "" });
|
||||
if (mode === "export") await handleExportDatabase(password);
|
||||
else if (mode === "import") await runImportDatabase(password);
|
||||
};
|
||||
|
||||
const observabilityEnabled = settings.enableObservability === true;
|
||||
|
||||
const handleShutdown = async () => {
|
||||
@@ -608,7 +624,7 @@ export default function ProfilePage() {
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon="download"
|
||||
onClick={handleExportDatabase}
|
||||
onClick={() => setDbAuth({ open: true, mode: "export", password: "" })}
|
||||
loading={dbLoading}
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
@@ -1135,6 +1151,35 @@ export default function ProfilePage() {
|
||||
variant="danger"
|
||||
loading={isShuttingDown}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
isOpen={dbAuth.open}
|
||||
onClose={() => setDbAuth({ open: false, mode: "", password: "" })}
|
||||
title="Confirm Password"
|
||||
size="sm"
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" onClick={() => setDbAuth({ open: false, mode: "", password: "" })} disabled={dbLoading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="primary" onClick={handleDbAuthConfirm} loading={dbLoading} disabled={!dbAuth.password}>
|
||||
Confirm
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<p className="text-text-muted mb-3 text-sm">
|
||||
Enter your current password to {dbAuth.mode === "export" ? "export" : "import"} the database.
|
||||
</p>
|
||||
<Input
|
||||
type="password"
|
||||
value={dbAuth.password}
|
||||
onChange={(e) => setDbAuth((s) => ({ ...s, password: e.target.value }))}
|
||||
onKeyDown={(e) => { if (e.key === "Enter" && dbAuth.password) handleDbAuthConfirm(); }}
|
||||
placeholder="Current password"
|
||||
autoFocus
|
||||
/>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user