security(env): setup build-time key sanitation to block private crede…#2171
Conversation
|
@VIDYANKSHINI is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a pre-build guard to prevent accidentally exposing private credentials via NEXT_PUBLIC_* environment variables during Next.js builds.
Changes:
- Introduce
scripts/validate-env.jsto load env files (Next.js-style) and scanNEXT_PUBLIC_*vars for blocked secret keywords / private key markers. - Gate
npm run buildby running the validation script beforenext build.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/validate-env.js | New env validation script that fails the build on detected secret leakage via public env vars. |
| package.json | Runs env validation as part of the build pipeline before next build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const { loadEnvConfig } = require('@next/env'); | ||
|
|
||
| // Load environment variables exactly as Next.js does | ||
| loadEnvConfig(process.cwd()); |
| if (key.startsWith('NEXT_PUBLIC_')) { | ||
| const lowerKey = key.toLowerCase(); | ||
| const lowerValue = (value || '').toLowerCase(); | ||
|
|
4fca250
into
Priyanshu-byte-coder:main
|
🎉 Merged! Thanks for contributing to DevTrack. If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers. Keep an eye on open issues for your next contribution! |
Summary
Implemented a pre-build environment validation check that blocks the compiler if private credentials accidentally leak into the public Next.js bundle.
Closes #1462
Type of Change
Changes Made
scripts/validate-env.jswhich loads environment variables and scans all keys prefixed withNEXT_PUBLIC_.private_key,supabase_secret,database_url,admin_key,service_role) or raw RSA key values are detected in public variables.buildscript inpackage.jsonto prepend the validation script execution (node scripts/validate-env.js && next build).How to Test
.env.local:NEXT_PUBLIC_DATABASE_URL=test_leaknpm run build🚨 SECURITY ERRORstating that a potentially private secret leaked into a public variable.Screenshots (if UI change)
N/A
Checklist
npm run lintpasses locallynpm run type-check)