From 84d2c02a097d018098aebc21b01e6a70e27f35e4 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 5 Aug 2017 23:30:24 +0200 Subject: [PATCH] whitelist: Do case-insensitive whitelist matching Matching whitelisted bridges using a case-insensitive match makes sense for following reasons: - Wrong upper/lower case spelling in the whitelist is not easily discovered. Example: Misspelling 'Youtube' as 'YouTube' will not show the 'Youtube' bridge (while it is expected to show) - Two bridges with the same name but different letter casing are discouraged to prevent confusion and keep the project compatible with Windows machines --- index.php | 7 +++++-- lib/Bridge.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 0c4d94fe..70b80cb4 100644 --- a/index.php +++ b/index.php @@ -119,6 +119,9 @@ try { } else { $whitelist_selection = Bridge::listBridges(); } + + // Prepare for case-insensitive match + $whitelist_selection = array_map('strtolower', $whitelist_selection); } $action = filter_input(INPUT_GET, 'action'); @@ -140,7 +143,7 @@ try { } // whitelist control - if(!Bridge::isWhitelisted($whitelist_selection, $bridge)) { + if(!Bridge::isWhitelisted($whitelist_selection, strtolower($bridge))) { throw new \HttpException('This bridge is not whitelisted', 401); die; } @@ -246,7 +249,7 @@ EOD; $inactiveBridges = ''; $bridgeList = Bridge::listBridges(); foreach($bridgeList as $bridgeName) { - if(Bridge::isWhitelisted($whitelist_selection, $bridgeName)) { + if(Bridge::isWhitelisted($whitelist_selection, strtolower($bridgeName))) { echo displayBridgeCard($bridgeName, $formats); $activeFoundBridgeCount++; } elseif($showInactive) { diff --git a/lib/Bridge.php b/lib/Bridge.php index d0a127ef..42a8b647 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -94,8 +94,8 @@ EOD; static public function isWhitelisted($whitelist, $name){ if(in_array($name, $whitelist) || in_array($name . '.php', $whitelist) - || in_array($name . 'Bridge', $whitelist) // DEPRECATED - || in_array($name . 'Bridge.php', $whitelist) // DEPRECATED + || in_array($name . 'bridge', $whitelist) // DEPRECATED + || in_array($name . 'bridge.php', $whitelist) // DEPRECATED || (count($whitelist) === 1 && trim($whitelist[0]) === '*')) { return true; } else {