fix(backend): harden runtime config and verification access
This commit is contained in:
17
backend/query-api/src/lib/runtime-safety.js
Normal file
17
backend/query-api/src/lib/runtime-safety.js
Normal file
@@ -0,0 +1,17 @@
|
||||
function runtimeEnvName() {
|
||||
return `${process.env.APP_ENV || process.env.NODE_ENV || ''}`.trim().toLowerCase();
|
||||
}
|
||||
|
||||
function isProtectedEnv() {
|
||||
return ['staging', 'prod', 'production'].includes(runtimeEnvName());
|
||||
}
|
||||
|
||||
export function assertSafeRuntimeConfig() {
|
||||
if (!isProtectedEnv()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.AUTH_BYPASS === 'true') {
|
||||
throw new Error(`Unsafe query-api runtime config for ${runtimeEnvName()}: AUTH_BYPASS must be disabled`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user