Secrets and Environment Variables — Concept Check
Questions on Secrets and Environment Variables. NEXT_PUBLIC_ is a publication decision, not a naming convention. Everything else is about making a wrong import fail the build instead of leaking.
Questions in this quiz
7 questions on Secrets and Environment Variables — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer accidentally includes a secret API key in a client-side component. What is the best course of action?
- ARotate the secret key immediately and update the client-side component.
- BChange the secret key and restart the server.
- CDelete the secret key from the codebase to prevent further exposure.
- DIgnore it if the key is not actively being exploited.
2.Which of the following environment variable practices helps prevent accidental secret leaks in a Next.js application?
- AUsing 'NEXT_PUBLIC_' prefix for all environment variables.
- BSeparating public and secret configurations into different modules.
- CCommitting .env.local to version control for consistency.
- DStoring all environment variables in a single .env file.
3.What happens if a server module containing secrets is imported into a client component without precautions?
- AThe secrets are exposed in the client bundle.
- BThe build fails due to 'server-only' package restrictions.
- CThe application crashes at runtime.
- DThe import is ignored by the build process.
4.How does the 'server-only' package in Next.js help secure environment variables?
- AIt automatically rotates secrets to prevent leaks.
- BIt encrypts all server-side environment variables.
- CIt prefixes all server-side variables with 'SERVER_'.
- DIt prevents server modules from being imported into client components.
5.A developer uses 'NEXT_PUBLIC_' prefix for a secret API key. What is the consequence of this action?
- AThe key is encrypted in the client bundle.
- BThe key is publicly accessible and should be rotated immediately.
- CThe key is only accessible during development.
- DThe key remains secure on the server side.
6.Where should real secret values be stored to ensure they are not accidentally committed to version control?
- AIn the .env.example file as placeholders.
- BIn the .env.production file for production use.
- CIn the .env.local file, which is gitignored.
- DIn the .env file committed to the repository.
7.What is a common mistake developers make when handling environment variables in Next.js applications?
- AUsing separate modules for public and secret configurations.
- BValidating environment variables at startup.
- CRotating secrets when exposed.
- DAssuming 'NEXT_PUBLIC_' variables are secure.