mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
Pin camera sources by parsed URL
Camera catalog image URLs were pinned by string prefix, so a URL that only began with the agency's directory before dot segments or an encoded separator were resolved still counted as inside it. The pin now parses the URL and requires the same scheme, the exact host, no credentials, the default port and a normalized path inside the pinned directory. Redirects on a pinned host must stay inside the same directory. Document the response format checks and API response headers alongside the existing server hardening notes.
This commit is contained in:
1 parent
0ad75095a7
commit
3e80afe713
8 files changed
+241
-31
No files matched your search
@@ -659,3 +659,36 @@ export function isLikelyTorontoCoordinate(lat, lon) {
|
||||
lon <= -79.1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A camera URL under a pinned directory, by parsed URL rather than string
|
||||
* prefix: the same scheme and exact host as `prefix`, no credentials, the
|
||||
* default port, and a normalized path inside the prefix's directory. Dot
|
||||
* segments (including encoded ones) are resolved before the path is compared,
|
||||
* and an encoded slash or backslash is refused.
|
||||
*
|
||||
* @param {string} raw - Camera URL from a catalog or redirect.
|
||||
* @param {string} prefix - Pinned origin and directory, ending in `/`.
|
||||
* @returns {string|null} The normalized URL, or null when it is not pinned.
|
||||
*/
|
||||
export function pinnedCameraUrl(raw, prefix) {
|
||||
let url;
|
||||
let pin;
|
||||
try {
|
||||
url = new URL(String(raw ?? '').trim());
|
||||
pin = new URL(prefix);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
url.protocol !== pin.protocol ||
|
||||
url.hostname !== pin.hostname ||
|
||||
url.username ||
|
||||
url.password ||
|
||||
url.port ||
|
||||
!url.pathname.startsWith(pin.pathname) ||
|
||||
/%2f|%5c|\\/i.test(url.pathname)
|
||||
)
|
||||
return null;
|
||||
return url.href;
|
||||
}
|
||||
Reference in new issue
Block a user