Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor whitelist inapp browser #13049

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions app/components/Views/BrowserTab/BrowserTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
id: tabId,
isIpfsGatewayEnabled,
addToWhitelist: triggerAddToWhitelist,
whitelist,
showTabs,
linkType,
isInTabsView,
Expand Down Expand Up @@ -145,7 +144,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
const [connectionType, setConnectionType] = useState(ConnectionType.UNKNOWN);
const webviewRef = useRef<WebView>(null);
const blockListType = useRef<string>(''); // TODO: Consider improving this type
const allowList = useRef<string[]>([]); // TODO: Consider improving this type
const webStates = useRef<
Record<string, { requested: boolean; started: boolean; ended: boolean }>
>({});
Expand Down Expand Up @@ -195,6 +193,11 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
(state: RootState) => state.browser.activeTab === tabId,
);

/**
* whitelisted url to bypass the phishing detection
*/
const whitelist = useSelector((state: RootState) => state.browser.whitelist);

const isFocused = useIsFocused();

/**
Expand Down Expand Up @@ -283,28 +286,30 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
/**
* Check if an origin is allowed
*/
const isAllowedOrigin = useCallback((urlOrigin: string) => {
const { PhishingController } = Engine.context;
const isAllowedOrigin = useCallback(
(urlOrigin: string) => {
const { PhishingController } = Engine.context;

// Update phishing configuration if it is out-of-date
// This is async but we are not `await`-ing it here intentionally, so that we don't slow
// down network requests. The configuration is updated for the next request.
PhishingController.maybeUpdateState();
// Update phishing configuration if it is out-of-date
// This is async but we are not `await`-ing it here intentionally, so that we don't slow
// down network requests. The configuration is updated for the next request.
PhishingController.maybeUpdateState();

const phishingControllerTestResult = PhishingController.test(urlOrigin);
const phishingControllerTestResult = PhishingController.test(urlOrigin);

// Only assign the if the hostname is on the block list
if (
phishingControllerTestResult.result &&
phishingControllerTestResult.name
)
blockListType.current = phishingControllerTestResult.name;
// Only assign the if the hostname is on the block list
if (
phishingControllerTestResult.result &&
phishingControllerTestResult.name
)
blockListType.current = phishingControllerTestResult.name;

return (
allowList.current?.includes(urlOrigin) ||
!phishingControllerTestResult.result
);
}, []);
return (
whitelist?.includes(urlOrigin) || !phishingControllerTestResult.result
);
},
[whitelist],
);

/**
* Show a phishing modal when a url is not allowed
Expand Down Expand Up @@ -971,10 +976,6 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
}
}, [isIpfsGatewayEnabled]);

useEffect(() => {
allowList.current = whitelist;
}, [whitelist]);

/**
* Render the progress bar
*/
Expand Down Expand Up @@ -1419,7 +1420,6 @@ const mapStateToProps = (state: RootState) => ({
selectedAddress:
selectSelectedInternalAccountFormattedAddress(state)?.toLowerCase(),
isIpfsGatewayEnabled: selectIsIpfsGatewayEnabled(state),
whitelist: state.browser.whitelist,
wizardStep: state.wizard.step,
activeChainId: selectChainId(state),
});
Expand Down
4 changes: 0 additions & 4 deletions app/components/Views/BrowserTab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ export type BrowserTabProps = {
* A string that represents the selected address
*/
selectedAddress: string | undefined; // This should never be undefined, need to fix the accounts controller selector
/**
* whitelisted url to bypass the phishing detection
*/
whitelist: string[];
/**
* Url coming from an external source
* For ex. deeplinks
Expand Down
Loading