Skip to content

Commit 7d7a64b

Browse files
committed
Disallow using line breaks in database configuration during setup process
1 parent 1035d0f commit 7d7a64b

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

app/Http/Requests/SetupDatabaseRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ public function rules(): array
1818
],
1919
'db_host' => [
2020
'required_unless:connection,sqlite',
21+
'not_regex:/[\r\n]/',
2122
],
2223
'db_port' => [
2324
'required_unless:connection,sqlite',
2425
'numeric',
2526
],
2627
'db_name' => [
2728
'required_unless:connection,sqlite',
29+
'not_regex:/[\r\n]/',
2830
],
2931
'db_user' => [
3032
'required_unless:connection,sqlite',
33+
'not_regex:/[\r\n]/',
3134
],
3235
'db_password' => [
3336
'nullable',
37+
'not_regex:/[\r\n]/',
3438
],
3539
];
3640
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Tests\Controller;
4+
5+
use App\Settings\SystemSettings;
6+
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Tests\TestCase;
8+
9+
class SetupDatabaseControllerTest extends TestCase
10+
{
11+
use RefreshDatabase;
12+
13+
public function test_database_setup_rejects_multiline_passwords(): void
14+
{
15+
SystemSettings::fake([
16+
'setup_completed' => false,
17+
]);
18+
19+
$response = $this->from('/setup/database')->post('/setup/database', [
20+
'connection' => 'mysql',
21+
'db_host' => '127.0.0.1',
22+
'db_port' => 3306,
23+
'db_name' => 'linkace',
24+
'db_user' => 'linkace',
25+
'db_password' => "secret\nMAIL_MAILER=sendmail",
26+
]);
27+
28+
$response
29+
->assertRedirect('/setup/database')
30+
->assertSessionHasErrors('db_password');
31+
}
32+
}

0 commit comments

Comments
 (0)