Skip to content

Commit

Permalink
ファイル管理で許可した拡張子以外アップロード不可に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Nov 15, 2022
1 parent b36f749 commit 42da928
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
13 changes: 13 additions & 0 deletions app/config/eccube/packages/eccube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,18 @@ parameters:
- admin_content_css
- admin_content_js
- admin_store_template_install
eccube_file_uploadable_extensions: # ファイル管理でアップロード可能な拡張子
- jpg
- jpeg
- png
- gif
- webp
- ico
- html
- htm
- js
- css
- txt
- pdf
eccube_login_throttling_max_attempts: 5
eccube_login_throttling_interval: '30 minutes'
8 changes: 4 additions & 4 deletions src/Eccube/Controller/Admin/Content/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ public function upload(Request $request)
if (!preg_match('/\A[a-zA-Z0-9_\-\.\(\) ]+\Z/', $filename)) {
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.folder_name_symbol_error'));
}
// phpファイルはアップロード不可
if ($file->getClientOriginalExtension() === 'php') {
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.phpfile_error'));
}
// dotファイルはアップロード不可
if (strpos($filename, '.') === 0) {
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.dotfile_error'));
}
// 許可した拡張子以外アップロード不可
if (!in_array(strtolower($file->getClientOriginalExtension()), $this->eccubeConfig['eccube_file_uploadable_extensions'], true)) {
throw new UnsupportedMediaTypeHttpException(trans('admin.content.file.extension_error'));
}
} catch (UnsupportedMediaTypeHttpException $e) {
if (!in_array($e->getMessage(), array_column($this->errors, 'message'))) {
$this->errors[] = ['message' => $e->getMessage()];
Expand Down
3 changes: 2 additions & 1 deletion src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,9 @@ admin.content.file.folder_name_symbol_error: The folder name contains invalid ch
admin.content.file.folder_name_period_error: Folder names beginning with a period(.) are not allowed.
admin.content.file.dir_exists: '%file_name% is already exists.'
admin.content.file.same_name_folder_exists: 'Cannot upload because a folder with the same name as the file exists.'
admin.content.file.phpfile_error: 'php files cannot be uploaded.'
admin.content.file.phpfile_error: 'php files cannot be uploaded.' # Unused
admin.content.file.dotfile_error: 'Dot files cannot be uploaded.'
admin.content.file.extension_error: 'File extension cannot be uploaded.'
admin.content.layout_delete: Delete Layouts
admin.content.layout_no_page: Page not registered
admin.content.layout__card_title: Layout Overview
Expand Down
3 changes: 2 additions & 1 deletion src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,9 @@ admin.content.file.folder_name_symbol_error: 使用できない文字が含ま
admin.content.file.folder_name_period_error: ピリオド(.)で始まる名前は使用できません。
admin.content.file.dir_exists: '%file_name% は既に使用されています。別のフォルダ名を入力してください'
admin.content.file.same_name_folder_exists: 'ファイルと同じ名前のフォルダが存在するためアップロードできません。'
admin.content.file.phpfile_error: 'phpファイルはアップロードできません。'
admin.content.file.phpfile_error: 'phpファイルはアップロードできません。' # 未使用
admin.content.file.dotfile_error: '.で始まるファイルはアップロードできません。'
admin.content.file.extension_error: 'アップロードできないファイル拡張子です。'
admin.content.layout_delete: レイアウトを削除
admin.content.layout_no_page: ページが登録されていません
admin.content.layout__card_title: レイアウト概要
Expand Down

0 comments on commit 42da928

Please sign in to comment.