Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion Form/Type/Admin/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;

class ConfigType extends AbstractType
{
Expand Down Expand Up @@ -36,10 +37,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('auth_magic', TextType::class, [
'label' => 'AUTH_MAGIC',
'required' => true,
//'placeholder' => '',
'attr' => [
'placeholder' => "旧サイトのAUTH_MAGICを入力してください。",
],
'constraints' => [
new NotBlank(['message' => 'AUTH_MAGICを入力してください。']),
new Regex([
'pattern' => '/^[a-zA-Z0-9_\-\.]+$/',
'message' => 'AUTH_MAGICには英数字、アンダースコア、ハイフン、ドットのみ使用できます。',
]),
],
])
;
}
Expand Down
6 changes: 6 additions & 0 deletions Service/DataMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public function isVersion($version)

public function updateEnv($newMagicValue)
{
// 改行を除去し、安全な文字のみ許可(.envインジェクション対策)
$newMagicValue = str_replace(["\r", "\n"], '', $newMagicValue);
if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $newMagicValue)) {
throw new \InvalidArgumentException('AUTH_MAGIC に使用できない文字が含まれています。');
}

$projectDir = $this->params->get('kernel.project_dir');
$envFile = $projectDir . '/.env';

Expand Down