- README: features, tech stack, install/run, config, commands, structure, security summary, known limitations - ARCHITECTURE: navigation graph, state model, data flow, cross-cutting notes - SECURITY: credential storage, transport, biometrics, account isolation - FEATURE_PARITY: implemented vs planned matrix per API area - ROADMAP: Phase 3 read paths marked done; write paths still planned
5.6 KiB
5.6 KiB
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) containbaseUrl,login,avatarUrl, timestamps — no tokens, no passwords, no refresh tokens. - In-memory only. The Zustand store keeps a
tokens: Record<string,string>map to attachAuthorization: token <PAT>to requests. It is excluded frompersistand from all write paths that serialise state. - Deletion on removal. Removing an account deletes its
token.<accountId>entry. Removing an instance cascades to all of its accounts' tokens.
Transport & network
- HTTPS enforced for remote instances.
normalizeInstanceUrlrejects plainhttp://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. Onlyhttp/httpsschemes are accepted. - No token in URLs. The REST calls always go to
Authorization: token <PAT>.buildQuerynever attaches atokenparameter. 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
fetchis wrapped withAbortControllerand a per-request timeout. Navigation unmounts/cancellations usesignal.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.
ApiErrorcarrieskindandstatus;serverMessageis 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.messageorerror.serverMessage. - Defensive fallbacks. Network/timeout/401/403 map to safe, translated
messages.
invalid-responsecatches 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.
AppLockGatewraps 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, andLocalAuthenticationreportsusable === true(hardware + enrolled). - Background → locked. On
AppStatechange tobackground,lockedis set totrue. - Foreground → prompt. When
effectiveLockedbecomes true and the app is active, an automatic prompt runs.prompting.currentprevents 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
activeAccountIdand returns a newGiteaClientwith the new token — no shared mutable client state leaked between accounts. - Connect flow is order-safe.
connectToInstancenormalises the URL and does a best-effort/versionprobe (non-fatal), then callsGET /userto validate the token. Only after a successful user probe doesregisterAccountwrite 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.
tokenKeyenforces/^[A-Za-z0-9._-]+$/— matches SecureStore's safe character set. - API boundaries.
RawResponse<T>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-doctorpasses. 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.