Skip to content

Colota - Android GPS Location tracker

Fix IPv4 validation, dark style cache retry, and parse error logging

Max Dietriche0249d29fbdf
diff --git a/apps/mobile/src/components/features/map/ColotaMapView.tsx b/apps/mobile/src/components/features/map/ColotaMapView.tsx
index 28db4557..08aab368 100644
--- a/apps/mobile/src/components/features/map/ColotaMapView.tsx
+++ b/apps/mobile/src/components/features/map/ColotaMapView.tsx
@@ -18,9 +18,9 @@ const OPENFREEMAP_STYLE = "https://tiles.openfreemap.org/styles/bright"
/** Cached dark style object so we only fetch + transform once */
let cachedDarkStyle: object | null = null
-let darkStyleFetchPromise: Promise<object> | null = null
+let darkStyleFetchPromise: Promise<object | null> | null = null
-async function getDarkStyle(): Promise<object> {
+async function getDarkStyle(): Promise<object | null> {
if (cachedDarkStyle) return cachedDarkStyle
if (darkStyleFetchPromise) return darkStyleFetchPromise
darkStyleFetchPromise = fetch(OPENFREEMAP_STYLE)
@@ -32,7 +32,7 @@ async function getDarkStyle(): Promise<object> {
})
.catch(() => {
darkStyleFetchPromise = null
- return { version: 8, sources: {}, layers: [] }
+ return null
})
return darkStyleFetchPromise
}
@@ -66,7 +66,9 @@ export const ColotaMapView = forwardRef<ColotaMapRef, Props>(function ColotaMapV
useEffect(() => {
if (isDark && !darkStyle) {
- getDarkStyle().then(setDarkStyle)
+ getDarkStyle().then((style) => {
+ if (style) setDarkStyle(style)
+ })
}
}, [isDark, darkStyle])
diff --git a/apps/mobile/src/contexts/TrackingProvider.tsx b/apps/mobile/src/contexts/TrackingProvider.tsx
index d6a93222..a4675dcb 100644
--- a/apps/mobile/src/contexts/TrackingProvider.tsx
+++ b/apps/mobile/src/contexts/TrackingProvider.tsx
@@ -59,7 +59,8 @@ function parseRawSettings(allRaw: Record<string, string>): Settings {
fieldMap: (() => {
try {
return allRaw.fieldMap ? JSON.parse(allRaw.fieldMap) : DEFAULT_SETTINGS.fieldMap
- } catch {
+ } catch (err) {
+ logger.warn("[TrackingContext] Corrupted fieldMap, using defaults:", err)
return DEFAULT_SETTINGS.fieldMap
}
})(),
@@ -67,7 +68,8 @@ function parseRawSettings(allRaw: Record<string, string>): Settings {
customFields: (() => {
try {
return allRaw.customFields ? JSON.parse(allRaw.customFields) : DEFAULT_SETTINGS.customFields
- } catch {
+ } catch (err) {
+ logger.warn("[TrackingContext] Corrupted customFields, using defaults:", err)
return DEFAULT_SETTINGS.customFields
}
})(),
diff --git a/apps/mobile/src/utils/settingsValidation.ts b/apps/mobile/src/utils/settingsValidation.ts
index 55413991..0353f10c 100644
--- a/apps/mobile/src/utils/settingsValidation.ts
+++ b/apps/mobile/src/utils/settingsValidation.ts
@@ -16,19 +16,25 @@ export function findDuplicates(values: string[]): Set<string> {
return dupes
}
+function isPrivateIP(host: string): boolean {
+ const parts = host.split(".")
+ if (parts.length !== 4) return false
+ const octets = parts.map(Number)
+ if (octets.some((o) => isNaN(o) || o < 0 || o > 255)) return false
+ const [a, b] = octets
+ return (
+ (a === 127 && octets[1] === 0 && octets[2] === 0 && octets[3] === 1) ||
+ a === 10 ||
+ (a === 192 && b === 168) ||
+ (a === 172 && b >= 16 && b <= 31)
+ )
+}
+
export function isPrivateHost(url: string) {
try {
- // Strip protocol
const stripped = url.replace(/^https?:\/\//, "").split(/[/?#]/)[0]
- // Extract host (before any port)
const host = stripped.split(":")[0]
-
- // Validate host: must be valid IP or hostname
- const ipRegex =
- /^(127\.0\.0\.1|10\.(\d{1,3}\.){2}\d{1,3}|192\.168\.(\d{1,3}\.)\d{1,3}|172\.(1[6-9]|2\d|3[0-1])\.(\d{1,3}\.)\d{1,3})$/
- const hostnameRegex = /^localhost$/
-
- return ipRegex.test(host) || hostnameRegex.test(host)
+ return isPrivateIP(host) || host === "localhost"
} catch {
return false
}