mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-01 00:07:01 +00:00
The Notifications pane shows a push setup failure as "<phase>: <message>" with a translated phase but an English message, and the open-link confirmation and the new-mail notification title were English too. They now go through the locale store's t() (translate() in the background task), with the technical detail passed as an argument.
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
// Guarded `Linking.openURL` for URIs that come from server data (contact
|
|
// cards, calendar invitations, mail bodies). An unvalidated scheme is an
|
|
// attack surface: `intent://…#Intent;component=…;end` launches arbitrary
|
|
// exported activities on Android, `file://`/`content://` reach local files,
|
|
// third-party deep links do whatever the receiving app does. Only the
|
|
// schemes a mail client legitimately hands off are allowed.
|
|
|
|
import { Alert, Linking } from 'react-native';
|
|
import { t } from '../stores/locale-store';
|
|
|
|
const ALLOWED_SCHEMES = new Set(['https', 'http', 'mailto', 'tel', 'sms', 'geo', 'webcal', 'webcals']);
|
|
|
|
export function schemeOf(uri: string): string | null {
|
|
const m = /^\s*([a-z][a-z0-9+.-]*):/i.exec(uri);
|
|
return m ? m[1].toLowerCase() : null;
|
|
}
|
|
|
|
/** True when `uri` uses a scheme the app may hand to the OS. */
|
|
export function isSafeExternalUrl(uri: string | null | undefined): uri is string {
|
|
if (!uri) return false;
|
|
const scheme = schemeOf(uri);
|
|
if (!scheme) return false;
|
|
if (!ALLOWED_SCHEMES.has(scheme)) return false;
|
|
// Reject anything with control characters - header/URL injection bait.
|
|
// eslint-disable-next-line no-control-regex
|
|
return !/[ |