DEV Community

Cover image for DotShare 3.7: Fixing a token leak, moving OAuth home, and teaching agents to sign in
freerave
freerave

Posted on

DotShare 3.7: Fixing a token leak, moving OAuth home, and teaching agents to sign in

The small OAuth server behind DotShare's LinkedIn and X sign-in could hand a user's LinkedIn or X tokens to anyone who sent them the right link. I found it while planning something unrelated: moving DotShare's sign-in from a separate Vercel app onto dotsuite.dev, so every DotShare service would live under one domain.

This post covers that fix, the move, and what the move made possible. AI agents can now sign in through the browser instead of pasting tokens. X tokens renew themselves. Saved drafts can be scheduled. Agents can post videos and read how their posts are doing. It all ships as DotShare 3.7.0 and dotshare-cli 3.1.0.

This isn't Part 2 of the series: Part 2 covers revision-bound approval and encrypted storage. This one is about sign-in, and what changes once sign-in is done properly.

The old server, and three problems in it

DotShare is an open-source VS Code extension that turns commits and release notes into posts for LinkedIn, X, Bluesky, Mastodon, Telegram, Discord and Dev.to. Since 3.6.0 it also ships a local MCP server, so an agent like Codex or Claude Code can draft and publish through the same library.

LinkedIn and X need OAuth, and OAuth needs a server that holds the client secret. For DotShare that was dotshare-auth-server, a small Next.js app on Vercel. The extension opened /auth/x?scheme=vscode in the browser. The page ran PKCE, the provider sent the user back, the page exchanged the code, and then it sent the tokens to the editor with a deep link:

window.location.href = `${scheme}://freerave.dotshare/auth?${params}`;
Enter fullscreen mode Exit fullscreen mode

1. scheme came straight from the URL. It was meant to be vscode, cursor and so on, because each editor registers its own URI scheme. Nothing checked it, though. With ?scheme=https://attacker.example/?, the "deep link" became an ordinary web URL, and after a perfectly normal LinkedIn or X sign-in, the victim's access and refresh tokens went to the attacker. The attacker only had to get someone to click a sign-in link.

2. The token exchange accepted a userId from the request body and saved the tokens to that DotSuite account through an internal endpoint. Nothing in DotShare sent userId, but the endpoint was public. Anyone with their own authorization code could attach their social account to someone else's DotSuite user.

3. LinkedIn sign-in had no state parameter, which left the classic login CSRF open. X had one, because PKCE flows usually do. LinkedIn didn't.

Before: the sign-in page put any scheme into the deep link, so ?scheme=https://attacker.example/? sent the tokens to the attacker. After: only editor schemes are allowed, anything else becomes vscode. Also fixed: userId from the request body, and LinkedIn's missing state.

The fix for the first one is an allowlist with a safe default:

export const EDITOR_SCHEMES = [
  'vscode', 'vscode-insiders', 'vscodium', 'code-oss',
  'cursor', 'windsurf', 'kiro', 'trae', 'positron',
] as const;

export function editorScheme(value: string | null | undefined): EditorScheme {
  return EDITOR_SCHEMES.find(scheme => scheme === value) ?? 'vscode';
}
Enter fullscreen mode Exit fullscreen mode

The userId field and the sync behind it are gone. Tokens from that server now go only to the user's own editor, and state is required for both providers. The fix went to Vercel before anything else in this post, and it's live there now.

Moving sign-in onto dotsuite.dev

With the holes closed, I moved sign-in into the DotSuite site, which is also Next.js. Instead of copying the client-side flow, I rewrote it to run entirely on the server:

  1. GET /api/connect/x creates the state and PKCE verifier and stores them, with the target editor, in an HMAC-signed, httpOnly cookie that lasts 10 minutes. Then it redirects to X.
  2. X redirects back to /api/connect/x/callback. The server checks the signature, compares the state in constant time, and exchanges the code. The client secret never reaches a browser.
  3. The cookie is cleared whatever the outcome, so each sign-in can be used once.

Sign-in on dotsuite.dev: GET /api/connect/x stores state and the PKCE verifier in a signed httpOnly cookie, X asks the user, and the callback checks the cookie, compares state in constant time and exchanges the code. The result goes to the editor, the DotSuite account, or the CLI.

Nothing depends on sessionStorage anymore. A sign-in that expired, or that started in a different browser, ends with a clear message and a Try again button instead of a blank page.

The same callback now serves three destinations:

  • editor: a small page that opens vscode://freerave.dotshare/auth?... (or Cursor, Windsurf, VSCodium and the others) and offers a button in case the browser asks first.
  • cloud: saves the account to the signed-in DotSuite user for scheduled posts. The user comes from the session, and the callback checks that the same user both started and finished the sign-in.
  • cli: the new one, covered next.

