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 plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,14 @@ public static function isSameReferrerAsCurrent()
*/
public static function isSameOriginAsCurrent()
{
$https = !empty($_SERVER['HTTPS']) && strtolower((string)$_SERVER['HTTPS']) !== 'off';
// TRUST_PROXY=true 環境では $_SERVER['HTTPS'] がリバースプロキシ配下で
// 設定されないため、BcRequestFilterMiddleware が trustProxy 済みで上書きする
// $request->is('https') を優先して使う。
// 取得できない場合のみ $_SERVER を見る。
$request = Router::getRequest();
$https = $request
? $request->is('https')
: (!empty($_SERVER['HTTPS']) && strtolower((string)$_SERVER['HTTPS']) !== 'off');
$host = $_SERVER['HTTP_HOST'] ?? '';
if ($host === '') {
return false;
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,10 @@ public static function isSameReferrerAsCurrentDataProvider()
*/
public function testIsSameOriginAsCurrent(array $server, bool $expected)
{
// 準備:他のテスト(test_getViewPath等)が残した Router::setRequest() の残留状態が
// Router::getRequest() 経由の判定に影響しないよう、リクエストをクリアする
Router::reload();

// 準備:判定に使う $_SERVER をクリアしてから流し込む
foreach (['HTTPS', 'HTTP_HOST', 'HTTP_ORIGIN', 'HTTP_REFERER'] as $key) {
unset($_SERVER[$key]);
Expand Down
Loading