EC-CUBE / EC-CUBE/ec-cube

サブディレクトリの.htaccess によるアクセス拒否が機能しなくなった(4.0.6以降)

Open
#5,358 3 comments 0 reactions 0 assignees View on GitHub
improvement
Dominant language
PHP
Stars
788
Forks
719
Avg merge
3d 20h
Merged PRs (30d)
45

Description

## 概要(Overview)

サブディレクトリに以下のような.htaccessを配置しても、アクセス拒否が行われない。
```
order allow,deny
deny from all
```

4.0.6対応の中で行われた以下の.htaccessのFileMatchブロックの記述による許可設定が優先されているため?

該当のFileMatch記述を削除すると、再度サブディレクトリの.htaccessによるアクセス拒否が機能するようになります
```.htaccess

SetEnvIf Request_URI "/vendor/" deny_dir
Order allow,deny
Deny from env=deny_dir
Allow from all

```

https://github.com/EC-CUBE/ec-cube/pull/5073/commits/e689164e09ed43deab0b139c86416cd515ceb70c#diff-270939b4fba4be968ab78e23dc0207eb893744491980a25c99a27c809a82ddabR13

### 本体開発のみでは問題とならない理由
本体の現状としては、サブディレクトリの.htaccessが機能しなくなっても `RewriteRule "^vendor/" - [F]` 等の記述で二重に守られているため、支障がない状況と思います。

ただ、カスタマイズで独自にフォルダを作成する場合等の落とし穴になりやすいと感じるため、回避できた方がうれしい
(もちろん独自にそのようなカスタマイズする場合はサブディレクトリの.htaccessのみに頼らず、vendor等と同様RewriteRule等で多重に対策すべきとは思いますが)

## 期待する内容(Expect) or 要望 (Requirement)

サブディレクトリに以下を記述した.htaccessを配置すると、該当ディレクトリへのアクセスが拒否されること

```
order allow,deny
deny from all
```

## 再現手順(Procedure)
- testdir 等のカスタムディレクトリを作成
- testdir/.htaccess を配置(deny from all)
- testdir/test.csv, testdir/test.txt, testdir/test.png 等を配置

以下のようなURLでアクセスすると、アクセス出来てしまう。
- http://example.com/testdir/test.txt
- http://example.com/testdir/test.csv
- http://example.com/testdir/test.png

該当のFileMatch記述をコメントアウトすると、403エラーになるようになる

### 環境 (environment)
+ EC-CUBE: 4.0.6-p1
+ Apache: 2.4.53(IUS)
+ PHP: 7.4.29

## 関連情報 (Ref)

## 備考
本件、事前にEC-CUBEサポートへ連絡し、本体の脆弱性としては扱わない旨確認済

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the .htaccess FileMatch block introduced for 4.0.6 and reproduce the behavior with testdir/.htaccess containing the reported deny rules and the listed test files. Done means requests to testdir/test.txt, test.csv, and test.png are denied with a 403 response while the existing protected paths continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
apache, php
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.