Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: harden default self-host deployment secrets (#6639)

Nahid Hasaned3020e4e63a
diff --git a/docker-compose.yml b/docker-compose.yml
index c0485a5c9..77fd5b070 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -133,7 +133,7 @@ services:
# The preset DB service, you can delete/comment the below lines if
# you are using an external postgres instance
- # This will be exposed at port 5432
+ # This will be exposed at port 5432 on localhost only
hoppscotch-db:
profiles:
[
@@ -147,7 +147,7 @@ services:
]
image: postgres:15
ports:
- - "5432:5432"
+ - "127.0.0.1:5432:5432"
user: postgres
environment:
# The default user defined by the docker image
diff --git a/packages/hoppscotch-backend/src/main.ts b/packages/hoppscotch-backend/src/main.ts
index 0244015e7..cc0c733d1 100644
--- a/packages/hoppscotch-backend/src/main.ts
+++ b/packages/hoppscotch-backend/src/main.ts
@@ -39,6 +39,28 @@ function setupSwagger(
});
}
+function warnIfExampleSecrets(configService: ConfigService): void {
+ if (
+ configService.get('DATA_ENCRYPTION_KEY') ===
+ 'data encryption key with 32 char'
+ ) {
+ console.warn(
+ '[SECURITY] DATA_ENCRYPTION_KEY is set to the example value from .env.example. Please change it.',
+ );
+ }
+
+ try {
+ const dbUrl = new URL(configService.get('DATABASE_URL') ?? '');
+ if (decodeURIComponent(dbUrl.password) === 'testpass') {
+ console.warn(
+ '[SECURITY] DATABASE_URL uses the example database password. Please change it.',
+ );
+ }
+ } catch {
+ // Invalid or missing DATABASE_URL, nothing to check
+ }
+}
+
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
@@ -48,6 +70,8 @@ async function bootstrap() {
console.log(`Running in production: ${isProduction}`);
console.log(`Port: ${configService.get('PORT')}`);
+ warnIfExampleSecrets(configService);
+
// Increase file upload limit to 100MB
app.use(
json({