Base path support (optional): - If FileRise is served under a subpath (e.g. https://example.com/fr), set `FR_BASE_PATH=/fr` or send `X-Forwarded-Prefix: /fr` from the proxy. - When not set, defaults to "" (root install) to preserve existing behavior.
($raw)
| 544 | // set `FR_BASE_PATH=/fr` or send `X-Forwarded-Prefix: /fr` from the proxy. |
| 545 | // - When not set, defaults to "" (root install) to preserve existing behavior. |
| 546 | function fr_normalize_base_path($raw) |
| 547 | { |
| 548 | $p = trim((string)$raw); |
| 549 | if ($p === '' || $p === '/') return ''; |
| 550 | // Reject full URLs or scheme-relative prefixes to avoid open redirects. |
| 551 | if (preg_match('~^[a-z][a-z0-9+.-]*://~i', $p)) return ''; |
| 552 | if (strpos($p, '//') === 0) return ''; |
| 553 | // Normalize slashes and strip query/fragment if provided. |
| 554 | $p = str_replace('\\', '/', $p); |
| 555 | $p = preg_replace('/[?#].*$/', '', $p); |
| 556 | if ($p === '' || $p === '/') return ''; |
| 557 | if ($p[0] !== '/') $p = '/' . $p; |
| 558 | $p = preg_replace('~/+~', '/', $p); |
| 559 | // Disallow path traversal segments. |
| 560 | if (preg_match('~(^|/)\.\.(?:/|$)~', $p)) return ''; |
| 561 | // strip trailing slashes |
| 562 | return preg_replace('~/+$~', '', $p) ?: ''; |
| 563 | } |
| 564 | |
| 565 | function fr_detect_base_path() |
| 566 | { |
no outgoing calls
no test coverage detected