Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+9
-2
@@ -14,14 +14,18 @@
|
||||
* possible here. Audit-LOG-row retention is handled by the existing worker job
|
||||
* (`audit-retention`).
|
||||
*/
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
import { getDbClient } from "@hivegrid/db/client.server";
|
||||
import { createAuditEvent } from "@hivegrid/db/audit-events.server";
|
||||
import { loadAuditVerificationContext } from "@hivegrid/db/audit-chain-checkpoint.server";
|
||||
import { putBufferAsFile, resolveStorageBucket, hasStorageCredentials } from "~/utils/integrations/storageService";
|
||||
import { createMediaDownloadUrl } from "~/utils/integrations/mediaSigning.server";
|
||||
import {
|
||||
AUDIT_EXPORT_MAX_ROWS,
|
||||
buildAuditExportWhere,
|
||||
computeAuditIntegritySummary,
|
||||
hasAuditExportPrefixFilters,
|
||||
renderAuditExportCsv,
|
||||
renderAuditExportNdjson,
|
||||
type AuditExportFilters,
|
||||
@@ -93,14 +97,17 @@ export async function runAuditExportToStorage(input: AuditExportToStorageInput):
|
||||
take: AUDIT_EXPORT_MAX_ROWS,
|
||||
})) as unknown as AuditExportRow[];
|
||||
|
||||
const integrity = computeAuditIntegritySummary(rows);
|
||||
const verification = await loadAuditVerificationContext(db as never, rows, {
|
||||
allowPartialPrefix: hasAuditExportPrefixFilters(input.filters),
|
||||
});
|
||||
const integrity = computeAuditIntegritySummary(rows, verification);
|
||||
const body = input.format === "ndjson" ? renderAuditExportNdjson(rows, integrity) : renderAuditExportCsv(rows, integrity);
|
||||
const ext = input.format === "ndjson" ? "ndjson" : "csv";
|
||||
const contentType = input.format === "ndjson" ? "application/x-ndjson; charset=utf-8" : "text/csv; charset=utf-8";
|
||||
|
||||
const scope = input.tenantId ?? "platform";
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||
const rand = Math.random().toString(36).slice(2, 10);
|
||||
const rand = randomBytes(8).toString("hex");
|
||||
const filename = `audit-export-${scope}-${stamp}.${ext}`;
|
||||
const key = `audit-exports/${scope}/${stamp}-${rand}.${ext}`;
|
||||
|
||||
|
||||
+15
-4
@@ -7,10 +7,11 @@ function makeRequest(headers: Record<string, string>): Request {
|
||||
}
|
||||
|
||||
describe("extractWebActorIp", () => {
|
||||
it("prefers cf-connecting-ip > x-real-ip > x-forwarded-for first hop", () => {
|
||||
expect(extractWebActorIp(makeRequest({ "cf-connecting-ip": "1.1.1.1", "x-forwarded-for": "2.2.2.2" }))).toBe("1.1.1.1");
|
||||
it("accepts Cloudflare client IPs only behind a verified Cloudflare peer", () => {
|
||||
expect(extractWebActorIp(makeRequest({ "cf-connecting-ip": "1.1.1.1", "x-forwarded-for": "2.2.2.2, 173.245.48.10" }))).toBe("1.1.1.1");
|
||||
expect(extractWebActorIp(makeRequest({ "x-real-ip": "2.2.2.2" }))).toBe("2.2.2.2");
|
||||
expect(extractWebActorIp(makeRequest({ "x-forwarded-for": "3.3.3.3, 8.8.8.8" }))).toBe("3.3.3.3");
|
||||
expect(extractWebActorIp(makeRequest({ "x-forwarded-for": "3.3.3.3, 8.8.8.8" }))).toBe("8.8.8.8");
|
||||
expect(extractWebActorIp(makeRequest({ "cf-connecting-ip": "not-an-ip" }))).toBeNull();
|
||||
expect(extractWebActorIp(makeRequest({}))).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -34,7 +35,17 @@ describe("extractWebRequestId", () => {
|
||||
describe("withAuditContext", () => {
|
||||
it("binds the context for the duration of the callback", async () => {
|
||||
expect(getWebAuditContext()).toBeNull();
|
||||
const captured = await withAuditContext({ request: makeRequest({ "cf-connecting-ip": "5.5.5.5", "user-agent": "Test/1.0", "x-request-id": "req_1" }) }, async () => getWebAuditContext());
|
||||
const captured = await withAuditContext(
|
||||
{
|
||||
request: makeRequest({
|
||||
"cf-connecting-ip": "5.5.5.5",
|
||||
"x-forwarded-for": "198.51.100.5, 173.245.48.10",
|
||||
"user-agent": "Test/1.0",
|
||||
"x-request-id": "req_1",
|
||||
}),
|
||||
},
|
||||
async () => getWebAuditContext()
|
||||
);
|
||||
expect(captured).toEqual({ actorIp: "5.5.5.5", actorUserAgent: "Test/1.0", requestId: "req_1" });
|
||||
expect(getWebAuditContext()).toBeNull();
|
||||
});
|
||||
|
||||
+2
-9
@@ -1,4 +1,5 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import { getTrustedClientIpOrNull } from "~/utils/server/IpUtils";
|
||||
|
||||
/**
|
||||
* Phase 10 Task #67 — Audit auto-capture (React-Router web).
|
||||
@@ -23,16 +24,8 @@ export type WebAuditContext = {
|
||||
|
||||
const webAuditContextStore = new AsyncLocalStorage<WebAuditContext>();
|
||||
|
||||
const FORWARDED_HEADERS = ["cf-connecting-ip", "x-real-ip", "x-forwarded-for"] as const;
|
||||
|
||||
export function extractWebActorIp(request: Request): string | null {
|
||||
for (const name of FORWARDED_HEADERS) {
|
||||
const raw = request.headers.get(name);
|
||||
if (typeof raw !== "string") continue;
|
||||
const first = raw.split(",")[0]?.trim();
|
||||
if (first && first.length > 0 && first.length <= 64) return first;
|
||||
}
|
||||
return null;
|
||||
return getTrustedClientIpOrNull(request);
|
||||
}
|
||||
|
||||
export function extractWebActorUserAgent(request: Request): string | null {
|
||||
|
||||
Reference in new issue
Block a user