|
169 | 169 | readfile($proxyBackup); |
170 | 170 | } |
171 | 171 | } else { |
172 | | - // CHECK IF THE ENDPOINT HAS WILDCARDS: /{...}/{...} OR /{...} |
173 | | - if (!$proxiedApp['access'][$endpoint]) { |
174 | | - $endpointRegexes = ['/(.*)\/(.*)\/(.*)/', '/(.*)\/(.*)/']; |
175 | | - $wildcardRegexes = ['/(.*)({.*})\/({.*})/', '/(.*)({.*})/']; |
176 | | - $wildcard = false; |
| 172 | + if ($accessEndpoint = $starr->isAllowedEndpoint($proxiedApp['access'], $endpoint)) { |
| 173 | + $endpoint = $accessEndpoint; |
| 174 | + } else { |
| 175 | + logger($logfile, $apikey, $endpoint, 401); |
| 176 | + logger(str_replace('access.log', 'access_' . $proxiedApp['proxiedAppDetails']['name'] . '.log', $logfile), $apikey, $endpoint, 401); |
| 177 | + $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], 401); |
177 | 178 |
|
178 | | - foreach ($wildcardRegexes as $index => $wildcardRegex) { |
179 | | - preg_match($endpointRegexes[$index], $endpoint, $requestMatches); |
180 | | - |
181 | | - if (!$requestMatches) { |
182 | | - continue; |
183 | | - } |
184 | | - |
185 | | - foreach ($proxiedApp['access'] as $accessEndpoint => $accessMethods) { |
186 | | - preg_match($wildcardRegex, $accessEndpoint, $accessMatches); |
187 | | - |
188 | | - if (!$accessMatches) { |
189 | | - continue; |
190 | | - } |
191 | | - |
192 | | - if ($accessMatches[1] == $requestMatches[1] . '/') { |
193 | | - if (count($accessMatches) == count($requestMatches)) { |
194 | | - $wildcard = true; |
195 | | - $endpoint = $accessEndpoint; //-- ALLOW LATER CHECKS TO PASS |
196 | | - break; |
197 | | - } |
198 | | - } |
199 | | - } |
200 | | - |
201 | | - if ($wildcard) { |
202 | | - break; |
203 | | - } |
| 179 | + if ($proxyDb->isNotificationTriggerEnabled('blocked')) { |
| 180 | + $payload = [ |
| 181 | + 'event' => 'blocked', |
| 182 | + 'proxyApp' => $proxiedApp['proxiedAppDetails']['name'], |
| 183 | + 'starrApp' => $proxiedApp['starrAppDetails']['name'], |
| 184 | + 'endpoint' => $endpoint |
| 185 | + ]; |
| 186 | + $notifications->notify(0, 'blocked', $payload); |
204 | 187 | } |
205 | 188 |
|
206 | | - if (!$wildcard) { |
207 | | - logger($logfile, $apikey, $endpoint, 401); |
208 | | - logger(str_replace('access.log', 'access_' . $proxiedApp['proxiedAppDetails']['name'] . '.log', $logfile), $apikey, $endpoint, 401); |
209 | | - $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], 401); |
210 | | - |
211 | | - if ($proxyDb->isNotificationTriggerEnabled('blocked')) { |
212 | | - $payload = [ |
213 | | - 'event' => 'blocked', |
214 | | - 'proxyApp' => $proxiedApp['proxiedAppDetails']['name'], |
215 | | - 'starrApp' => $proxiedApp['starrAppDetails']['name'], |
216 | | - 'endpoint' => $endpoint |
217 | | - ]; |
218 | | - $notifications->notify(0, 'blocked', $payload); |
219 | | - } |
220 | | - |
221 | | - apiResponse(401, ['error' => sprintf(APP_API_ERROR, 'provided apikey is missing access to ' . $endpoint)]); |
222 | | - } |
| 189 | + apiResponse(401, ['error' => sprintf(APP_API_ERROR, 'provided apikey is missing access to ' . $endpoint)]); |
223 | 190 | } |
224 | 191 |
|
225 | | - if (!in_array($method, $proxiedApp['access'][$endpoint])) { |
| 192 | + if (!$accessMethod = $starr->isAllowedEndpointMethod($proxiedApp['access'], $endpoint, $method)) { |
226 | 193 | logger($logfile, $apikey, $endpoint, 405); |
227 | 194 | logger(str_replace('access.log', 'access_' . $proxiedApp['proxiedAppDetails']['name'] . '.log', $logfile), $apikey, $endpoint, 405); |
228 | 195 | $usageDb->adjustAppUsage($proxiedApp['proxiedAppDetails']['id'], 405); |
|
0 commit comments