Skip to content

Commit db1ee09

Browse files
authored
Merge pull request #25 from zenstackhq/dev
fix: Added redactDatabaseUrl() utility that masks username/password with *** before logging (#24)
2 parents 0bf3a3e + 97e5900 commit db1ee09

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/proxy",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "A CLI tool to run an Express server that proxies CRUD requests to a ZenStack backend",
55
"main": "index.js",
66
"publishConfig": {
@@ -24,7 +24,7 @@
2424
"author": "",
2525
"license": "MIT",
2626
"dependencies": {
27-
"@prisma/adapter-better-sqlite3": "^6.2.1",
27+
"@prisma/adapter-better-sqlite3": "^7.3.0",
2828
"@prisma/adapter-mariadb": "^7.1.0",
2929
"@prisma/adapter-pg": "^6.18.0",
3030
"@zenstackhq/server": "^2.0.0",

pnpm-lock.yaml

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path'
22
import express from 'express'
33
import cors from 'cors'
44
import { ZenStackMiddleware } from '@zenstackhq/server/express'
5-
import { GeneratorConfig, ZModelConfig } from './zmodel-parser'
5+
import { ZModelConfig } from './zmodel-parser'
66
import { getNodeModulesFolder, getPrismaVersion, getZenStackVersion } from './utils/version-utils'
77
import { blue, grey } from 'colors'
88
import semver from 'semver'
@@ -46,6 +46,22 @@ function resolveSQLitePath(filePath: string, prismaSchemaDir: string): string {
4646
return path.join(prismaSchemaDir, filePath)
4747
}
4848

49+
function redactDatabaseUrl(url: string): string {
50+
try {
51+
const parsedUrl = new URL(url)
52+
if (parsedUrl.password) {
53+
parsedUrl.password = '***'
54+
}
55+
if (parsedUrl.username) {
56+
parsedUrl.username = '***'
57+
}
58+
return parsedUrl.toString()
59+
} catch {
60+
// If URL parsing fails, return the original (might be a file path for SQLite)
61+
return url
62+
}
63+
}
64+
4965
/**
5066
* Create database adapter based on provider
5167
*/
@@ -79,7 +95,7 @@ function createAdapter(config: ZModelConfig, zmodelSchemaDir: string): any {
7995
case 'postgresql': {
8096
try {
8197
const { PrismaPg } = require('@prisma/adapter-pg')
82-
console.log(grey(`Connecting to PostgreSQL database at: ${url}`))
98+
console.log(grey(`Connecting to PostgreSQL database at: ${redactDatabaseUrl(url)}`))
8399
return new PrismaPg({ connectionString: url })
84100
} catch (error) {
85101
throw new CliError(
@@ -90,7 +106,7 @@ function createAdapter(config: ZModelConfig, zmodelSchemaDir: string): any {
90106
case 'mysql': {
91107
try {
92108
const { PrismaMariaDB } = require('@prisma/adapter-mariadb')
93-
console.log(grey(`Connecting to MySQL/MariaDB database at: ${url}`))
109+
console.log(grey(`Connecting to MySQL/MariaDB database at: ${redactDatabaseUrl(url)}`))
94110
return new PrismaMariaDB({
95111
url,
96112
})

0 commit comments

Comments
 (0)