I used a path on the main domain (dotsuite.dev/api/connect) instead of auth.dotsuite.dev. On the same origin, the dashboard's Connect button can use the DotSuite session as it is, with no cross-subdomain cookies to manage.

The Vercel server keeps running for now. DotShare 3.6.x calls it directly and refuses HTTP redirects, so redirecting it would quietly break X token refresh for everyone who hasn't updated. It retires once traffic reaches zero.

Agents sign in through the browser

Until 3.7, adding a LinkedIn or X account to the agent CLI meant pasting an access token. For LinkedIn, that meant using LinkedIn's token generator, which failed during launch with a "state parameter" error. Now it's one command:

dotshare-agent accounts connect work-x --platform x
Enter fullscreen mode Exit fullscreen mode

The browser opens, you approve DotShare on X, and the terminal prints the saved account. There's nothing to copy.

The interesting part is how the tokens get back to the terminal. The CLI listens on 127.0.0.1 on a random port, and the obvious approach is to redirect the browser to http://127.0.0.1:PORT/callback?access_token=.... That puts live tokens in a URL, in browser history, and in front of anything else listening on that machine.

Instead, the CLI generates a fresh X25519 key pair for each sign-in and sends dotsuite.dev only the public key and a random nonce. The server encrypts the result to that key:

const own = generateKeyPairSync('x25519');
const shared = diffieHellman({ privateKey: own.privateKey, publicKey: cliKey });
const key = hkdfSync('sha256', shared, salt, 'dotshare-connect-v1', 32);
// AES-256-GCM over { nonce, platform, token }
Enter fullscreen mode Exit fullscreen mode

The loopback URL carries only ciphertext. The private key exists in the memory of that one CLI process and nowhere else, so the payload is useless even if it ends up in history.

The CLI makes an X25519 key pair and a nonce and opens the browser with the public key. dotsuite.dev encrypts the token with AES-256-GCM to that key and redirects to 127.0.0.1 with ciphertext only. The CLI decrypts it, checks the nonce and saves the account to the OS keyring.

Encryption alone doesn't stop one thing: anyone can encrypt to a public key. A malicious page could send its own tokens to the CLI's port and connect the user to the attacker's account. The nonce prevents that. It sits inside the ciphertext, the CLI checks it, and the attacker never sees it.

My first version failed the whole sign-in when a result didn't verify. That's a denial of service: any page could cancel your sign-in just by hitting the port. Now results that don't verify are ignored, and only the genuine one (or the timeout) ends the wait. A test sends a forged payload, a wrong platform, garbage and a forged cancel before the real one, and checks that only the real one is saved.

X tokens that last two hours

Update since 3.8: X posts now go through DotSuite, which keeps the X token on the server. X tokens no longer reach your device, and the refresh endpoint described here is retired. This section describes how 3.7 handled them.

X OAuth 2.0 access tokens expire after about two hours. The agent used to store only the access token, so MCP posting to X stopped working shortly after an account was added.

Accounts connected through the browser now keep the refresh token. Before publishing (or a doctor check), DotShare swaps it through dotsuite.dev/api/connect/refresh/x when the access token has less than five minutes left. Two details mattered.

X rotates refresh tokens. The old one dies as soon as X accepts the request, so the new pair is written to the OS keyring before it's used. If two MCP clients refresh at the same moment, one of them loses. The loser doesn't fail: it re-reads the keyring, sees that the other process already saved a new pair, and uses that.

Refreshing mustn't invalidate a saved preview. DotShare binds approval to a preview, and the preview records a fingerprint of every account it targets, so changed credentials force a new review. Hashing the access token would have expired every X preview within two hours. A connected account now gets a connectionId at sign-in, and the fingerprint covers that instead of the rotating tokens. A refresh leaves previews valid. Connecting a different login still invalidates them.

Scheduling a saved draft

schedule_post existed, but it took one text for every platform and public image URLs only. The new schedule_draft takes a previewed draft, with the same revision and preview checks as publish_draft, and sends DotSuite one post per platform, each with that platform's own version. Local images are uploaded to DotSuite first, so a failed upload schedules nothing. The draft's status becomes Scheduled.

The cloud scheduler can't do everything yet, and the tool says so instead of half-doing it. It refuses threads, LinkedIn first comments, videos, Discord and Dev.to with a reason, and it refuses drafts where two accounts on the same platform have different text, because DotSuite holds one connection per platform.

Writing it turned up an old bug. The CLI read the scheduled post's ID from id, but DotSuite returns post_id. Every schedule succeeded, but the receipt never recorded which post to cancel.

Video, GIFs, and one thing I didn't ship

