Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:config): normalize quoted admin credentials

johaven5fea5b476164
diff --git a/backend/src/common/shared.spec.ts b/backend/src/common/shared.spec.ts
new file mode 100644
index 00000000..7f33a0f2
--- /dev/null
+++ b/backend/src/common/shared.spec.ts
@@ -0,0 +1,13 @@
+import { stripMatchingQuotes } from './shared'
+
+describe(stripMatchingQuotes.name, () => {
+ it.each([
+ ['value', 'value'],
+ ['"value"', 'value'],
+ ["'value'", 'value'],
+ [`"'value'"`, "'value'"],
+ [`"value'`, `"value'`]
+ ])('should convert %s to %s', (value, expectedValue) => {
+ expect(stripMatchingQuotes(value)).toBe(expectedValue)
+ })
+})
diff --git a/backend/src/common/shared.ts b/backend/src/common/shared.ts
index 667b37ac..9ee37f7c 100644
--- a/backend/src/common/shared.ts
+++ b/backend/src/common/shared.ts
@@ -103,6 +103,10 @@ export function capitalizeString(value: string): string {
return value.charAt(0).toUpperCase() + value.slice(1)
}
+export function stripMatchingQuotes(value: string): string {
+ return value.replace(/^(["'])(.*)\1$/s, '$2')
+}
+
export function intersectPermissions(aPermissions: string, bPermissions: string, permissionsSeparator: string = SPACE_PERMS_SEP): string {
const aPerms = aPermissions.split(permissionsSeparator)
const bPerms = bPermissions.split(permissionsSeparator)
diff --git a/backend/src/configuration/config.loader.ts b/backend/src/configuration/config.loader.ts
index b657c1b5..e427b8ef 100644
--- a/backend/src/configuration/config.loader.ts
+++ b/backend/src/configuration/config.loader.ts
@@ -2,6 +2,7 @@ import deepmerge from 'deepmerge'
import * as yaml from 'js-yaml'
import fs from 'node:fs'
import path from 'node:path'
+import { stripMatchingQuotes } from '../common/shared'
import {
DEFAULT_LOG_FILE_PATH,
ENVIRONMENT_DIST_FILE_NAME,
@@ -64,8 +65,7 @@ function hasEnvConfig(): boolean {
* Parse a raw env-string into boolean, number or leave as string.
*/
function parseEnvValue(value: string): any {
- // Remove a matching pair of surrounding single or double quotes.
- value = value.replace(/^(["'])(.*)\1$/s, '$2')
+ value = stripMatchingQuotes(value)
if (value === 'true') return true
if (value === 'false') return false
if (!isNaN(Number(value))) return Number(value)
diff --git a/backend/src/infrastructure/database/scripts/create-user.ts b/backend/src/infrastructure/database/scripts/create-user.ts
index dc6afbcc..8bce9c16 100644
--- a/backend/src/infrastructure/database/scripts/create-user.ts
+++ b/backend/src/infrastructure/database/scripts/create-user.ts
@@ -3,7 +3,7 @@ import { USER_PERMISSION, USER_ROLE } from '../../../applications/users/constant
import { User } from '../../../applications/users/schemas/user.interface'
import { users } from '../../../applications/users/schemas/users.schema'
import { hashPassword } from '../../../common/functions'
-import { capitalizeString } from '../../../common/shared'
+import { capitalizeString, stripMatchingQuotes } from '../../../common/shared'
import { getDB } from './db'
interface InitUser extends Partial<User> {
@@ -56,12 +56,13 @@ async function parseArgs(): Promise<InitUser> {
}
// 2. Derive and validate options with defaults
- const login = raw.login || 'sync-in'
+ const login = stripMatchingQuotes(raw.login || '') || 'sync-in'
const email = raw.email?.trim() || `${login}@sync-in.com`
- const pwdPlain = raw.password && raw.password.length > 3 ? raw.password : 'sync-in'
- if (!raw.password || raw.password.length <= 3) {
+ const rawPassword = stripMatchingQuotes(raw.password || '')
+ const pwdPlain = rawPassword.length > 3 ? rawPassword : 'sync-in'
+ if (rawPassword.length <= 3) {
console.warn('Password invalid or not specified, using default.')
}