Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build && node scripts/copy-standalone-static.js",
"build": "node scripts/validate-env.js && next build && node scripts/copy-standalone-static.js",
"start": "next start",
"lint": "next lint",
"type-check": "tsc --noEmit",
Expand Down Expand Up @@ -50,6 +50,7 @@
"tailwind-merge": "^3.6.0"
},
"devDependencies": {
"@next/env": "^16.2.7",
"@playwright/test": "1.60.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
Expand All @@ -60,9 +61,9 @@
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/swagger-ui-react": "^5.18.0",
"@vitest/coverage-v8": "^1.6.1",
"@typescript-eslint/eslint-plugin": "^8.60.0",
"@typescript-eslint/parser": "^8.60.0",
"@vitest/coverage-v8": "^1.6.1",
"autoprefixer": "^10.4.19",
"eslint": "^8",
"eslint-config-next": "^14.2.35",
Expand Down
43 changes: 43 additions & 0 deletions scripts/validate-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { loadEnvConfig } = require('@next/env');

// Load environment variables exactly as Next.js does
loadEnvConfig(process.cwd());
Comment on lines +1 to +4

const BLOCKED_KEYWORDS = [
'private_key',
'supabase_secret',
'database_url',
'service_role',
'admin_key',
'jwt_secret',
];

let hasError = false;

console.log('🔒 Validating environment variables...');

for (const [key, value] of Object.entries(process.env)) {
if (key.startsWith('NEXT_PUBLIC_')) {
const lowerKey = key.toLowerCase();
const lowerValue = (value || '').toLowerCase();

// Check if the key name contains any blocked private keywords
const isLeakingName = BLOCKED_KEYWORDS.some(kw => lowerKey.includes(kw));

// Check if the value looks like a raw private key string
const isLeakingValue = lowerValue.includes('-----begin private key-----') || lowerValue.includes('-----begin rsa private key-----');

if (isLeakingName || isLeakingValue) {
console.error(`\n🚨 SECURITY ERROR: Potentially private secret leaked into public variable: ${key}`);
console.error(` NEXT_PUBLIC_ prefix makes this variable visible to the browser!`);
hasError = true;
}
}
}

if (hasError) {
console.error('\n❌ Build halted due to environment variable security check failure.\n');
process.exit(1);
} else {
console.log('✅ Environment variable security check passed.\n');
}
Loading