fix: 웹뷰가 날씨각과 정확히 같은 origin 만 열게 — originWhitelist 는 접두사 일치라 weather.o2o.kr.evil.com·weather.o2o.kr@evil.com 도 통과해, onShouldStartLoadWithRequest 로 다시 거르고 나머지는 휴대폰 브라우저로
This commit is contained in:
1 parent
a228fcf560
commit
e64b001bf9
1 file changed
+17
@@ -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 }) {
|
function LoadFailed({ onRetry }: { onRetry: () => void }) {
|
||||||
return (
|
return (
|
||||||
<View className="absolute inset-0 items-center justify-center px-6" style={{ backgroundColor: BG }}>
|
<View className="absolute inset-0 items-center justify-center px-6" style={{ backgroundColor: BG }}>
|
||||||
@@ -116,6 +132,7 @@ export function WebShell({ onReady }: { onReady: () => void }) {
|
|||||||
ref={webView}
|
ref={webView}
|
||||||
source={{ uri: startUri }}
|
source={{ uri: startUri }}
|
||||||
originWhitelist={[SITE_ORIGIN]}
|
originWhitelist={[SITE_ORIGIN]}
|
||||||
|
onShouldStartLoadWithRequest={stayOnSite}
|
||||||
applicationNameForUserAgent={APP_UA}
|
applicationNameForUserAgent={APP_UA}
|
||||||
onNavigationStateChange={onNavigationStateChange}
|
onNavigationStateChange={onNavigationStateChange}
|
||||||
onMessage={onMessage}
|
onMessage={onMessage}
|
||||||
|
|||||||
Reference in new issue
Block a user