Skip to content

Commit fcd7305

Browse files
authored
chore: configure csp (#144)
* chore: configure csp * fix: redirect to catalog page clicking on logo
1 parent bcff681 commit fcd7305

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

next.config.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,59 @@ import type { NextConfig } from "next";
22

33
const isDev = process.env.NODE_ENV !== "production";
44

5+
/**
6+
* Content Security Policy header.
7+
* All API calls (OIDC, backend API) happen server-side,
8+
* so browser CSP only needs 'self'.
9+
*/
10+
const cspHeader = `
11+
default-src 'self';
12+
script-src 'self' 'unsafe-inline';
13+
style-src 'self' 'unsafe-inline';
14+
img-src 'self' blob: data:;
15+
font-src 'self';
16+
connect-src 'self';
17+
form-action 'self';
18+
frame-ancestors 'none';
19+
base-uri 'self';
20+
object-src 'none';
21+
upgrade-insecure-requests;
22+
`
23+
.replace(/\s{2,}/g, " ")
24+
.trim();
25+
526
const nextConfig: NextConfig = {
6-
/* config options here */
727
reactCompiler: true,
828
output: "standalone",
29+
async headers() {
30+
return [
31+
{
32+
source: "/(.*)",
33+
headers: [
34+
{
35+
key: "Content-Security-Policy",
36+
value: cspHeader,
37+
},
38+
{
39+
key: "X-Content-Type-Options",
40+
value: "nosniff",
41+
},
42+
{
43+
key: "X-Frame-Options",
44+
value: "DENY",
45+
},
46+
{
47+
key: "Referrer-Policy",
48+
value: "strict-origin-when-cross-origin",
49+
},
50+
{
51+
key: "Permissions-Policy",
52+
value: "camera=(), microphone=(), geolocation=()",
53+
},
54+
],
55+
},
56+
];
57+
},
958
async rewrites() {
1059
if (!isDev) return [];
1160

src/components/navbar-logo.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import Link from "next/link";
12
import { ToolHiveIcon } from "@/components/icons";
23

34
export function NavbarLogo() {
45
return (
5-
<div className="flex items-center gap-2">
6+
<Link href="/catalog" className="flex items-center gap-2">
67
<ToolHiveIcon className="size-5 shrink-0" />
78
<span className="text-2xl font-bold tracking-tight">ToolHive</span>
8-
</div>
9+
</Link>
910
);
1011
}

0 commit comments

Comments
 (0)