A practical guide to keeping API keys out of browser code, limiting secret access, and rotating credentials safely in Next JS applications.

Keep reusable API credentials in managed secret storage and expose them only to authorized server side code.
Keep confidential API keys in trusted server side code. Give each workload access only to the secrets it needs.
Give every service its own identity. Record access decisions, never secret values.
Keep payment credentials and database passwords in managed secret storage. Limit public browser keys by website, service, and usage. Store ordinary settings with deployment configuration.
Use test credentials or a developer identity for local work. Use the hosting platform's protected secret service for builds and production. Keep production credentials off personal devices.
Use managed identity to let an Azure application read only the required values from Azure Key Vault. Other platforms can use their own protected secret services.
Retrieve secrets through an authorized server application. Keep vault settings separate from confidential values, and test access in every environment.
Read credentials on the server only. Never return them to browsers, error messages, analytics, or logs. For busy services, use protected delivery or a limited cache with a refresh plan.
Keep outside service calls on the server. Validate requests, check user permissions, and return only the result needed by the browser.
Treat browser code as public, even when the source repository is private. Use browser keys only when designed for public use and restricted by their provider.
Trace each secret from its source to its use and possible exposure. Search code and records with test values, never production credentials.
List every key, owner, user, environment, and expiry rule. Confirm whether the provider allows old and new keys to overlap.
Create a replacement with equal or narrower access. Store it privately, update users in stages, and confirm it works.
Verify every user has switched before disabling the old key. If overlap is unavailable, plan a maintenance period. Disable exposed keys promptly.
Missing secrets should trigger a clear error and alert. Never use an empty value or public key as a silent fallback. Log outcomes, not credentials.
Track each secret's purpose, owner, users, environment, permissions, and rotation plan. Scanning helps, but cannot catch every leak.
A private repository does not protect values sent to a browser. Choose storage supported by your host. Protect server routes and return only the required result.
Set a schedule based on risk, policy, and provider support. Test the process and rotate promptly if a key may be exposed.
A vault stores secret values but does not replace keys at outside services by itself. Confirm a process updates both the provider and every user.
Fetching a secret for every request can add delay. Use protected storage or delivery with a clear refresh and revocation plan.
Keep secrets out of the browser, limit workload access, and read credentials only on the server. Practice key replacement before it is urgent. Use Azure Key Vault or an equivalent service supported by your host.
Inventory keys and users. Remove exposed values, assign separate identities, and practice replacing and disabling a key.
Explore other service pillars