Skip to content

Colota - Android GPS Location tracker

fix(setup-link): show the full endpoint host on import and reject a link whose address hides it (#887)

Max Dietrichb7bc005364b1
diff --git a/apps/docs/docs/guides/deep-link-setup.md b/apps/docs/docs/guides/deep-link-setup.md
index 52073c08..febf6ce3 100644
--- a/apps/docs/docs/guides/deep-link-setup.md
+++ b/apps/docs/docs/guides/deep-link-setup.md
@@ -31,7 +31,7 @@ Geofences and tracking profiles can also be shared on their own from the [Geofen
<ScreenshotGallery screenshots={[ { src: "/img/screenshots/SetupImport.png", label: "Import configuration" }, ]} />
1. User taps the link or scans a QR code
-2. Colota opens and shows a confirmation screen listing all settings that will be applied
+2. Colota opens and shows a confirmation screen listing all settings that will be applied. The server address is shown in full with its host on a separate line. A link that replaces a configured server names the server it replaces.
3. Sensitive values (passwords, tokens) are masked in the preview
4. User taps **Apply Configuration** to save or **Cancel** to discard
5. Settings are persisted and the app navigates to the Dashboard
@@ -48,7 +48,7 @@ The `config` parameter is a base64-encoded JSON object. Only include the setting
| Parameter | Type | Description |
| --- | --- | --- |
-| `endpoint` | string | Server URL to send location data to |
+| `endpoint` | string | Server URL to send location data to. A host written as `user@host` or containing a backslash rejects the whole link. |
| `interval` | number | GPS polling interval in seconds (must be > 0) |
| `distance` | number | Minimum movement in meters before recording a new location |
| `syncInterval` | number | Batch sync interval in seconds (0 = instant) |
@@ -147,3 +147,5 @@ print(f'colota://setup?config={encoded}')
- The configuration URL is not encrypted. Avoid putting sensitive tokens in QR codes displayed in public.
- All settings are shown to the user for confirmation before being applied.
+- A link whose server address is rejected cannot be applied at all. The screen shows the reason and offers only **Go back**.
+- Any app, web page or message can open a `colota://setup` link. Apply one only if you trust where it came from, and read the host under **Sends locations to** before applying.
diff --git a/apps/mobile/src/screens/SetupImportScreen.tsx b/apps/mobile/src/screens/SetupImportScreen.tsx
index 46463e02..9ffd83d2 100644
--- a/apps/mobile/src/screens/SetupImportScreen.tsx
+++ b/apps/mobile/src/screens/SetupImportScreen.tsx
@@ -19,13 +19,19 @@ import {
StatRow,
Toggle
} from "../components"
-import { fontSizes, fonts, lineHeights } from "../styles/typography"
+import { fontSizes, fonts, lineHeights, type } from "../styles/typography"
import { Check, CircleAlert } from "lucide-react-native"
import NativeLocationService from "../services/NativeLocationService"
import { showAlert } from "../services/modalService"
import { logger } from "../utils/logger"
import { type Settings } from "../types/global"
-import { validateConfig, detectPreset, type ConfigEntry, type ValidationResult } from "../utils/setupConfig"
+import {
+ validateConfig,
+ detectPreset,
+ setupEndpointHost,
+ type ConfigEntry,
+ type ValidationResult
+} from "../utils/setupConfig"
import { decodeConfig } from "../utils/setupLink"
import { space } from "../constants"
@@ -135,6 +141,20 @@ export function SetupImportScreen({ route, navigation }: any) {
}
}
+ // The endpoint decides where every location goes, so it is never cut to one line like a StatRow value.
+ const renderEndpoint = (entry: ConfigEntry) => {
+ const current = currentSettings.endpoint
+ const currentHost = current && current !== entry.value ? (setupEndpointHost(current) ?? current) : null
+ return (
+ <View style={styles.endpoint}>
+ <Text style={[styles.endpointLabel, { color: colors.textSecondary }]}>Sends locations to</Text>
+ <Text style={[styles.endpointHost, { color: colors.text }]}>{setupEndpointHost(entry.value)}</Text>
+ <Text style={[type.mono, { color: colors.textSecondary }]}>{entry.value}</Text>
+ {currentHost && <FieldMessage variant="warning">Replaces your current server, {currentHost}</FieldMessage>}
+ </View>
+ )
+ }
+
const renderSection = (title: string, entries: ConfigEntry[]) => {
if (entries.length === 0) return null
return (
@@ -144,9 +164,7 @@ export function SetupImportScreen({ route, navigation }: any) {
{entries.map((entry, i) => (
<React.Fragment key={entry.label}>
{i > 0 && <Divider tight />}
- {/* A rejected entry carries a reason where a value would be, so it gets both. */}
- <StatRow label={entry.label} value={entry.rejected ? "Not applied" : entry.value} />
- {entry.rejected && <FieldMessage variant="error">{entry.value}</FieldMessage>}
+ {entry.label === "Endpoint" ? renderEndpoint(entry) : <StatRow label={entry.label} value={entry.value} />}
</React.Fragment>
))}
</Card>
@@ -182,7 +200,8 @@ export function SetupImportScreen({ route, navigation }: any) {
<Container>
<ScrollView contentContainerStyle={styles.content}>
<Text style={[styles.subtitle, { color: colors.textSecondary }]}>
- A setup link wants to apply {result.entries.length} setting{result.entries.length !== 1 ? "s" : ""}
+ A setup link wants to apply {result.entries.length} setting{result.entries.length !== 1 ? "s" : ""}. Apply it
+ only if you trust where it came from.
</Text>
{renderSection("Tracking", trackingEntries)}
@@ -237,6 +256,19 @@ const styles = StyleSheet.create({
section: {
marginTop: space.xl
},
+ endpoint: {
+ paddingVertical: space.sm,
+ gap: space.xxs
+ },
+ endpointLabel: {
+ fontSize: fontSizes.body,
+ ...fonts.regular
+ },
+ endpointHost: {
+ fontSize: fontSizes.body,
+ ...fonts.semiBold,
+ lineHeight: lineHeights.body
+ },
actions: {
marginTop: space.xl
}
diff --git a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
index ce52afae..2db279f0 100644
--- a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
@@ -16,6 +16,7 @@ const mockGetProfiles = jest.fn().mockResolvedValue([])
const mockDeleteProfile = jest.fn().mockResolvedValue(true)
const mockNavigate = jest.fn()
const mockShowAlert = jest.fn()
+let mockCurrentEndpoint = ""
jest.mock("../../services/NativeLocationService", () => ({
__esModule: true,
@@ -38,7 +39,7 @@ jest.mock("../../services/modalService", () => ({
jest.mock("../../contexts/TrackingProvider", () => ({
useTracking: () => ({
- settings: { ...require("../../types/global").DEFAULT_SETTINGS },
+ settings: { ...require("../../types/global").DEFAULT_SETTINGS, endpoint: mockCurrentEndpoint },
setSettings: mockSetSettings
})
}))
@@ -123,6 +124,7 @@ function renderScreen(configParam?: string) {
beforeEach(() => {
jest.clearAllMocks()
+ mockCurrentEndpoint = ""
})
describe("SetupImportScreen", () => {
@@ -151,7 +153,7 @@ describe("SetupImportScreen", () => {
it("parses valid endpoint config", () => {
const { getByText } = renderScreen(encode({ endpoint: "https://my-server.com/api" }))
- expect(getByText("Endpoint")).toBeTruthy()
+ expect(getByText("Sends locations to")).toBeTruthy()
expect(getByText("https://my-server.com/api")).toBeTruthy()
})
@@ -202,9 +204,57 @@ describe("SetupImportScreen", () => {
it("shows singular 'setting' for single entry", () => {
const { getByText } = renderScreen(encode({ endpoint: "https://test.com" }))
- // Text is split across nodes: "A setup link wants to apply " + "1" + " setting"
- expect(getByText(/1/)).toBeTruthy()
- expect(getByText(/setting$/)).toBeTruthy()
+ expect(getByText(/apply 1 setting\./)).toBeTruthy()
+ })
+ })
+
+ // The confirmation is the only thing between a phishing link and the user's location stream.
+ describe("endpoint confirmation", () => {
+ it("prints the host on its own line, so a lookalike prefix cannot stand in for it", () => {
+ const endpoint = "https://my-server.com.evil.example/api/locations"
+ const { getByText } = renderScreen(encode({ endpoint }))
+
+ expect(getByText("my-server.com.evil.example")).toBeTruthy()
+ expect(getByText(endpoint)).toBeTruthy()
+ })
+
+ it("never cuts the address to one line, because the cut would hide where locations go", () => {
+ const endpoint = `https://my-server.com.${"a".repeat(80)}.evil.example/api`
+ const { getByText } = renderScreen(encode({ endpoint }))
+
+ expect(getByText(endpoint).props.numberOfLines).toBeUndefined()
+ expect(getByText(endpoint.slice(8, -4)).props.numberOfLines).toBeUndefined()
+ })
+
+ it("refuses an address whose host hides behind user@, which reads as the trusted host", () => {
+ const { getByText, queryByText } = renderScreen(
+ encode({ endpoint: "https://[email protected]/api", interval: 10 })
+ )
+
+ expect(getByText(/must be a plain host/)).toBeTruthy()
+ expect(queryByText("Sends locations to")).toBeNull()
+ })
+
+ it("says which server the link replaces when one is already configured", () => {
+ mockCurrentEndpoint = "https://my-server.com/api"
+ const { getByText } = renderScreen(encode({ endpoint: "https://evil.example/api" }))
+
+ expect(getByText("Replaces your current server, my-server.com")).toBeTruthy()
+ })
+
+ it("stays quiet on a first setup and on a link that carries the configured address", () => {
+ const first = renderScreen(encode({ endpoint: "https://my-server.com/api" }))
+ expect(first.queryByText(/Replaces your current server/)).toBeNull()
+ first.unmount()
+
+ mockCurrentEndpoint = "https://my-server.com/api"
+ const same = renderScreen(encode({ endpoint: "https://my-server.com/api" }))
+ expect(same.queryByText(/Replaces your current server/)).toBeNull()
+ })
+
+ it("tells the user to apply a link only from a trusted source", () => {
+ const { getByText } = renderScreen(encode({ endpoint: "https://my-server.com/api" }))
+ expect(getByText(/only if you trust where it came from/)).toBeTruthy()
})
})
@@ -761,13 +811,25 @@ describe("SetupImportScreen", () => {
})
})
- describe("rejected entries", () => {
- it("says the setting was not applied and why, instead of only turning the row red", () => {
- const { getByText } = renderScreen(encode({ endpoint: "notaurl", interval: 10 }))
+ // A link is written by someone else: once its address fails a check, none of it has earned an Apply button.
+ describe("rejected link", () => {
+ it("offers no way to apply the rest of a link whose address was rejected", () => {
+ const { getByText, queryByText } = renderScreen(encode({ endpoint: "notaurl", interval: 10 }))
- // The value column carries a reason for a rejected entry, so it cannot double as the value.
- expect(getByText("Not applied")).toBeTruthy()
- expect(getByText("HTTP not allowed for public hosts")).toBeTruthy()
+ expect(getByText("Invalid configuration")).toBeTruthy()
+ expect(getByText(/HTTP not allowed for public hosts\. Nothing from this link will be applied\./)).toBeTruthy()
+ expect(queryByText("Apply configuration")).toBeNull()
+ expect(queryByText("10s")).toBeNull()
+ })
+
+ it("writes nothing when the user leaves a rejected link", () => {
+ const { getByText } = renderScreen(encode({ endpoint: "https://[email protected]/api", interval: 10 }))
+
+ fireEvent.press(getByText("Go back"))
+
+ expect(mockSetSettings).not.toHaveBeenCalled()
+ expect(mockSaveAuthConfig).not.toHaveBeenCalled()
+ expect(mockNavigate).toHaveBeenCalledWith("Dashboard")
})
})
})
diff --git a/apps/mobile/src/utils/__tests__/setupLink.test.ts b/apps/mobile/src/utils/__tests__/setupLink.test.ts
index 94b39a73..d1eae192 100644
--- a/apps/mobile/src/utils/__tests__/setupLink.test.ts
+++ b/apps/mobile/src/utils/__tests__/setupLink.test.ts
@@ -6,7 +6,7 @@ import {
type SetupShareParts,
type SetupShareSelection
} from "../setupLink"
-import { validateConfig } from "../setupConfig"
+import { validateConfig, setupEndpointHost } from "../setupConfig"
import type { Settings, AuthConfig, Geofence, TrackingProfile } from "../../types/global"
const settings = {
@@ -140,3 +140,33 @@ describe("setupLink", () => {
expect(decodeConfig(asReceived)).toEqual(config)
})
})
+
+// The import screen prints this host as the thing the user is trusting, so it has to be the host native sends to.
+describe("setupEndpointHost", () => {
+ it("reads the authority and keeps the port", () => {
+ expect(setupEndpointHost("https://example.com/api")).toBe("example.com")
+ expect(setupEndpointHost("http://192.168.1.10:8080/api?x=1")).toBe("192.168.1.10:8080")
+ })
+
+ it("ignores an @ in the path, which a looser parser reads as userinfo and reports the wrong host", () => {
+ expect(setupEndpointHost("https://evil.example/[email protected]")).toBe("evil.example")
+ })
+
+ it("gives no host when userinfo or a backslash lets two parsers disagree on it", () => {
+ expect(setupEndpointHost("https://[email protected]/api")).toBeNull()
+ expect(setupEndpointHost("https://my-server.com\\@evil.example/api")).toBeNull()
+ expect(setupEndpointHost("https://evil.example\\.my-server.com/api")).toBeNull()
+ })
+
+ it("rejects the whole link with such an endpoint, so the settings riding along are not applied either", () => {
+ const result = validateConfig({
+ endpoint: "https://[email protected]/api",
+ interval: 10,
+ auth: { type: "bearer", bearerToken: "abcdefghijkl" }
+ })
+ expect(result.valid).toBe(false)
+ expect(result.config).toEqual({ settings: {}, auth: null, geofences: [], profiles: [] })
+ expect(result.entries).toEqual([])
+ expect(result.error).toMatch(/plain host.*Nothing from this link will be applied/)
+ })
+})
diff --git a/apps/mobile/src/utils/setupConfig.ts b/apps/mobile/src/utils/setupConfig.ts
index 23dc298c..c577cb2a 100644
--- a/apps/mobile/src/utils/setupConfig.ts
+++ b/apps/mobile/src/utils/setupConfig.ts
@@ -37,7 +37,6 @@ export interface ConfigEntry {
label: string
value: string
category: "tracking" | "api" | "auth" | "geofence" | "profile"
- rejected?: boolean
}
export interface ValidationResult {
@@ -68,6 +67,13 @@ export function detectPreset(settings: Partial<Settings>): SyncPreset {
return "custom"
}
+/** The host a setup link's endpoint sends to, or null when userinfo or a backslash would let parsers disagree on it. */
+export function setupEndpointHost(endpoint: string): string | null {
+ const authority = /^https?:\/\/([^/?#]*)/i.exec(endpoint)?.[1]
+ if (!authority || /[@\\\s]/.test(authority)) return null
+ return authority
+}
+
export function validateConfig(raw: unknown): ValidationResult {
if (!raw || typeof raw !== "object") {
return {
@@ -86,12 +92,22 @@ export function validateConfig(raw: unknown): ValidationResult {
// --- API settings (endpoint) ---
if ("endpoint" in obj && typeof obj.endpoint === "string" && obj.endpoint.length > 0) {
- if (isEndpointAllowed(obj.endpoint)) {
- settings.endpoint = obj.endpoint
- entries.push({ label: "Endpoint", value: obj.endpoint, category: "api" })
- } else {
- entries.push({ label: "Endpoint", value: "HTTP not allowed for public hosts", category: "api", rejected: true })
+ const rejection = !isEndpointAllowed(obj.endpoint)
+ ? "HTTP not allowed for public hosts"
+ : setupEndpointHost(obj.endpoint) === null
+ ? "The server address must be a plain host, without user@ or a backslash"
+ : null
+ // A link is written by someone else, so one rejected address rejects all of it rather than applying the rest.
+ if (rejection) {
+ return {
+ valid: false,
+ config: { settings: {}, auth: null, geofences: [], profiles: [] },
+ entries: [],
+ error: `${rejection}. Nothing from this link will be applied.`
+ }
}
+ settings.endpoint = obj.endpoint
+ entries.push({ label: "Endpoint", value: obj.endpoint, category: "api" })
}
// --- Tracking settings ---
diff --git a/fastlane/metadata/android/en-US/changelogs/51.txt b/fastlane/metadata/android/en-US/changelogs/51.txt
index ee96b1e5..2e3363e9 100644
--- a/fastlane/metadata/android/en-US/changelogs/51.txt
+++ b/fastlane/metadata/android/en-US/changelogs/51.txt
@@ -1 +1,2 @@
- A tracking profile keeps its deactivation delay when a lower-priority profile starts to match
+- Setup links show the full server address with its host on its own line, name the server they replace and are rejected as a whole when the address hides its host