Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Wallet Guard: Protect Your Crypto",
"version": "1.3.9",
"version": "1.4.0",
"description": "A browser extension for detecting phishing attacks on crypto wallets",
"main": "index.js",
"scripts": {
Expand Down
261 changes: 128 additions & 133 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,37 @@ chrome.action.onClicked.addListener(function (tab) {
}
});

chrome.webRequest.onBeforeRequest.addListener(req => {
isBlocked(req.url).then(({ hash, blocked }) => {
if (blocked) {
chrome.tabs.get(req.tabId).then((tab) => {
if (!tab.url) return;
if (urlIsPhishingWarning(tab.url)) return;

const domainName = getDomainNameFromURL(tab.url);

localStorageHelpers.get<string[]>(WgKeys.PersonalWhitelist).then((whitelist) => {
if (whitelist?.includes(domainName)) return;

chrome.tabs.update(req.tabId, {
url:
(chrome.runtime.getURL('phish.html') +
'?safe=' +
'null' +
'&proceed=' +
(tab.url || '') +
'&reason=' +
WarningType.DrainerRequest +
'&value=' +
hash)
});
});
});
}
});
}, {
urls: ['<all_urls>'],
});
// chrome.webRequest.onBeforeRequest.addListener(req => {
// isBlocked(req.url).then(({ hash, blocked }) => {
// if (blocked) {
// chrome.tabs.get(req.tabId).then((tab) => {
// if (!tab.url) return;
// if (urlIsPhishingWarning(tab.url)) return;

// const domainName = getDomainNameFromURL(tab.url);

// localStorageHelpers.get<string[]>(WgKeys.PersonalWhitelist).then((whitelist) => {
// if (whitelist?.includes(domainName)) return;

// chrome.tabs.update(req.tabId, {
// url:
// (chrome.runtime.getURL('phish.html') +
// '?safe=' +
// 'null' +
// '&proceed=' +
// (tab.url || '') +
// '&reason=' +
// WarningType.DrainerRequest +
// '&value=' +
// hash)
// });
// });
// });
// }
// });
// }, {
// urls: ['<all_urls>'],
// });

// MESSAGING
chrome.runtime.onMessage.addListener((message: BrowserMessage, sender, sendResponse) => {
Expand Down Expand Up @@ -131,22 +131,22 @@ chrome.runtime.onMessage.addListener((message: BrowserMessage, sender, sendRespo
});

// EXTENSION DETECTION
chrome.management.onInstalled.addListener(async (extensionInfo) => {
const settings = await localStorageHelpers.get<ExtensionSettings>(WgKeys.ExtensionSettings);

if (extensionInfo.installType === 'development' && settings?.maliciousExtensionDetection) {
chrome.management.setEnabled(extensionInfo.id, false);
const activityInfo = {
name: 'Unpacked Extension Installed',
category: AlertCategory.MaliciousExtension,
details: `Disabled extension: ${extensionInfo.name}`,
key: `extension:${extensionInfo.id}`,
data: extensionInfo,
} as AlertDetail;
AlertHandler.create(activityInfo);
openDashboard('malicious_extension');
}
});
// chrome.management.onInstalled.addListener(async (extensionInfo) => {
// const settings = await localStorageHelpers.get<ExtensionSettings>(WgKeys.ExtensionSettings);

// if (extensionInfo.installType === 'development' && settings?.maliciousExtensionDetection) {
// chrome.management.setEnabled(extensionInfo.id, false);
// const activityInfo = {
// name: 'Unpacked Extension Installed',
// category: AlertCategory.MaliciousExtension,
// details: `Disabled extension: ${extensionInfo.name}`,
// key: `extension:${extensionInfo.id}`,
// data: extensionInfo,
// } as AlertDetail;
// AlertHandler.create(activityInfo);
// openDashboard('malicious_extension');
// }
// });

// PHISHING DETECTION
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
Expand All @@ -156,32 +156,27 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
const currentSite = await getCurrentSite();

if (domainHasChanged(changeInfo.url, currentSite)) {
await checkUrlForPhishing(tab);
// await checkUrlForPhishing(tab);
}
});

