Skip to content

Commit 83d86e7

Browse files
committed
Make sure the wildcard lookup uses the right starr app
Fix the log endpoint list being able to add empty endpoints
1 parent 743a127 commit 83d86e7

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

root/app/www/public/api/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
apiResponse($code, $response);
154154
} else {
155155
$proxiedApp = $starr->getAppFromProxiedKey($apikey);
156+
$app = $starr->getStarrInterfaceNameFromId($proxiedApp['starrAppDetails']['starr']);
156157

157158
if (!$proxiedApp) {
158159
logger($logfile, $apikey, $endpoint, 401);
@@ -169,7 +170,7 @@
169170
readfile($proxyBackup);
170171
}
171172
} else {
172-
$isAllowedEndpoint = $starr->isAllowedEndpoint($proxiedApp['access'], $endpoint);
173+
$isAllowedEndpoint = $starr->isAllowedEndpoint($app, $proxiedApp['access'], $endpoint);
173174
$starrEndpoint = $isAllowedEndpoint['starrEndpoint'];
174175
$isAllowed = $isAllowedEndpoint['allowed'];
175176

root/app/www/public/classes/Starr.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ public function getAppFromStarrKey($apikey, $starrsTable)
228228
return [];
229229
}
230230

231-
public function findWildcardEndpoint($endpoint)
231+
public function findWildcardEndpoint($starrApp, $endpoint)
232232
{
233-
foreach (StarrApps::LIST as $starrApp) {
233+
foreach (StarrApps::LIST as $listStarr) {
234+
if (strtolower($listStarr) != strtolower($starrApp)) {
235+
continue;
236+
}
237+
234238
$endpoints = $this->getEndpoints(strtolower($starrApp));
235239

236240
$endpointRegexes = ['/(.*)\/(.*)\/(.*)/', '/(.*)\/(.*)/'];
@@ -265,9 +269,9 @@ public function findWildcardEndpoint($endpoint)
265269
return;
266270
}
267271

268-
public function isAllowedEndpoint($endpoints, $endpoint)
272+
public function isAllowedEndpoint($starrApp, $endpoints, $endpoint)
269273
{
270-
if (!$endpoint) {
274+
if (!$starrApp || !$endpoint) {
271275
return ['allowed' => false];
272276
}
273277

@@ -279,7 +283,7 @@ public function isAllowedEndpoint($endpoints, $endpoint)
279283

280284
// CHECK IF THE ENDPOINT HAS WILDCARDS: /{...}/{...} OR /{...}
281285
if (!$endpoints[$endpoint]) {
282-
$wildcard = $this->findWildcardEndpoint($endpoint);
286+
$wildcard = $this->findWildcardEndpoint($starrApp, $endpoint);
283287
return ['allowed' => $endpoints[$wildcard], 'starrEndpoint' => $wildcard];
284288
}
285289

root/app/www/public/functions/logger.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,24 @@ function getLog($logfile, $page = 1, $app = false)
189189
<?php
190190
if ($app) {
191191
$proxiedApp = $starr->getAppFromProxiedKey($_POST['key'], true);
192+
$starrApp = $starr->getStarrInterfaceNameFromId($proxiedApp['starrAppDetails']['starr']);
193+
192194
?>
193195
<div class="tab-pane fade" id="endpoints" role="tabpanel">
194196
<h4>Endpoint usage <span class="text-small">(<?= count($endpointUsage) ?> endpoint<?= count($endpointUsage) == 1 ? '' : 's' ?>)</span></h4>
195197
<?php
196198
foreach ($endpointUsage as $endpoint => $methods) {
197-
$isAllowedEndpoint = $starr->isAllowedEndpoint($proxiedApp['access'], $endpoint);
199+
$isAllowedEndpoint = $starr->isAllowedEndpoint($starrApp, $proxiedApp['access'], $endpoint);
198200
$starrEndpoint = $isAllowedEndpoint['starrEndpoint'];
199201
$isAllowed = $isAllowedEndpoint['allowed'];
200202

201203
foreach ($methods as $method => $usage) {
202204
$isAllowedEndpointMethod = $isAllowed ? $starr->isAllowedEndpointMethod($proxiedApp['access'], $starrEndpoint, $method) : false;
203205

204206
?>
205-
<i id="disallowed-endpoint-<?= md5($starrEndpoint.$method) ?>" class="far fa-times-circle text-danger" title="Disallowed endpoint, click to allow it" style="display: <?= !$isAllowedEndpointMethod ? 'inline-block' : 'none' ?>; cursor: pointer;" onclick="addEndpointAccess('<?= $app ?>', <?= $proxiedApp['proxiedAppDetails']['id'] ?>, '<?= $starrEndpoint ?>', '<?= $method ?>', '<?= md5($starrEndpoint.$method) ?>')"></i>
206-
<i id="allowed-endpoint-<?= md5($starrEndpoint.$method) ?>" class="far fa-check-circle text-success" title="Allowed endpoint, click to block it" style="display: <?= $isAllowedEndpointMethod ? 'inline-block' : 'none' ?>; cursor: pointer;" onclick="removeEndpointAccess('<?= $app ?>', <?= $proxiedApp['proxiedAppDetails']['id'] ?>, '<?= $starrEndpoint ?>', '<?= $method ?>', '<?= md5($starrEndpoint.$method) ?>')"></i>
207-
[<?= strtoupper($method) ?>] <?= ($starrEndpoint != $endpoint ? $starrEndpoint . '' : '') . $endpoint . ': ' . number_format($usage) ?> hit<?= $usage == 1 ? '' : 's' ?><br>
207+
<i id="disallowed-endpoint-<?= md5($starrEndpoint.$method) ?>" class="far fa-times-circle text-danger" title="Disallowed endpoint, click to allow it" style="display: <?= !$isAllowedEndpointMethod ? 'inline-block' : 'none' ?>; cursor: pointer;" onclick="addEndpointAccess('<?= $app ?>', <?= $proxiedApp['proxiedAppDetails']['id'] ?>, '<?= $starrEndpoint ?: $endpoint ?>', '<?= $method ?>', '<?= md5($starrEndpoint.$method) ?>')"></i>
208+
<i id="allowed-endpoint-<?= md5($starrEndpoint.$method) ?>" class="far fa-check-circle text-success" title="Allowed endpoint, click to block it" style="display: <?= $isAllowedEndpointMethod ? 'inline-block' : 'none' ?>; cursor: pointer;" onclick="removeEndpointAccess('<?= $app ?>', <?= $proxiedApp['proxiedAppDetails']['id'] ?>, '<?= $starrEndpoint ?: $endpoint ?>', '<?= $method ?>', '<?= md5($starrEndpoint.$method) ?>')"></i>
209+
[<?= strtoupper($method) ?>] <?= ($starrEndpoint && $starrEndpoint != $endpoint ? $starrEndpoint . '' : '') . $endpoint . ': ' . number_format($usage) ?> hit<?= $usage == 1 ? '' : 's' ?><br>
208210
<?php
209211
}
210212
}

0 commit comments

Comments
 (0)