Skip to content

Commit 9c2250a

Browse files
Merge pull request #7058 from christianbeeznest/GH-3667
Install: Sanitize database name and reflect effective value in summary - refs #3667
2 parents 424f492 + 4487dbd commit 9c2250a

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

assets/vue/components/installer/Step4.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
for="dbNameForm"
107107
/>
108108
</div>
109+
<small v-if="'update' !== installerData.installType">
110+
{{
111+
t(
112+
"Only letters, digits and underscore (_) are allowed in the database name. Invalid characters will be removed automatically.",
113+
)
114+
}}
115+
</small>
109116
</div>
110117

111118
<div
@@ -128,7 +135,7 @@
128135
v-if="installerData.stepData.dbExists"
129136
:closable="false"
130137
severity="warn"
131-
style="margin-bottom: 8px;"
138+
style="margin-bottom: 8px"
132139
>
133140
<span v-html="t('A database with the same name already exists. It will be deleted.')" />
134141
</Message>
@@ -230,8 +237,10 @@ const { t } = useI18n()
230237
231238
const installerData = inject("installerData")
232239
233-
// Database Name fix replace weird chars
234-
if ("update" !== installerData.value.installType) {
235-
installerData.value.dbNameForm = installerData.value.dbNameForm.replace(/[-*$ .]/g, "")
240+
// Normalize database name on the client so it matches backend sanitization.
241+
// We only allow letters, digits and underscore. Other characters are stripped.
242+
if (installerData.value.installType !== "update") {
243+
const rawName = installerData.value.stepData?.dbNameForm || ""
244+
installerData.value.stepData.dbNameForm = rawName.replace(/[^a-zA-Z0-9_]/g, "")
236245
}
237246
</script>

assets/vue/components/installer/Step6.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
/>
227227
<div
228228
class="field text-body-2"
229-
v-text="installerData.stepData.dbNameForm"
229+
v-text="sanitizedDbName"
230230
/>
231231
</div>
232232

@@ -379,7 +379,7 @@
379379
</template>
380380

381381
<script setup>
382-
import { inject, ref } from "vue"
382+
import { inject, ref, computed } from "vue"
383383
import { useI18n } from "vue-i18n"
384384
385385
import Message from "primevue/message"
@@ -392,6 +392,19 @@ const { t } = useI18n()
392392
393393
const installerData = inject("installerData")
394394
395+
// Compute the sanitized database name as it will be created on the server.
396+
const sanitizedDbName = computed(() => {
397+
const raw = installerData.value?.stepData?.dbNameForm || ""
398+
399+
// For updates we trust the existing database name as-is.
400+
if (installerData.value.installType === "update" || installerData.value.isUpdateAvailable) {
401+
return raw
402+
}
403+
404+
// Same rule as backend: only letters, digits and underscore are kept.
405+
return raw.replace(/[^a-zA-Z0-9_]/g, "")
406+
})
407+
395408
const loading = ref(false)
396409
const isButtonDisabled = ref(installerData.value.isUpdateAvailable)
397410
const isExecutable = ref("")
@@ -423,7 +436,7 @@ function btnStep6OnClick() {
423436
}
424437
425438
function startMigration(updatePath) {
426-
var xhr = new XMLHttpRequest()
439+
const xhr = new XMLHttpRequest()
427440
xhr.onreadystatechange = function () {
428441
if (xhr.readyState === 4 && xhr.status !== 200) {
429442
loading.value = false
@@ -442,7 +455,7 @@ function startMigration(updatePath) {
442455
443456
function pollMigrationStatus() {
444457
setTimeout(() => {
445-
var xhr = new XMLHttpRequest()
458+
const xhr = new XMLHttpRequest()
446459
xhr.onreadystatechange = function () {
447460
if (xhr.readyState === 4 && xhr.status === 200) {
448461
const response = JSON.parse(xhr.responseText)

public/main/install/index.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,18 @@
514514
$dbPortForm
515515
);
516516
$manager = Database::getManager();
517-
$dbNameForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbNameForm);
518517

519-
// Drop and create the database anyways
518+
// Sanitize database name: only letters, numbers and underscore
519+
$dbNameForm = preg_replace('/[^a-zA-Z0-9_]/', '', $dbNameForm);
520+
521+
// Drop and create the database anyway
520522
error_log("Drop database $dbNameForm");
521523
$schemaManager = $manager->getConnection()->createSchemaManager();
522524

523525
try {
524526
$schemaManager->dropDatabase($dbNameForm);
525527
} catch (\Doctrine\DBAL\Exception $e) {
526-
error_log("Database ".$dbNameForm." does not exists");
528+
error_log("Database ".$dbNameForm." does not exist");
527529
}
528530

529531
$schemaManager->createDatabase($dbNameForm);

0 commit comments

Comments
 (0)