// ALARMS
chrome.alarms.onAlarm.addListener(async (alarm) => {
if (alarm.name === 'checkVersions') {
checkAllWalletsAndCreateAlerts();
// checkAllWalletsAndCreateAlerts();
} else if (alarm.name === 'fetchRequestsBlocklist') {
handleRequestsBlocklist();
// handleRequestsBlocklist();
}
});

// INSTALLS / UPDATES
chrome.runtime.onInstalled.addListener(async (details) => {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app' });

if (details.reason === 'install') {
// TODO: Signin Anonymously
} else if (details.reason === 'update') {
AlertHandler.create({
key: 'wg-sunset-notice',
category: AlertCategory.News,
name: "Wallet Guard Sunset Notice",
details: `The Wallet Guard extension will be discontinued on March 31st, 2025. Please install MetaMask to continue using Wallet Guard's security features.`,
link: "https://www.walletguard.app/blog/wallet-guard-sunset-notice",
createdAt: new Date().toISOString()
});
// TODO: Signin Anonymously
}

localStorageHelpers.get<SimulationSettings>(WgKeys.SimulationSettings).then((res) => {
Expand All @@ -198,7 +193,7 @@ chrome.runtime.onInstalled.addListener(async (details) => {
}
});

chrome.runtime.setUninstallURL('https://dashboard.walletguard.app/uninstall');
chrome.runtime.setUninstallURL('https://dashboard.walletguard.app');

const ONE_DAY_AS_MINUTES = 1440;
chrome.alarms.create('checkVersions', {
Expand All @@ -211,24 +206,24 @@ chrome.runtime.onInstalled.addListener(async (details) => {
periodInMinutes: ONE_DAY_AS_MINUTES,
});

await checkAllWalletsAndCreateAlerts();
// await checkAllWalletsAndCreateAlerts();

if (process.env.NODE_ENV === 'production' && details.reason === 'install') {
openDashboard('install');
}
// if (process.env.NODE_ENV === 'production' && details.reason === 'install') {
// openDashboard('install');
// }

// Create a context menu item
chrome.contextMenus.create({
id: 'ask-chatweb3',
title: 'Ask ChatWeb3',
contexts: ['all'],
});
// chrome.contextMenus.create({
// id: 'ask-chatweb3',
// title: 'Ask ChatWeb3',
// contexts: ['all'],
// });
});

// STARTUP
chrome.runtime.onStartup.addListener(() => {
// This is ran once per Startup and every 24h
checkAllWalletsAndCreateAlerts();
// checkAllWalletsAndCreateAlerts();
});

// Reject the current transaction if we close the simulation popup
Expand Down Expand Up @@ -332,72 +327,72 @@ chrome.storage.onChanged.addListener((changes, area) => {
}
});

Browser.runtime.onConnect.addListener(async (remotePort: Browser.Runtime.Port) => {
if (remotePort.name === PortIdentifiers.WG_CONTENT_SCRIPT) {
remotePort.onMessage.addListener(bypassCheckMessageHandler);
}
});
// Browser.runtime.onConnect.addListener(async (remotePort: Browser.Runtime.Port) => {
// if (remotePort.name === PortIdentifiers.WG_CONTENT_SCRIPT) {
// remotePort.onMessage.addListener(bypassCheckMessageHandler);
// }
// });

// Listen for when the user clicks on the context menu item
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === 'ask-chatweb3') {
// Send a message to the content script

if (!currentChatWeb3Popup) {
// Indicate we're creating a popup so we don't have many.
currentChatWeb3Popup = -1;

chrome.windows
.create({
url: 'chatweb3.html',
type: 'popup',
width: 420,
height: 760,
})
.then((createdWindow) => {
currentChatWeb3Popup = createdWindow?.id;
});

return;
}

if (currentChatWeb3Popup && currentChatWeb3Popup !== -1) {
const closeId = currentChatWeb3Popup;
currentChatWeb3Popup = undefined;
chrome.windows.remove(closeId);

return;
}
}
});

chrome.commands.onCommand.addListener((command) => {
if (!currentChatWeb3Popup) {
// Indicate we're creating a popup so we don't have many.
currentChatWeb3Popup = -1;

chrome.windows
.create({
url: 'chatweb3.html',
type: 'popup',
width: 420,
height: 760,
})
.then((createdWindow) => {
currentChatWeb3Popup = createdWindow?.id;
});

return;
}

if (currentChatWeb3Popup && currentChatWeb3Popup !== -1) {
const closeId = currentChatWeb3Popup;
currentChatWeb3Popup = undefined;
chrome.windows.remove(closeId);

return;
}
});
// chrome.contextMenus.onClicked.addListener((info, tab) => {
// if (info.menuItemId === 'ask-chatweb3') {
// // Send a message to the content script

