MCPcopy Create free account
hub / github.com/error311/FileRise / fr_normalize_base_path

Function fr_normalize_base_path

config/config.php:546–563  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
546function 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
565function fr_detect_base_path()
566{

Callers 1

fr_detect_base_pathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected