Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix(linkedin): allow verified contact info links

16Miku3251f4d617b6
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 3fa8fc10b..963278394 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -5168,25 +5168,40 @@
const verifiedLinkedInNavigation = (clicked) => {
if (params.adapterName !== 'linkedin' || !clicked) return false;
const link = clicked.closest?.('a[href]');
- if (!link || !visible(link) || !link.closest?.('nav,[role="navigation"]')) return false;
+ if (!link || !visible(link)) return false;
// 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,dialog,[role="dialog"],[role="alertdialog"]')
+ || link.closest?.('form')
|| link.hasAttribute?.('download')
|| (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return false;
try {
const href = String(link.getAttribute('href') || '').trim();
if (!href || href.startsWith('#')) return false;
const destination = new URL(href, document.baseURI);
- // Only the site's top-level navigation destinations are known not
- // to send. Arbitrary action URLs and conversation controls stay
- // inconclusive, even when their visible label says Home or Jobs.
- return /^https?:$/.test(destination.protocol)
- && destination.origin === location.origin
- && /^(?:www\.)?linkedin\.com$/.test(destination.hostname)
- && /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname);
+ if (!/^https?:$/.test(destination.protocol)) return false;
+ const isLinkedInHost = (hostname) => /^(?:www\.)?linkedin\.com$/.test(hostname);
+ const linkedInDestination = isLinkedInHost(destination.hostname);
+ const redirectPath = /^\/(?:safety\/go|redir\/redirect)\/?$/.test(destination.pathname);
+ let verifiedExternalRedirect = false;
+ if (linkedInDestination && redirectPath) {
+ const redirectValue = destination.searchParams.get('url') || '';
+ try {
+ const redirectDestination = new URL(redirectValue);
+ verifiedExternalRedirect = /^https?:$/.test(redirectDestination.protocol)
+ && !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 (!linkedInDestination) return true;
+ return verifiedExternalRedirect
+ || /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname)
+ || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname);
} catch {
return false;
}
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 7c94a725a..234664e3e 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -4331,25 +4331,40 @@
const verifiedLinkedInNavigation = (clicked) => {
if (params.adapterName !== 'linkedin' || !clicked) return false;
const link = clicked.closest?.('a[href]');
- if (!link || !visible(link) || !link.closest?.('nav,[role="navigation"]')) return false;
+ if (!link || !visible(link)) return false;
// 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,dialog,[role="dialog"],[role="alertdialog"]')
+ || link.closest?.('form')
|| link.hasAttribute?.('download')
|| (link.getAttribute?.('role') && link.getAttribute('role') !== 'link')) return false;
try {
const href = String(link.getAttribute('href') || '').trim();
if (!href || href.startsWith('#')) return false;
const destination = new URL(href, document.baseURI);
- // Only the site's top-level navigation destinations are known not
- // to send. Arbitrary action URLs and conversation controls stay
- // inconclusive, even when their visible label says Home or Jobs.
- return /^https?:$/.test(destination.protocol)
- && destination.origin === location.origin
- && /^(?:www\.)?linkedin\.com$/.test(destination.hostname)
- && /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname);
+ if (!/^https?:$/.test(destination.protocol)) return false;
+ const isLinkedInHost = (hostname) => /^(?:www\.)?linkedin\.com$/.test(hostname);
+ const linkedInDestination = isLinkedInHost(destination.hostname);
+ const redirectPath = /^\/(?:safety\/go|redir\/redirect)\/?$/.test(destination.pathname);
+ let verifiedExternalRedirect = false;
+ if (linkedInDestination && redirectPath) {
+ const redirectValue = destination.searchParams.get('url') || '';
+ try {
+ const redirectDestination = new URL(redirectValue);
+ verifiedExternalRedirect = /^https?:$/.test(redirectDestination.protocol)
+ && !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 (!linkedInDestination) return true;
+ return verifiedExternalRedirect
+ || /^\/(?:feed|jobs|mynetwork|messaging|notifications)\/?$/.test(destination.pathname)
+ || /^\/in\/[^/]+\/overlay\/contact-info\/?$/.test(destination.pathname);
} catch {
return false;
}
diff --git a/test/fixtures/message-recipient-navigation.mjs b/test/fixtures/message-recipient-navigation.mjs
index 8423f1cb3..e39f593de 100644
--- a/test/fixtures/message-recipient-navigation.mjs
+++ b/test/fixtures/message-recipient-navigation.mjs
@@ -25,6 +25,15 @@ export function registerMessageRecipientNavigationFixtures({
<a id="jobs" class="destination" href="/jobs/"><span id="jobs-label">Jobs</span></a>
<a id="messaging" href="/messaging/">Messaging</a>
</nav>
+ <main>
+ <a id="portfolio" href="https://portfolio.example/"><span id="portfolio-label">View my portfolio</span></a>
+ <a id="contact-info" href="/in/alice/overlay/contact-info/">Contact info</a>
+ </main>
+ <div id="contact-info-dialog" role="dialog" aria-modal="true" hidden>
+ <button id="close-contact-info" type="button">Close</button>
+ <a id="safety-portfolio" href="/safety/go/?url=https%3A%2F%2Fportfolio.example%2F">portfolio.example</a>
+ <a id="legacy-portfolio" href="/redir/redirect?url=https%3A%2F%2Flegacy-portfolio.example%2F">legacy-portfolio.example</a>
+ </div>
<form id="chat" hidden>
<h2>Alice</h2><textarea id="body">Hello Alice</textarea><button id="send" type="button">Send</button>
</form>`, kind);
@@ -65,9 +74,83 @@ export function registerMessageRecipientNavigationFixtures({
}
});
+ register(`${kind}: LinkedIn ordinary document links bypass the message recipient guard (#3010)`, async (page) => {
+ const { guard, probe } = await setup(page);
+ for (const open of [false, true]) {
+ await page.evaluate(open => { document.querySelector('#chat').hidden = !open; }, open);
+ const portfolioRef = await page.evaluate(
+ () => window.__wb_ax_ref(document.querySelector('#portfolio-label')),
+ );
+ for (const [tool, args, expected] of [
+ ['click', { text: 'View my portfolio', textMatch: 'exact' }, 'portfolio'],
+ ['click_ax', { ref_id: portfolioRef }, 'portfolio'],
+ ['click', { text: 'Contact info', textMatch: 'exact' }, 'contact-info'],
+ ]) {
+ const result = await probe(tool, args);
+ assert.equal(result.conclusive, true, JSON.stringify(result));
+ assert.equal(result.messageSend, false);
+ assert.equal(result.navigation, true);
+ assert.equal(await guard(tool, args), null);
+ const clicked = await call(page, tool, args);
+ assert.equal(clicked.success, true, JSON.stringify(clicked));
+ assert.equal(await page.evaluate(() => window.fixtureClicks.at(-1)), expected);
+ }
+ }
+ });
+
+ register(`${kind}: LinkedIn contact-info safety redirects navigate inside the modal (#3010)`, async (page) => {
+ const { guard, probe } = await setup(page);
+ await page.evaluate(() => {
+ history.replaceState(null, '', '/in/alice/overlay/contact-info/');
+ document.querySelector('#contact-info-dialog').hidden = false;
+ });
+ for (const open of [false, true]) {
+ await page.evaluate(open => { document.querySelector('#chat').hidden = !open; }, open);
+ const safetyRef = await page.evaluate(
+ () => window.__wb_ax_ref(document.querySelector('#safety-portfolio')),
+ );
+ for (const [tool, args, expected] of [
+ ['click', { text: 'portfolio.example', textMatch: 'exact' }, 'safety-portfolio'],
+ ['click_ax', { ref_id: safetyRef }, 'safety-portfolio'],
+ ['click', { text: 'legacy-portfolio.example', textMatch: 'exact' }, 'legacy-portfolio'],
+ ]) {
+ const result = await probe(tool, args);
+ assert.equal(result.conclusive, true, JSON.stringify(result));
+ assert.equal(result.messageSend, false);
+ assert.equal(result.navigation, true);
+ assert.equal(await guard(tool, args), null);
+ const clicked = await call(page, tool, args);
+ assert.equal(clicked.success, true, JSON.stringify(clicked));
+ assert.equal(await page.evaluate(() => window.fixtureClicks.at(-1)), expected);
+ }
+ }
+ for (const href of [
+ 'https://portfolio.example/',
+ '/safety/go/',
+ '/safety/go/?url=javascript%3Aalert(1)',
+ '/safety/go/?url=https%3A%2F%2Flinkedin.com%2Fmessaging%2Fsend',
+ ]) {
+ await page.locator('#safety-portfolio').evaluate((el, value) => el.setAttribute('href', value), href);
+ const result = await probe('click', { text: 'portfolio.example', textMatch: 'exact' });
+ assert.notEqual(result.navigation, true, `${href}: ${JSON.stringify(result)}`);
+ }
+ });
+
register(`${kind}: LinkedIn recipient guard rejects ambiguous navigation and action lookalikes`, async (page) => {
const { guard } = await setup(page);
- for (const href of ['#', 'javascript:void(0)', 'https://example.com/jobs/', '/messaging/compose/', '/messaging/send/']) {
+ for (const href of [
+ '#',
+ 'javascript:void(0)',
+ 'mailto:[email protected]',
+ '/in/alice/',
+ '/messaging/compose/',
+ '/messaging/send/',
+ 'https://linkedin.com/messaging/send/',
+ '/safety/go/',
+ '/safety/go/?url=javascript%3Aalert(1)',
+ '/safety/go/?url=https%3A%2F%2Fwww.linkedin.com%2Fmessaging%2Fsend',
+ '/safety/go/?url=https%3A%2F%2Flinkedin.com%2Fmessaging%2Fsend',
+ ]) {
await page.locator('#jobs').evaluate((el, href) => el.setAttribute('href', href), href);
assert.equal((await guard('click', { text: 'Jobs' }))?.noDispatch, true, href);
}