// if (!currentChatWeb3Popup) {
// // Indicate we're creating a popup so we don't have many.
// currentChatWeb3Popup = -1;

// chrome.windows
// .create({
// url: 'chatweb3.html',
// type: 'popup',
// width: 420,
// height: 760,
// })
// .then((createdWindow) => {
// currentChatWeb3Popup = createdWindow?.id;
// });

// return;
// }

// if (currentChatWeb3Popup && currentChatWeb3Popup !== -1) {
// const closeId = currentChatWeb3Popup;
// currentChatWeb3Popup = undefined;
// chrome.windows.remove(closeId);

// return;
// }
// }
// });

// chrome.commands.onCommand.addListener((command) => {
// if (!currentChatWeb3Popup) {
// // Indicate we're creating a popup so we don't have many.
// currentChatWeb3Popup = -1;

// chrome.windows
// .create({
// url: 'chatweb3.html',
// type: 'popup',
// width: 420,
// height: 760,
// })
// .then((createdWindow) => {
// currentChatWeb3Popup = createdWindow?.id;
// });

// return;
// }

// if (currentChatWeb3Popup && currentChatWeb3Popup !== -1) {
// const closeId = currentChatWeb3Popup;
// currentChatWeb3Popup = undefined;
// chrome.windows.remove(closeId);

// return;
// }
// });

const bypassCheckMessageHandler = async (message: PortMessage, sourcePort: Browser.Runtime.Port) => {
if (!message.data.chainId) {
Expand Down
6 changes: 3 additions & 3 deletions src/content-scripts/contentScripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const addScript = (url: string) => {
scriptTag.onload = () => scriptTag.remove();
};

// Add vendor and injectWalletGuard
addScript('js/vendor.js');
addScript('js/injected/injectWalletGuard.js');
// SUNSET NOTICE - We no longer inject to proxy transactions
// addScript('js/vendor.js');
// addScript('js/injected/injectWalletGuard.js');

const log = logger.child({ component: 'Content-Script' });

Expand Down
12 changes: 1 addition & 11 deletions src/lib/helpers/linkHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,5 @@ export function openGuide() {
}

export function openDashboard(source: string) {
if (source === 'settings') {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app/settings/extension/?client=extension&source=settings' });
} else if (source === 'install') {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app/onboarding/welcome/?client=extension&source=install' });
} else if (source === 'lockedAsset') {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app/softlock/?client=extension&source=lockedAsset' });
} else if (source === 'referrals') {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app/?referrals&client=extension&source=referrals' });
} else {
chrome.tabs.create({ url: 'https://dashboard.walletguard.app/?client=extension&source=' + source });
}
chrome.tabs.create({ url: 'https://dashboard.walletguard.app' });
}
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Wallet Guard: Protect Your Crypto",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0SMGNwLFsP2k1jAD54vtDqLJuIpeZWCc9gdvo2N8hzE1qIkOt29ynU1VgkJbtfuWHqWSyOCo1ljs2MjbqqFjG4qz5o3ZrEAMwmEbWGCuPddUIIiWIK0oF+BkwZiRpRS2nw/i9Dmeusf0eOlxxLYD0NpKszX73lqGt4LBIY8Wva7vmqdnKPa1F6+DDZviXcBRa8CLCzqDujTjON37o+NvQOq2u49UzVXr/DcePFrUTnnjdNkKTQkLlH00lwvxUUJl0g5IVdlxNgZXPY/C6P39YIIxsBFJH0rXvQrLgED6NGR17CBnLhOmmYghku17yoUGg3KrT4aeh8+uG5NrQZuqGwIDAQAB",
"description": "Wallet Guard acts as a security companion to your crypto wallet of choice, so you can browse at ease.",
"version": "1.3.9",
"version": "1.4.0",
"icons": {
"128": "images/wg_logos/logo_128x128.png"
},
Expand Down