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
+20
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { setServerTimingHeaders } from "./defaultHeaders";
|
||||
|
||||
describe("default route headers", () => {
|
||||
it("carries the request nonce and root CSP through nested route header functions", () => {
|
||||
const nonce = "aBcDeFgHiJkLmNoPqRsTuVwX";
|
||||
const policy = `default-src 'self'; script-src 'nonce-${nonce}'`;
|
||||
const headers = setServerTimingHeaders(new Headers(), {
|
||||
loaderHeaders: new Headers(),
|
||||
parentHeaders: new Headers({
|
||||
"x-hivegrid-csp-nonce": nonce,
|
||||
"Content-Security-Policy": policy,
|
||||
}),
|
||||
});
|
||||
|
||||
expect(headers.get("x-hivegrid-csp-nonce")).toBe(nonce);
|
||||
expect(headers.get("Content-Security-Policy")).toBe(policy);
|
||||
});
|
||||
});
|
||||
+7
@@ -1,4 +1,7 @@
|
||||
import type { HeadersFunction } from "react-router";
|
||||
import { CSP_NONCE_REQUEST_HEADER } from "~/utils/security/contentSecurityPolicy";
|
||||
|
||||
const INHERITED_SECURITY_HEADERS = [CSP_NONCE_REQUEST_HEADER, "Content-Security-Policy"] as const;
|
||||
|
||||
export const serverTimingHeaders: HeadersFunction = ({ loaderHeaders, parentHeaders }) => {
|
||||
return setServerTimingHeaders(new Headers(), {
|
||||
@@ -14,5 +17,9 @@ export function setServerTimingHeaders(headers: Headers, args: { loaderHeaders:
|
||||
if (args.parentHeaders.has("Server-Timing")) {
|
||||
headers.append("Server-Timing", args.parentHeaders.get("Server-Timing")!);
|
||||
}
|
||||
for (const headerName of INHERITED_SECURITY_HEADERS) {
|
||||
const value = args.loaderHeaders.get(headerName) ?? args.parentHeaders.get(headerName);
|
||||
if (value) headers.set(headerName, value);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
Reference in new issue
Block a user