fix(settings): защищать восстановление базы от повторов и смены контекста

This commit is contained in:
Denozordec committed 2026-10-03 16:52:02 +07:00
1 parent 92b65a30ce
commit 57293479d1
13 files changed
+148 -188

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
import assert from "node:assert/strict"
import {test} from "node:test"
import {NextRequest} from "next/server"
import {proxyBackendRequest} from "./proxy-backend-request"
test("same-origin backup proxy preserves bytes, filename and secondary outcome metadata",async()=>{
const original=globalThis.fetch;try{
const outcome=encodeURIComponent(JSON.stringify({eventError:"audit unavailable"}))
globalThis.fetch=async()=>new Response("PGDMPfixture",{headers:{"Content-Type":"application/octet-stream","Content-Disposition":"attachment; filename=fixture.dump","X-System-Database-Outcome":outcome,"X-Internal-Secret":"fixture"}})
const response=await proxyBackendRequest(new NextRequest("http://app.test/api/system/database/backup"),"/api/system/database/backup",{method:"GET",forwardRequestBody:false})
assert.equal(await response.text(),"PGDMPfixture");assert.equal(response.headers.get("Content-Disposition"),"attachment; filename=fixture.dump");assert.equal(response.headers.get("X-System-Database-Outcome"),outcome);assert.equal(response.headers.get("X-Internal-Secret"),null)
}finally{globalThis.fetch=original}
})
+2
View File
@@ -38,6 +38,8 @@ export async function proxyBackendRequest(
const contentDisposition = upstream.headers.get("Content-Disposition")
if (contentType) responseHeaders.set("Content-Type", contentType)
if (contentDisposition) responseHeaders.set("Content-Disposition", contentDisposition)
const databaseOutcome = upstream.headers.get("X-System-Database-Outcome")
if (databaseOutcome) responseHeaders.set("X-System-Database-Outcome", databaseOutcome)
return new Response(upstream.body, {
status: upstream.status,