Skip to content

Commit 1705900

Browse files
GudE-Rclaude
andcommitted
fix: add security headers (CSP, X-Frame-Options) and harden env handling
- Add CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy headers - Change supabase.ts to throw on missing env vars instead of using fallback values - Add .env.production to .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9afae50 commit 1705900

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ yarn-error.log*
1111
pnpm-debug.log*
1212
.vercel
1313
.env*.local
14+
.env.production
1415

1516
# Test coverage
1617
coverage/

apps/web/next.config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ const withNextIntl = createNextIntlPlugin();
66

77
const nextConfig: NextConfig = {
88
transpilePackages: ['@studytodo/shared'],
9+
async headers() {
10+
return [
11+
{
12+
source: '/(.*)',
13+
headers: [
14+
{
15+
key: 'Content-Security-Policy',
16+
value: [
17+
"default-src 'self'",
18+
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://pagead2.googlesyndication.com https://www.googletagmanager.com",
19+
"style-src 'self' 'unsafe-inline'",
20+
"img-src 'self' data: https:",
21+
"font-src 'self'",
22+
"connect-src 'self' https://*.supabase.co wss://*.supabase.co",
23+
"frame-src https://pagead2.googlesyndication.com",
24+
"frame-ancestors 'none'",
25+
].join('; '),
26+
},
27+
{ key: 'X-Frame-Options', value: 'DENY' },
28+
{ key: 'X-Content-Type-Options', value: 'nosniff' },
29+
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
30+
],
31+
},
32+
];
33+
},
934
};
1035

1136
export default withNextIntl(nextConfig);

apps/web/src/lib/supabase.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ import { createClient } from '@supabase/supabase-js';
33
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
44
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
55

6-
// 環境変数がロードされていない場合のエラーハンドリング
76
if (!supabaseUrl || !supabaseAnonKey) {
8-
console.error(`
9-
[Supabase Error] Environment variables missing.
10-
NEXT_PUBLIC_SUPABASE_URL: ${supabaseUrl ? "Loaded" : "Missing"}
11-
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${supabaseAnonKey ? "Loaded" : "Missing"}
12-
Please check .env.local content format.
13-
`);
7+
throw new Error(
8+
`Supabase environment variables missing. ` +
9+
`NEXT_PUBLIC_SUPABASE_URL: ${supabaseUrl ? "OK" : "Missing"}, ` +
10+
`NEXT_PUBLIC_SUPABASE_ANON_KEY: ${supabaseAnonKey ? "OK" : "Missing"}`
11+
);
1412
}
1513

16-
// クライアント作成(URLがない場合は空文字を渡すが、これを使用するとエラーになるため、使用側でチェックが必要)
17-
export const supabase = createClient(
18-
supabaseUrl || "https://placeholder.supabase.co",
19-
supabaseAnonKey || "placeholder-key"
20-
);
14+
export const supabase = createClient(supabaseUrl, supabaseAnonKey);

0 commit comments

Comments
 (0)