Skip to content

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

Guard NoneCap token injection by browser User-Agent

Emre Sokullu793212990501
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 1e08a83bb..da324cb6d 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -36091,6 +36091,13 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
dispatched = true;
const result = await solveCaptchaWithProviders(providers, params);
+ if (wantInject && result.provider === 'nonecap' && result.solution?.userAgent
+ && result.solution.userAgent !== params.userAgent) {
+ return { success: false, dispatched: true, manualCompletionRequired: true,
+ provider: result.provider, taskId: result.taskId, injected: false,
+ solverUserAgent: result.solution.userAgent,
+ error: 'NoneCap solved this hCaptcha with a different User-Agent. The token was not injected; ask the user to complete the challenge manually.' };
+ }
// For non-image types, push the token into the page response field
// unless the caller explicitly opted out.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index c0d2e202d..82d00b3a4 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -33074,6 +33074,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
dispatched = true;
const result = await solveCaptchaWithProviders(providers, params);
+ if (wantInject && result.provider === 'nonecap' && result.solution?.userAgent
+ && result.solution.userAgent !== params.userAgent) {
+ return { success: false, dispatched: true, manualCompletionRequired: true,
+ provider: result.provider, taskId: result.taskId, injected: false,
+ solverUserAgent: result.solution.userAgent,
+ error: 'NoneCap solved this hCaptcha with a different User-Agent. The token was not injected; ask the user to complete the challenge manually.' };
+ }
let injection = null;
if (wantInject && result.fieldName && result.token) {
diff --git a/test/run.js b/test/run.js
index c17b7512e..331bcf868 100644
--- a/test/run.js
+++ b/test/run.js
@@ -121976,6 +121976,42 @@ test('CAPTCHA providers: observed hCaptcha rqdata reaches fallback and returns t
}
});
+test('NoneCap hCaptcha token is not injected when its User-Agent differs from the browser', async () => {
+ for (const [build, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
+ const sitekey = 'f5ab1c2d-7e8f-4a9b-b1c2-d3e4f5a6b7c8';
+ await withCaptchaFakePage(build, [captchaEl('div', { class: 'h-captcha', 'data-sitekey': sitekey })], async () => {
+ const api = build === 'chrome' ? globalThis.chrome : globalThis.browser;
+ api.storage = { local: { get: async () => ({ nonecapEnabled: true,
+ nonecapApiKey: 'nc_live_' + 'a'.repeat(32) }) } };
+ api.tabs = { ...api.tabs, get: async () => ({ url: 'https://example.test/form' }) };
+ const originalExecute = build === 'chrome' ? api.scripting.executeScript : api.tabs.executeScript;
+ let injections = 0;
+ if (build === 'chrome') api.scripting.executeScript = async options => {
+ if (options.world === 'MAIN') injections++;
+ return originalExecute(options);
+ };
+ else api.tabs.executeScript = async (tabId, options) => {
+ if (options.code.includes('injectCaptchaTokenInPage')) injections++;
+ return originalExecute(tabId, options);
+ };
+ const originalFetch = globalThis.fetch;
+ globalThis.fetch = async () => Response.json({ id: 'solve_test', status: 'solved',
+ token: 'paid-token', user_agent: `${globalThis.navigator?.userAgent || ''}-mismatch` });
+ try {
+ const agent = new AgentClass({});
+ const result = await agent._executeToolImpl(1, 'solve_captcha', {});
+ assert.equal(result.success, false, build);
+ assert.equal(result.dispatched, true, build);
+ assert.equal(result.manualCompletionRequired, true, build);
+ assert.equal(result.injected, false, build);
+ assert.equal(result.token, undefined, build);
+ assert.match(result.error, /different User-Agent/, build);
+ assert.equal(injections, 0, build);
+ } finally { globalThis.fetch = originalFetch; }
+ });
+ }
+});
+
test('CAPTCHA providers: explicit rqdata selects NoneCap Enterprise when frame detection is unavailable', async () => {
for (const [build, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
await withCaptchaFakePage(build, [], async () => {