Skip to content

Commit c5b8fae

Browse files
committed
fix(proxy): match route URL against request path with leading slash (HaRP alignment, with legacy fallback)
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent c865d78 commit c5b8fae

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/Controller/ExAppProxyController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,20 @@ private function buildMultipartFormData(array $bodyParams, array $files): array
312312
}
313313

314314
private function passesExAppProxyRoutesChecks(ExApp $exApp, string $exAppRoute): array {
315+
// Route URL is a regex matched against the request path including its leading slash, mirroring HaRP's target_path semantics.
316+
$canonicalSubject = '/' . $exAppRoute;
315317
foreach ($exApp->getRoutes() as $route) {
316318
$pattern = '~^(?:' . str_replace('~', '\\~', $route['url']) . ')~i';
317-
if (preg_match($pattern, $exAppRoute) === 1 &&
319+
$matched = preg_match($pattern, $canonicalSubject) === 1;
320+
if (!$matched && preg_match($pattern, $exAppRoute) === 1) {
321+
// TODO(deprecation): remove this bare-path fallback once known ExApps have migrated their info.xml route URLs to the canonical `^/path$` form. Tracked by the AppAPI / context_chat_backend coordination effort.
322+
$this->logger->debug(sprintf(
323+
'ExApp "%s" matched route "%s" via legacy bare-path fallback. Update the info.xml route URL to start with "/" or "^/" so it matches against "%s".',
324+
$exApp->getAppid(), $route['url'], $canonicalSubject
325+
));
326+
$matched = true;
327+
}
328+
if ($matched &&
318329
str_contains(strtolower($route['verb']), strtolower($this->request->getMethod()))
319330
) {
320331
// First match by path+verb wins. Apply its access level without falling through to broader routes.

0 commit comments

Comments
 (0)