Skip to content

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

Scope social API publication guard

Emre Sokullu518c7f468297
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 940392058..72e5e6c44 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -18476,7 +18476,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
});
if (networkMutation) {
let platform;
- try { platform = socialPublicationApiPlatform(args?.url); }
+ try { platform = socialPublicationApiPlatform(args?.url, args?.body); }
catch {
return { success: false, dispatched: false, noDispatch: true,
error: 'The API destination could not be resolved. Use an explicit HTTP(S) URL without embedded credentials.' };
diff --git a/src/chrome/src/agent/social-publish-contract.js b/src/chrome/src/agent/social-publish-contract.js
index 1aaf95511..7a902a685 100644
--- a/src/chrome/src/agent/social-publish-contract.js
+++ b/src/chrome/src/agent/social-publish-contract.js
@@ -3,10 +3,11 @@
export const SOCIAL_PLATFORMS = Object.freeze(['twitter', 'bluesky']);
// Network tools act on their explicit destination, independently of the open
-// tab. Include API hosts and AT Protocol repository writes on self-hosted PDSes.
+// tab. API hosts can carry unrelated account mutations, so only post creation
+// endpoints and AT Protocol post records select the publication guard.
// This only selects the publication guard; API permission, SSRF, and redirect
// checks still belong to the network dispatch path.
-export function socialPublicationApiPlatform(rawUrl) {
+export function socialPublicationApiPlatform(rawUrl, body) {
if (typeof rawUrl !== 'string') throw new Error('Missing network destination');
const url = new URL(rawUrl);
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password) {
@@ -14,10 +15,21 @@ export function socialPublicationApiPlatform(rawUrl) {
}
const host = url.hostname.toLowerCase().replace(/\.$/, '');
const within = domain => host === domain || host.endsWith('.' + domain);
- if (['x.com', 'twitter.com'].some(within)) return 'twitter';
- if (['bsky.app', 'bsky.social', 'bsky.network'].some(within)
- || decodeURIComponent(url.pathname).startsWith('/xrpc/com.atproto.repo.')) return 'bluesky';
- return null;
+ const path = decodeURIComponent(url.pathname).replace(/\/$/, '');
+ if (['x.com', 'twitter.com'].some(within)
+ && (/\/i\/api\/graphql\/(?:[^/]+\/)?CreateTweet$/i.test(path)
+ || /^\/2\/tweets$/i.test(path)
+ || /^\/1\.1\/statuses\/update\.json$/i.test(path))) return 'twitter';
+ if (within('bsky.app') && path === '/api/post') return 'bluesky';
+ if (!path.startsWith('/xrpc/com.atproto.repo.')) return null;
+ let payload;
+ try { payload = typeof body === 'string' ? JSON.parse(body) : body; }
+ catch { return 'bluesky'; }
+ const isPost = value => value?.collection === 'app.bsky.feed.post';
+ if (Array.isArray(payload?.writes)) {
+ return payload.writes.every(write => typeof write?.collection === 'string' && !isPost(write)) ? null : 'bluesky';
+ }
+ return typeof payload?.collection === 'string' && !isPost(payload) ? null : 'bluesky';
}
const TYPES = ['any', 'image', 'video', 'gif'];
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index a9a3dbe59..5b126d6de 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -16287,7 +16287,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
});
if (networkMutation) {
let platform;
- try { platform = socialPublicationApiPlatform(args?.url); }
+ try { platform = socialPublicationApiPlatform(args?.url, args?.body); }
catch {
return { success: false, dispatched: false, noDispatch: true,
error: 'The API destination could not be resolved. Use an explicit HTTP(S) URL without embedded credentials.' };
diff --git a/src/firefox/src/agent/social-publish-contract.js b/src/firefox/src/agent/social-publish-contract.js
index 1aaf95511..7a902a685 100644
--- a/src/firefox/src/agent/social-publish-contract.js
+++ b/src/firefox/src/agent/social-publish-contract.js
@@ -3,10 +3,11 @@
export const SOCIAL_PLATFORMS = Object.freeze(['twitter', 'bluesky']);
// Network tools act on their explicit destination, independently of the open
-// tab. Include API hosts and AT Protocol repository writes on self-hosted PDSes.
+// tab. API hosts can carry unrelated account mutations, so only post creation
+// endpoints and AT Protocol post records select the publication guard.
// This only selects the publication guard; API permission, SSRF, and redirect
// checks still belong to the network dispatch path.
-export function socialPublicationApiPlatform(rawUrl) {
+export function socialPublicationApiPlatform(rawUrl, body) {
if (typeof rawUrl !== 'string') throw new Error('Missing network destination');
const url = new URL(rawUrl);
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password) {
@@ -14,10 +15,21 @@ export function socialPublicationApiPlatform(rawUrl) {
}
const host = url.hostname.toLowerCase().replace(/\.$/, '');
const within = domain => host === domain || host.endsWith('.' + domain);
- if (['x.com', 'twitter.com'].some(within)) return 'twitter';
- if (['bsky.app', 'bsky.social', 'bsky.network'].some(within)
- || decodeURIComponent(url.pathname).startsWith('/xrpc/com.atproto.repo.')) return 'bluesky';
- return null;
+ const path = decodeURIComponent(url.pathname).replace(/\/$/, '');
+ if (['x.com', 'twitter.com'].some(within)
+ && (/\/i\/api\/graphql\/(?:[^/]+\/)?CreateTweet$/i.test(path)
+ || /^\/2\/tweets$/i.test(path)
+ || /^\/1\.1\/statuses\/update\.json$/i.test(path))) return 'twitter';
+ if (within('bsky.app') && path === '/api/post') return 'bluesky';
+ if (!path.startsWith('/xrpc/com.atproto.repo.')) return null;
+ let payload;
+ try { payload = typeof body === 'string' ? JSON.parse(body) : body; }
+ catch { return 'bluesky'; }
+ const isPost = value => value?.collection === 'app.bsky.feed.post';
+ if (Array.isArray(payload?.writes)) {
+ return payload.writes.every(write => typeof write?.collection === 'string' && !isPost(write)) ? null : 'bluesky';
+ }
+ return typeof payload?.collection === 'string' && !isPost(payload) ? null : 'bluesky';
}
const TYPES = ['any', 'image', 'video', 'gif'];
diff --git a/test/social-publish-contract.mjs b/test/social-publish-contract.mjs
index 37125aec9..e95683623 100644
--- a/test/social-publish-contract.mjs
+++ b/test/social-publish-contract.mjs
@@ -715,7 +715,7 @@ for (const browser of ['chrome', 'firefox']) {
});
test(`${browser}: publication shortcuts and page callbacks cannot bypass the concrete click contract`,async()=>{
- for(const [name,args] of [['press_keys',{key:'Space'}],['press_keys',{key:'Enter'}],['execute_js',{code:'publish()'}],['execute_webmcp_tool',{}],['fetch_url',{url:'https://x.com/api/post',method:'POST'}]]){
+ for(const [name,args] of [['press_keys',{key:'Space'}],['press_keys',{key:'Enter'}],['execute_js',{code:'publish()'}],['execute_webmcp_tool',{}],['fetch_url',{url:'https://x.com/i/api/graphql/CreateTweet',method:'POST'}]]){
const f=setup();
assert((await f.agent._workflowPreSubmitDispatchBlock(f.tabId,name,args,null,f.provider)).noDispatch);
}
@@ -747,21 +747,21 @@ for (const browser of ['chrome', 'firefox']) {
test(`${browser}: social API writes stay guarded independently of the active page`, async () => {
const f = setup('Call the business in Turkish');
const destinations = [
- 'https://x.com/i/api/graphql/CreateTweet',
- 'https://api.x.com/2/tweets',
- 'https://api.twitter.com/1.1/statuses/update.json',
- 'https://API.X.COM.:443/2/tweets',
- 'https://bsky.app/api/post',
- 'https://bsky.social/xrpc/com.atproto.repo.createRecord',
- 'https://pds.host.bsky.network/xrpc/com.atproto.repo.putRecord',
- 'https://pds.example/xrpc/com.atproto.repo.applyWrites',
- 'https://pds.example/xrpc/%63om.atproto.repo.createRecord',
+ ['https://x.com/i/api/graphql/CreateTweet', undefined],
+ ['https://api.x.com/2/tweets', undefined],
+ ['https://api.twitter.com/1.1/statuses/update.json', undefined],
+ ['https://API.X.COM.:443/2/tweets', undefined],
+ ['https://bsky.app/api/post', undefined],
+ ['https://bsky.social/xrpc/com.atproto.repo.createRecord', '{"collection":"app.bsky.feed.post"}'],
+ ['https://pds.host.bsky.network/xrpc/com.atproto.repo.putRecord', '{"collection":"app.bsky.feed.post"}'],
+ ['https://pds.example/xrpc/com.atproto.repo.applyWrites', '{"writes":[{"collection":"app.bsky.feed.post"}]}'],
+ ['https://pds.example/xrpc/%63om.atproto.repo.createRecord', '{"collection":"app.bsky.feed.post"}'],
];
for (const page of ['https://x.com/home', 'https://bsky.app/', 'https://phonr.xyz/docs']) {
f.agent._currentUrl = async () => page;
for (const name of ['fetch_url', 'research_url']) {
- for (const url of destinations) {
- const result = await f.agent._workflowPreSubmitDispatchBlock(f.tabId, name, { url, method: 'POST' }, null, f.provider);
+ for (const [url, body] of destinations) {
+ const result = await f.agent._workflowPreSubmitDispatchBlock(f.tabId, name, { url, body, method: 'POST' }, null, f.provider);
assert.equal(result?.noDispatch, true, `${page}: ${name} ${url}`);
assert.equal(result.dispatched, false);
assert.equal(result.workflowJob, 'publish-post');
@@ -774,6 +774,21 @@ for (const browser of ['chrome', 'firefox']) {
assert.equal(f.calls.length, 0);
});
+ test(`${browser}: non-publication social API writes retain normal API authorization`, async () => {
+ const f = setup('Like the post and update my Bluesky profile');
+ const destinations = [
+ ['https://api.x.com/2/users/123/likes', undefined],
+ ['https://x.com/i/api/graphql/FavoriteTweet', undefined],
+ ['https://bsky.social/xrpc/com.atproto.repo.putRecord', '{"collection":"app.bsky.actor.profile"}'],
+ ['https://pds.example/xrpc/com.atproto.repo.applyWrites', '{"writes":[{"collection":"app.bsky.graph.listitem"}]}'],
+ ];
+ for (const [url, body] of destinations) {
+ const result = await f.agent._workflowPreSubmitDispatchBlock(f.tabId, 'fetch_url', { url, body, method: 'POST' }, null, f.provider);
+ assert.equal(result, null, url);
+ }
+ assert.equal(f.calls.length, 0);
+ });
+
test(`${browser}: unresolved network destinations cannot claim an unrelated-API exemption`, async () => {
const f = setup();
for (const page of ['https://x.com/home', 'https://phonr.xyz/docs']) {