Skip to content

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

Infer hCaptcha Enterprise from explicit rqdata

Emre Sokullub6aeb453b436
diff --git a/src/chrome/src/agent/captcha-hcaptcha-providers.js b/src/chrome/src/agent/captcha-hcaptcha-providers.js
index acbb16922..9fed02aee 100644
--- a/src/chrome/src/agent/captcha-hcaptcha-providers.js
+++ b/src/chrome/src/agent/captcha-hcaptcha-providers.js
@@ -31,6 +31,9 @@ export function hcaptchaParamError(params) {
try {
if (!['http:', 'https:'].includes(new URL(params.websiteURL).protocol)) throw new Error();
} catch { return 'solve_captcha: hCaptcha requires an HTTP(S) page URL.'; }
+ if (params.rqdata && params.isEnterprise === false) {
+ return 'solve_captcha: isEnterprise=false conflicts with observed hCaptcha rqdata, which requires Enterprise.';
+ }
return null;
}
@@ -44,7 +47,7 @@ export function buildHcaptchaTask(id, params) {
...(params.userAgent ? { useragent: params.userAgent } : {}),
};
// NoneCap ignores caller-supplied user_agent; do not claim to control it.
- return { type: params.isEnterprise ? 'hcaptcha_enterprise' : 'hcaptcha', ...common,
+ return { type: params.isEnterprise || params.rqdata ? 'hcaptcha_enterprise' : 'hcaptcha', ...common,
...(params.rqdata ? { rqdata: params.rqdata } : {}),
};
}
diff --git a/src/firefox/src/agent/captcha-hcaptcha-providers.js b/src/firefox/src/agent/captcha-hcaptcha-providers.js
index acbb16922..9fed02aee 100644
--- a/src/firefox/src/agent/captcha-hcaptcha-providers.js
+++ b/src/firefox/src/agent/captcha-hcaptcha-providers.js
@@ -31,6 +31,9 @@ export function hcaptchaParamError(params) {
try {
if (!['http:', 'https:'].includes(new URL(params.websiteURL).protocol)) throw new Error();
} catch { return 'solve_captcha: hCaptcha requires an HTTP(S) page URL.'; }
+ if (params.rqdata && params.isEnterprise === false) {
+ return 'solve_captcha: isEnterprise=false conflicts with observed hCaptcha rqdata, which requires Enterprise.';
+ }
return null;
}
@@ -44,7 +47,7 @@ export function buildHcaptchaTask(id, params) {
...(params.userAgent ? { useragent: params.userAgent } : {}),
};
// NoneCap ignores caller-supplied user_agent; do not claim to control it.
- return { type: params.isEnterprise ? 'hcaptcha_enterprise' : 'hcaptcha', ...common,
+ return { type: params.isEnterprise || params.rqdata ? 'hcaptcha_enterprise' : 'hcaptcha', ...common,
...(params.rqdata ? { rqdata: params.rqdata } : {}),
};
}
diff --git a/test/captcha-hcaptcha-providers.mjs b/test/captcha-hcaptcha-providers.mjs
index e5603e616..24ee10e53 100644
--- a/test/captcha-hcaptcha-providers.mjs
+++ b/test/captcha-hcaptcha-providers.mjs
@@ -45,6 +45,9 @@ for (const build of ['chrome', 'firefox']) {
const options = {...params,isEnterprise:true,rqdata:'observed-rqdata',userAgent:'browser-agent'};
assert.deepEqual(h.buildHcaptchaTask('nopecha',options),{sitekey:params.websiteKey,url:params.websiteURL,data:{rqdata:'observed-rqdata'},useragent:'browser-agent'});
assert.deepEqual(h.buildHcaptchaTask('nonecap',options),{type:'hcaptcha_enterprise',sitekey:params.websiteKey,url:params.websiteURL,rqdata:'observed-rqdata'});
+ assert.deepEqual(h.buildHcaptchaTask('nonecap',{...params,rqdata:'observed-rqdata'}),{type:'hcaptcha_enterprise',sitekey:params.websiteKey,url:params.websiteURL,rqdata:'observed-rqdata'});
+ assert.match(h.hcaptchaParamError({...params,rqdata:'observed-rqdata',isEnterprise:false}),/conflicts with observed hCaptcha rqdata/);
+ assert.throws(()=>h.buildHcaptchaTask('nonecap',{...params,rqdata:'observed-rqdata',isEnterprise:false}),/conflicts with observed hCaptcha rqdata/);
for (const invalid of [{...params,websiteKey:'invalid'},{...params,websiteURL:'file:///secret'}]) assert.ok(h.hcaptchaParamError(invalid));
assert.equal(h.hcaptchaParamError(params),null);
assert.equal(h.hcaptchaParamError({...params,isEnterprise:true}),null);
diff --git a/test/run.js b/test/run.js
index 684688acb..afb9d22ca 100644
--- a/test/run.js
+++ b/test/run.js
@@ -121976,6 +121976,39 @@ test('CAPTCHA providers: observed hCaptcha rqdata reaches fallback and returns t
}
});
+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 () => {
+ 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' }),
+ ...(build === 'firefox' ? { executeScript: async () => { throw new Error('frame detection unavailable'); } } : {}) };
+ if (build === 'chrome') api.scripting.executeScript = async () => { throw new Error('frame detection unavailable'); };
+ const originalFetch = globalThis.fetch;
+ const calls = [];
+ globalThis.fetch = async (_url, options) => {
+ calls.push(JSON.parse(options.body));
+ return Response.json({ id: 'solve_test', status: 'solved', token: 'P1_token' });
+ };
+ try {
+ const agent = new AgentClass({});
+ const args = { type: 'hcaptcha', websiteKey: 'f5ab1c2d-7e8f-4a9b-b1c2-d3e4f5a6b7c8', rqdata: 'observed-rqdata', inject: false };
+ const conflict = await agent._executeToolImpl(1, 'solve_captcha', { ...args, isEnterprise: false });
+ assert.equal(conflict.dispatched, false, build);
+ assert.match(conflict.error, /conflicts with observed hCaptcha rqdata/, build);
+ assert.equal(calls.length, 0, build);
+ const result = await agent._executeToolImpl(1, 'solve_captcha', args);
+ assert.equal(result.success, true, `${build}: ${result.error}`);
+ assert.equal(result.provider, 'nonecap', build);
+ assert.deepEqual(calls, [{ type: 'hcaptcha_enterprise', sitekey: args.websiteKey,
+ url: 'https://example.test/form', rqdata: 'observed-rqdata' }]);
+ } finally { globalThis.fetch = originalFetch; }
+ });
+ }
+});
+
test('CAPTCHA native methods dispatch through the real agent, preserve structured answers, and keep gates scoped', async () => {
for (const [build, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
await withCaptchaFakePage(build, [], async () => {