Skip to content

Commit 47d4221

Browse files
SashkoMarchukclaude
andcommitted
fix(cpb): add identifier validation to init-db.sh and fix production note
- Add validate_pg_identifier to init-db.sh matching cpb-setup-db.sh pattern - Validate all 7 database/user identifiers before SQL execution - Fix .env.example production note: correct line range (30-48), add CPB_POSTGRES_PASSWORD Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c3dded commit 47d4221

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ MN_SERVICE_SA_GOOGLE_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oaut
116116
MN_SERVICE_SA_GOOGLE_CLIENT_X509_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/mock-service-account%40mock-project-id.iam.gserviceaccount.com
117117
MN_SERVICE_SA_GOOGLE_UNIVERSE_DOMAIN=googleapis.com
118118
# CPB (Connecting People Bot) — Production overrides
119-
# Variables are defined in the Development section above (lines 30-46).
119+
# Variables are defined in the Development section above (lines 30-48).
120120
# For production: set real values for POSTGRES_PASSWORD_CPB, CPB_POSTGRES_HOST,
121-
# CPB_SLACK_BOT_TOKEN, CPB_CHANNEL_ID, CPB_REPORT_CHANNEL_ID,
122-
# CPB_ADMIN_SLACK_ID, and CPB_DEV_SLACK_ID in your .env file.
121+
# CPB_POSTGRES_PASSWORD, CPB_SLACK_BOT_TOKEN, CPB_CHANNEL_ID,
122+
# CPB_REPORT_CHANNEL_ID, CPB_ADMIN_SLACK_ID, and CPB_DEV_SLACK_ID in your .env file.

scripts/init-db.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
#!/bin/bash
22
set -e
33

4+
# Validate PostgreSQL identifiers (prevent SQL injection via crafted names)
5+
validate_pg_identifier() {
6+
local value="$1" name="$2"
7+
if [[ -z "$value" ]]; then
8+
echo "ERROR: ${name} cannot be empty" >&2; exit 1
9+
fi
10+
if [[ ${#value} -gt 63 ]]; then
11+
echo "ERROR: ${name} exceeds PostgreSQL's 63-char identifier limit" >&2; exit 1
12+
fi
13+
if [[ ! "$value" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
14+
echo "ERROR: ${name} contains invalid characters (must match ^[a-zA-Z_][a-zA-Z0-9_]*$)" >&2; exit 1
15+
fi
16+
return 0
17+
}
18+
19+
validate_pg_identifier "$POSTGRES_USER_N8N" "POSTGRES_USER_N8N"
20+
validate_pg_identifier "$POSTGRES_DB_N8N" "POSTGRES_DB_N8N"
21+
validate_pg_identifier "$POSTGRES_USER_TEMPORAL" "POSTGRES_USER_TEMPORAL"
22+
validate_pg_identifier "$POSTGRES_DB_TEMPORAL" "POSTGRES_DB_TEMPORAL"
23+
validate_pg_identifier "$POSTGRES_DB_TEMPORAL_VISIBILITY" "POSTGRES_DB_TEMPORAL_VISIBILITY"
24+
validate_pg_identifier "$POSTGRES_USER_CPB" "POSTGRES_USER_CPB"
25+
validate_pg_identifier "$POSTGRES_DB_CPB" "POSTGRES_DB_CPB"
26+
427
# Escape single quotes in passwords for SQL safety
528
ESCAPED_POSTGRES_PASSWORD_N8N="${POSTGRES_PASSWORD_N8N//\'/''}"
629
ESCAPED_POSTGRES_PASSWORD_TEMPORAL="${POSTGRES_PASSWORD_TEMPORAL//\'/''}"

0 commit comments

Comments
 (0)