Agents can now attach MP4 and MOV videos on X, LinkedIn, Mastodon, Telegram and Discord (WebM on Mastodon and Discord), and GIFs on X, Mastodon, Telegram and Discord. Files are identified by their first bytes, not just the extension, and preview shows each platform's size limit before anything uploads.

X needed real work. DotShare's video path used X's v1.1 INIT/APPEND/FINALIZE upload, which doesn't accept OAuth 2.0 user tokens. So video and GIF uploads to X could never have worked with those tokens. Following X's current docs, I replaced it with the v2 chunked upload: initialize, then 4 MB append segments, then finalize, then polling the status until processing succeeds before the post is created.

Bluesky video isn't in this release. Its upload goes through a separate video service with its own auth, and I couldn't get the current documentation or the lexicon files from any source I tried. I wasn't going to ship it from memory, so the preview says plainly that Bluesky accepts images only.

Smaller things

  • Bluesky mentions. @handle.domain becomes a real mention facet when the handle resolves. Unknown handles stay plain text, as they do in the Bluesky app. Links and hashtags were fixed in 3.6.1.
  • get_post_stats. Read-only engagement for something DotShare published: likes, reposts, replies and quotes on X, Bluesky and Mastodon, plus impressions on X, likes and comments on LinkedIn, and views, reactions and comments on Dev.to. Telegram and Discord don't offer message metrics. LinkedIn and X may withhold them depending on the app's access or API plan, and the result says why when that happens.
  • One-command setup for Claude Code and Cursor. setup --client claude registers the server through claude mcp add-json. --client cursor merges into ~/.cursor/mcp.json while keeping your other servers, and saves a backup.
  • A skill for agents. The npm package now ships skills/dotshare/SKILL.md, which teaches an agent the draft → preview → approval → publish workflow and the per-platform rules. I checked every tool and field name in it against the server code. That check caught two mistakes in my own first draft: a wrong field name in the template tools, and a claim about Bluesky mentions that wasn't true yet. It's true now.

How it was tested

  • 399 Jest tests pass, 18 of them new for this release. The loopback tests use a real HTTP server.
  • A cross-repository check ran the real connectAccount from the CLI against the real encryption code from dotsuite.dev, for both LinkedIn and X.
  • The existing end-to-end scripts drive the real MCP transport (now 25 tools), the VS Code library bridge and the encrypted store.
  • The CLI tarball was installed into a clean prefix and run from there.

Live sign-ins against the production LinkedIn and X apps on dotsuite.dev, including a real X token refresh with rotation, have since been tested too.

Try it

npm install -g dotshare-cli
dotshare-agent setup --client claude        # or --client cursor, or Codex by default
dotshare-agent accounts connect work-linkedin --platform linkedin
dotshare-agent doctor --check-accounts
Enter fullscreen mode Exit fullscreen mode

The VS Code extension is on the Marketplace and Open VSX. The full changelog and the agent guide cover everything above in more detail.

I used AI assistance (Claude) to build, test and write up this release. The numbers and behavior described come from the shipped code and its tests.

Top comments (4)

Collapse
 
userxnom profile image
Abdullah Naseer •

The X25519 loopback design is the part I'd steal — keeping live tokens out of the redirect URL entirely, so they never land in browser history or in front of anything else on that port. And the concurrent-refresh recovery is neat: the loser just re-reads the keyring instead of failing. One window I'm curious about: the old refresh token dies the moment X accepts the request, so if the process crashes between that accept and the new pair landing in the keyring, there's no usable token left. Is that a gap you've accepted as a reconnect, or does something survive it?

Collapse
 
freerave profile image
freerave •

Good catch, and yes, that window exists. X rotates the pair as soon as it accepts the refresh, and the CLI writes the new pair to the keyring right after the response comes back. If the process dies between those two steps, the new pair is lost and the old refresh token is already dead. The next refresh gets a 401, and DotShare tells you to reconnect with dotshare-agent accounts connect. So it's an accepted reconnect rather than a silent failure. The window is one HTTP response plus a keyring write, so I didn't build more around it.

Since 3.8 it has mostly moved off the device anyway: X posting goes through DotSuite, which keeps the X token on the server, so the CLI no longer refreshes X tokens.

Collapse
 
parlup profile image
parlupme •

Great breakdown of both the open-redirect deep-link pitfall and the encrypted loopback handoff. Keeping the X25519 keypair in process memory and binding the nonce inside the AES-256-GCM payload neatly avoids leaking tokens into browser history or letting another local process inject an account. Binding preview fingerprints to a stable connectionId instead of rotating OAuth tokens—and moving X posting server-side in 3.8 so refresh tokens never leave the backend—is also a clean pattern for multi-client MCP setups where two agent processes might otherwise race on token rotation.

Collapse
 
freerave profile image
freerave •

Thanks! The connectionId part took a second look: hashing the token felt right until every X preview expired after two hours.