diff --git a/mobile/src/components/web-shell.tsx b/mobile/src/components/web-shell.tsx index c0a7f86..02f0f03 100644 --- a/mobile/src/components/web-shell.tsx +++ b/mobile/src/components/web-shell.tsx @@ -26,6 +26,22 @@ function toSiteUrl(link: string): string | null { } } +/** + * 웹뷰는 날씨각 사이트(정확히 같은 origin)에서만 움직인다. originWhitelist 는 접두사 일치라 + * weather.o2o.kr.evil.com·weather.o2o.kr@evil.com 도 통과시키므로, 통과한 주소를 여기서 다시 거른다. + * 다른 주소는 웹뷰에 열지 않고 휴대폰 브라우저로 보낸다. + */ +function stayOnSite(req: { url: string }) { + if (req.url === 'about:blank') return true; + try { + if (new URL(req.url).origin === SITE_ORIGIN) return true; + } catch { + // 읽을 수 없는 주소는 웹뷰에서 열지 않는다 + } + Linking.openURL(req.url).catch((e: unknown) => console.warn('[shell] 외부 주소를 열지 못함', req.url, e)); + return false; +} + function LoadFailed({ onRetry }: { onRetry: () => void }) { return ( @@ -116,6 +132,7 @@ export function WebShell({ onReady }: { onReady: () => void }) { ref={webView} source={{ uri: startUri }} originWhitelist={[SITE_ORIGIN]} + onShouldStartLoadWithRequest={stayOnSite} applicationNameForUserAgent={APP_UA} onNavigationStateChange={onNavigationStateChange} onMessage={onMessage}