Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix(linkedin): terminate unsafe navigation classification
16Miku2de25a035d34
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.jsindex 5f2b08abf..f048c7beb 100644--- a/src/chrome/src/content/content.js+++ b/src/chrome/src/content/content.js@@ -5165,22 +5165,24 @@&& railRect.right <= composerRect.left + 64;};- const verifiedLinkedInNavigation = (clicked) => {- if (params.adapterName !== 'linkedin' || !clicked) return false;- const link = clicked.closest?.('a[href]');- if (!link || !visible(link)) return false;+ const classifyLinkedInNavigation = (clicked) => {+ if (params.adapterName !== 'linkedin' || !clicked) return 'none';+ const link = _composedClosestElement(clicked, 'a[href]');+ if (!link || !visible(link)) return 'none';// A navigation-looking descendant of a composer/action is not a// navigation escape hatch. Keep actual sends and modal controls on// the existing recipient-verification path.- if (clicked.closest?.('button,[role="button"],input,select,textarea,[contenteditable]:not([contenteditable="false"]),[onclick],[data-action]')- || link.closest?.('form')+ if (_composedClosestElement(clicked, 'button,[role="button"],input,select,textarea,[contenteditable]:not([contenteditable="false"]),[onclick],[data-action]')+ || _composedClosestElement(link, 'form')|| link.hasAttribute?.('download')- || (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return false;+ || (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return 'blocked';+ const modal = _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]');+ const unresolved = () => modal ? 'blocked' : 'none';try {const href = String(link.getAttribute('href') || '').trim();- if (!href || href.startsWith('#')) return false;+ if (!href || href.startsWith('#')) return unresolved();const destination = new URL(href, document.baseURI);- if (!/^https?:$/.test(destination.protocol)) return false;+ if (!/^https?:$/.test(destination.protocol)) return unresolved();const isLinkedInHost = (hostname) => {const normalized = String(hostname || '').toLowerCase().replace(/\.$/, '');return normalized === 'linkedin.com' || normalized.endsWith('.linkedin.com');@@ -5196,17 +5198,18 @@&& !isLinkedInHost(redirectDestination.hostname);} catch {}}- const modal = link.closest?.('dialog,[role="dialog"],[role="alertdialog"]');if (modal) {const contactInfoOverlay = /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(location.pathname);- if (!contactInfoOverlay || !verifiedExternalRedirect) return false;+ if (!contactInfoOverlay || !verifiedExternalRedirect) return 'blocked';}- if (!linkedInDestination) return true;- return verifiedExternalRedirect+ if (!linkedInDestination) return 'navigation';+ return (verifiedExternalRedirect|| /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname)- || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname);+ || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname))+ ? 'navigation'+ : 'none';} catch {- return false;+ return unresolved();}};@@ -5250,9 +5253,19 @@if (!visible(control) || (modal && !_isComposedAncestor(modal, target))) {return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };}- if (verifiedLinkedInNavigation(target)) {+ const linkedInNavigation = classifyLinkedInNavigation(target);+ if (linkedInNavigation === 'navigation') {return { success: true, messageSend: false, conclusive: true, navigation: true, identityCandidates: [] };}+ if (linkedInNavigation === 'blocked') {+ return {+ success: true,+ messageSend: null,+ conclusive: false,+ navigationBlocked: true,+ identityCandidates: [],+ };+ }composer = layoutComposer;if (!composer) {const actionLabel = compact(diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex 19a1c68ea..b21e741a6 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -4328,22 +4328,24 @@&& railRect.right <= composerRect.left + 64;};- const verifiedLinkedInNavigation = (clicked) => {- if (params.adapterName !== 'linkedin' || !clicked) return false;- const link = clicked.closest?.('a[href]');- if (!link || !visible(link)) return false;+ const classifyLinkedInNavigation = (clicked) => {+ if (params.adapterName !== 'linkedin' || !clicked) return 'none';+ const link = _composedClosestElement(clicked, 'a[href]');+ if (!link || !visible(link)) return 'none';// A navigation-looking descendant of a composer/action is not a// navigation escape hatch. Keep actual sends and modal controls on// the existing recipient-verification path.- if (clicked.closest?.('button,[role="button"],input,select,textarea,[contenteditable]:not([contenteditable="false"]),[onclick],[data-action]')- || link.closest?.('form')+ if (_composedClosestElement(clicked, 'button,[role="button"],input,select,textarea,[contenteditable]:not([contenteditable="false"]),[onclick],[data-action]')+ || _composedClosestElement(link, 'form')|| link.hasAttribute?.('download')- || (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return false;+ || (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return 'blocked';+ const modal = _composedClosestElement(link, 'dialog,[role="dialog"],[role="alertdialog"]');+ const unresolved = () => modal ? 'blocked' : 'none';try {const href = String(link.getAttribute('href') || '').trim();- if (!href || href.startsWith('#')) return false;+ if (!href || href.startsWith('#')) return unresolved();const destination = new URL(href, document.baseURI);- if (!/^https?:$/.test(destination.protocol)) return false;+ if (!/^https?:$/.test(destination.protocol)) return unresolved();const isLinkedInHost = (hostname) => {const normalized = String(hostname || '').toLowerCase().replace(/\.$/, '');return normalized === 'linkedin.com' || normalized.endsWith('.linkedin.com');@@ -4359,17 +4361,18 @@&& !isLinkedInHost(redirectDestination.hostname);} catch {}}- const modal = link.closest?.('dialog,[role="dialog"],[role="alertdialog"]');if (modal) {const contactInfoOverlay = /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(location.pathname);- if (!contactInfoOverlay || !verifiedExternalRedirect) return false;+ if (!contactInfoOverlay || !verifiedExternalRedirect) return 'blocked';}- if (!linkedInDestination) return true;- return verifiedExternalRedirect+ if (!linkedInDestination) return 'navigation';+ return (verifiedExternalRedirect|| /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname)- || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname);+ || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname))+ ? 'navigation'+ : 'none';} catch {- return false;+ return unresolved();}};@@ -4413,9 +4416,19 @@if (!visible(control) || (modal && !_isComposedAncestor(modal, target))) {return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };}- if (verifiedLinkedInNavigation(target)) {+ const linkedInNavigation = classifyLinkedInNavigation(target);+ if (linkedInNavigation === 'navigation') {return { success: true, messageSend: false, conclusive: true, navigation: true, identityCandidates: [] };}+ if (linkedInNavigation === 'blocked') {+ return {+ success: true,+ messageSend: null,+ conclusive: false,+ navigationBlocked: true,+ identityCandidates: [],+ };+ }composer = layoutComposer;if (!composer) {const actionLabel = compact(diff --git a/test/fixtures/message-recipient-navigation.mjs b/test/fixtures/message-recipient-navigation.mjsindex 0d85b5a61..d5e36c0ba 100644--- a/test/fixtures/message-recipient-navigation.mjs+++ b/test/fixtures/message-recipient-navigation.mjs@@ -125,6 +125,8 @@ export function registerMessageRecipientNavigationFixtures({}}for (const href of [+ '#',+ 'mailto:[email protected]','https://portfolio.example/','/safety/go/','/safety/go/?url=javascript%3Aalert(1)',@@ -140,6 +142,67 @@ export function registerMessageRecipientNavigationFixtures({}});+ register(`${kind}: LinkedIn contact-info redirects honor composed-tree safety boundaries`, async (page) => {+ const { guard, probe } = await setup(page);+ const refs = await page.evaluate(() => {+ history.replaceState(null, '', '/in/alice/overlay/contact-info/');+ document.querySelector('#chat').hidden = false;+ const dialog = document.querySelector('#contact-info-dialog');+ dialog.hidden = false;+ const addShadowLink = (parent, hostId, text) => {+ const host = document.createElement('span');+ host.id = hostId;+ parent.append(host);+ const shadow = host.attachShadow({ mode: 'open' });+ shadow.innerHTML = `<a href="/safety/go/?url=https%3A%2F%2Fportfolio.example%2F" style="display:inline-block;padding:8px">${text}</a>`;+ return window.__wb_ax_ref(shadow.querySelector('a'));+ };+ const form = document.createElement('form');+ dialog.append(form);+ const action = document.createElement('span');+ action.dataset.action = 'send';+ dialog.append(action);+ return {+ safe: addShadowLink(dialog, 'shadow-safe-host', 'Shadow safe link'),+ form: addShadowLink(form, 'shadow-form-host', 'Shadow form link'),+ action: addShadowLink(action, 'shadow-action-host', 'Shadow action link'),+ };+ });+ const safeArgs = { ref_id: refs.safe };+ const safe = await probe('click_ax', safeArgs);+ assert.equal(safe.navigation, true, JSON.stringify(safe));+ assert.equal(await guard('click_ax', safeArgs), null);+ for (const ref_id of [refs.form, refs.action]) {+ const args = { ref_id };+ const result = await probe('click_ax', args);+ assert.equal(result.navigationBlocked, true, JSON.stringify(result));+ assert.equal(result.conclusive, false, JSON.stringify(result));+ assert.equal((await guard('click_ax', args))?.noDispatch, true);+ }+ });++ register(`${kind}: LinkedIn safety redirects cannot escape a shadow-root modal`, async (page) => {+ const { guard, probe } = await setup(page);+ const ref_id = await page.evaluate(() => {+ document.querySelector('#chat').hidden = false;+ const modal = document.createElement('div');+ modal.setAttribute('role', 'dialog');+ modal.setAttribute('aria-modal', 'true');+ modal.style.cssText = 'position:fixed;inset:0;background:white';+ document.body.append(modal);+ const host = document.createElement('span');+ modal.append(host);+ const shadow = host.attachShadow({ mode: 'open' });+ shadow.innerHTML = '<a href="/safety/go/?url=https%3A%2F%2Fportfolio.example%2F" style="display:inline-block;padding:8px">Shadow modal link</a>';+ return window.__wb_ax_ref(shadow.querySelector('a'));+ });+ const args = { ref_id };+ const result = await probe('click_ax', args);+ assert.equal(result.navigationBlocked, true, JSON.stringify(result));+ assert.equal(result.conclusive, false, JSON.stringify(result));+ assert.equal((await guard('click_ax', args))?.noDispatch, true);+ });+register(`${kind}: LinkedIn recipient guard rejects ambiguous navigation and action lookalikes`, async (page) => {const { guard } = await setup(page);for (const href of [