# Security Gitea Native is built to handle personal access tokens and account metadata. This document states the intended security posture. ## Credential storage - **Platform keystore only.** All PATs are stored with Expo SecureStore: `SecureStore.setItemAsync(tokenKey(accountId), token, { keychainService: 'gitea-native.credentials' })`. - **No plaintext persistence.** Tokens are **never** written to AsyncStorage, `react-native-mmkv` (not used), the accounts registry, JSON files or logs. - **Non-sensitive metadata.** Instance and account records (`InstanceRecord`, `AccountRecord`) contain `baseUrl`, `login`, `avatarUrl`, timestamps — no tokens, no passwords, no refresh tokens. - **In-memory only.** The Zustand store keeps a `tokens: Record` map to attach `Authorization: token ` to requests. It is excluded from `persist` and from all write paths that serialise state. - **Deletion on removal.** Removing an account deletes its `token.` entry. Removing an instance cascades to all of its accounts' tokens. ## Transport & network - **HTTPS enforced for remote instances.** `normalizeInstanceUrl` rejects plain `http://` except for loopback hosts: `localhost`, `127.0.0.1`, `::1`, `0.0.0.0`, `10.0.2.2`. Embedded credentials (`user:pass@`) are rejected to prevent token smuggling. Only `http/https` schemes are accepted. - **No token in URLs.** The REST calls always go to `Authorization: token `. `buildQuery` never attaches a `token` parameter. The client does not log the full URL with sensitive fragments. - **Sub-path support.** Gitea installations under a sub-path (e.g. `https://example.com/git`) are preserved and become `…/git/api/v1` — correct for reverse proxies. - **Timeouts & aborts.** Each `fetch` is wrapped with `AbortController` and a per-request timeout. Navigation unmounts/cancellations use `signal.aborted`. - **Private assets.** When rendering images from `download_url`, the app only sends the token header if the host matches the instance host. This avoids leaking credentials to third-party CDNs. ## Error handling & logging - **Centralised errors.** `ApiError` carries `kind` and `status`; `serverMessage` is taken from the JSON body but never augmented with the token. - **No secret leakage in errors.** The tests explicitly assert that no occurrence of the PAT appears in `error.message` or `error.serverMessage`. - **Defensive fallbacks.** Network/timeout/401/403 map to safe, translated messages. `invalid-response` catches HTML replies (mitigates MITM/proxy surprises). - **No analytics by default.** The project contains no remote telemetry or crash reporting hooks. ## Biometric app lock - **UI gating only.** `AppLockGate` wraps the navigators. It does not encrypt on-disk storage; it protects access to the UI on the running device. - **Arming conditions.** Locks only when `biometricsEnabled`, the account store has accounts, and `LocalAuthentication` reports `usable === true` (hardware + enrolled). - **Background → locked.** On `AppState` change to `background`, `locked` is set to `true`. - **Foreground → prompt.** When `effectiveLocked` becomes true and the app is active, an automatic prompt runs. `prompting.current` prevents duplicate prompts. - **Correct failure semantics.** If the user cancels or authentication fails, the app remains locked. If `unavailable`/no credentials, the gate never forcibly traps the user (state remains unlocked). - **App switcher redaction.** Expo's app metadata (`ios.infoPlist`, native build behaviour) plus the locked overlay helps prevent showing account lists in the recent-apps preview. The app treats screenshots/recents as a surface to minimise. ## Account isolation - **Cache keys include accountId.** `queryKeys.repo('acct-a', …)` differs from `'acct-b'`. Two different accounts cannot accidentally share React Query data. - **Purge on removal.** `purgeAccountCache(client, accountId)` clears all queries and mutations for that account (notifications, repositories, issues, home activity, unread counts). - **Session swap.** Switching accounts updates `activeAccountId` and returns a new `GiteaClient` with the new token — no shared mutable client state leaked between accounts. - **Connect flow is order-safe.** `connectToInstance` normalises the URL and does a best-effort `/version` probe (non-fatal), then calls `GET /user` to validate the token. Only after a successful user probe does `registerAccount` write the token to SecureStore and mutate the store. ## Input validation - **Base URL.** `new URL(normalized)` is used after normalisation; fragment and query stripped from the base URL. Trailing slashes collapsed. - **Account IDs.** `tokenKey` enforces `/^[A-Za-z0-9._-]+$/` — matches SecureStore's safe character set. - **API boundaries.** `RawResponse` is the transport shape; feature code narrows to domain types. Unknown fields are ignored rather than blindly trusted. ## Known gaps (not a complete list) - Write actions (comment, edit issue/PR, merge, review, quick-edit commit) are not implemented yet. When added, they must reuse the same auth header, enforce HTTPS, validate 409/stale-SHA and never echo payload secrets. - `expo-doctor` passes. Any new native dependency must be checked against Expo SDK 57 compatibility. - The inline diff viewer is planned; rendering untrusted diffs should avoid executing embedded scripts (Markdown renderer already doesn't run scripts). - A capability probe (server version, supported endpoints) is a planned hardening to gracefully degrade on older Gitea releases.