security hardening
This commit is contained in:
+11
-1
@@ -5,6 +5,7 @@ import path from 'node:path';
|
||||
dotenv.config();
|
||||
|
||||
const envPath = path.resolve(process.cwd(), '.env');
|
||||
const minApiTokenLength = 32;
|
||||
|
||||
export const requiredEnv = [
|
||||
'AWS_ACCESS_KEY_ID',
|
||||
@@ -36,6 +37,10 @@ export const config = {
|
||||
},
|
||||
};
|
||||
|
||||
if (!config.apiToken || config.apiToken.length < minApiTokenLength) {
|
||||
throw new Error(`API_TOKEN is required and must be at least ${minApiTokenLength} characters long.`);
|
||||
}
|
||||
|
||||
export const editableEnv = [
|
||||
{ key: 'AWS_ACCESS_KEY_ID', label: 'AWS access key ID', required: true, secret: true },
|
||||
{ key: 'AWS_SECRET_ACCESS_KEY', label: 'AWS secret access key', required: true, secret: true },
|
||||
@@ -47,7 +52,7 @@ export const editableEnv = [
|
||||
{ key: 'RESTIC_KEEP_WEEKLY', label: 'Keep weekly snapshots', required: false, secret: false },
|
||||
{ key: 'RESTIC_KEEP_MONTHLY', label: 'Keep monthly snapshots', required: false, secret: false },
|
||||
{ key: 'PORT', label: 'API port', required: false, secret: false },
|
||||
{ key: 'API_TOKEN', label: 'API token', required: false, secret: true },
|
||||
{ key: 'API_TOKEN', label: 'API token', required: true, secret: true },
|
||||
{ key: 'ALLOWED_MANAGEMENT_IPS', label: 'Allowed management IPs', required: false, secret: false },
|
||||
];
|
||||
|
||||
@@ -77,6 +82,11 @@ export async function writeEnvSettings(values) {
|
||||
|
||||
for (const [key, value] of Object.entries(values || {})) {
|
||||
if (!allowedKeys.has(key)) continue;
|
||||
if (key === 'API_TOKEN' && String(value || '').length < minApiTokenLength) {
|
||||
const error = new Error(`API_TOKEN must be at least ${minApiTokenLength} characters long.`);
|
||||
error.status = 400;
|
||||
throw error;
|
||||
}
|
||||
nextValues[key] = String(value ?? '');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user