Back

1-Click GitHub Token Stealing via a VSCode Bug

356 points19 hoursblog.ammaraskar.com
zbentley7 hours ago

This is a very good writeup.

Zooming way out (perhaps to the point of useless observation), it's a pity that the web embedded VSCode editor is signed into GitHub at all. Defense-in-depth or not, a huge vulnerability surface arises from that original sin. It'd be like if you had a god-permissioned GitHub API token stored in world-readable plaintext on your workstation for the malicious-NPM-package-of-the-week to find.

In a perfect world, it'd be awesome if the in-browser IDE launched with a temporary per-repo permission scope or token that allowed only pull and push to the repo in question; no github.com web session whatsoever. If you want the full GitHub web UI experience, well .... go back to github.com; make github.dev a single-repo service.

I'm assuming that's a) inconvenient for users, b) hard to implement, and c) a historical assumption baked into a lot of the github.dev tooling, though. Ah well.

ammar27 hours ago

> it'd be awesome if the in-browser IDE launched with a temporary per-repo permission scope

That's actually exactly what they do for codespaces. The token only has read/write on the repo you activated for the codespace [1]. They should definitely consider doing that for github.dev as well.

[1] https://orca.security/resources/blog/hacking-github-codespac...

lifis2 hours ago

I think it's ok to be signed-in when opening your own repositories, but definitely not when opening repositories from other accounts. And also the webview keyboard shortcut thing needs to be fixed to only allow harmless keybinds and NOT propagate to any keydown handler. Also on desktop it should be removed in favor of Electron intercepting directly. And on web it should probably disabled by the default.

ffemac3 hours ago

> malicious-NPM-package-of-the-week

This is going to get worse and worse. I recently noticed AI harness (e.g. OpenCode) downloading random npm packages in the background and litter them everywhere in a few place in ~ and in your project dir, all without telling/asking you.

What's worse is that people don't seem to care even the devs.

amluto6 hours ago

> temporary per-repo permission scope or token that allowed only pull and push to the repo in question

How about pull from the repo but only push to a staging area from which the user, but not the token, can push for real?

Frankly, LLM agents should do this too. Letting your LLM push seems foolhardy to me.

lifis2 hours ago

You can just fork the repository, give it access to the fork and then merge what you want

namibj5 hours ago

Jules is heavily restricted in what it can do to your repos.

alostpuppy5 hours ago

Exe.dev has an integrations feature which is similar allowing you to grant access to specific repos without having give the VMs credentials. I think it’s a similar pattern to iron.sh.

I have been thinking more and more about how I might use this pattern.

moi23885 hours ago

That makes so much more sense.

owl577 hours ago

If the malicious-npm-package-of-the-week is reading arbitrary files on your workstation, isn't it usually able to run git clone/push/whatever with your current credentials anyway?

digi594047 hours ago

Yes, but also no. For example in GitLab a user who’s infected could push code to a branch. Then it could even make a merge request to pull that branch into main (if main is protected).

But then someone else on the team should have to manually approve that MR to allow it to be merged to main.

This kind of defeats the ability of malware to push stuff out automatically.

ikiris6 hours ago

Not if they're touch required in a secure enclave like a yubikey

JessieJanie2 hours ago

Thank you for all your efforts and detail here, noted.

AgentReinAi3 hours ago

The attack surface that makes this particularly nasty is that VSCode extensions run with the same trust level as the editor itself, and most developers have dozens installed without reviewing their permissions. A malicious or compromised extension silently exfiltrating GitHub tokens is undetectable without network monitoring. This is a good argument for running extensions in isolated profiles.

crimsonnoodle582 hours ago

> is undetectable without network monitoring

Even with network monitoring, exfil to Github itself can be very hard to stop unless you SSL intercept and have very strict URL allow lists.

Best is to move away from Github, move to self hosted internal Gitlab/Forgejo and block Github completely.

zuzululu6 hours ago

I had this happen to me recently

github token got stolen and also cloudflare tokens

guys even if you take security seriously you are going to get hit on a long enough time frame

best thing to do is segregate and control damage

trust no one, nothing, use orbstack, and always operate under the assumption that your token is going to get leaked at some point

it knocked off my entire momentum. fortunately seemed like it was just a spam bot that took my tokens and created bunch of fake spam pages and trying to mine crypto

the biggest feeling is the one of feeling violated

take care fellow travelers

pjot5 hours ago

  > created bunch of fake spam pages and trying to mine crypto
Pages like GitHub pages? We’re repos being created in your account? Curious how you discovered that your tokens were pwned
zuzululu5 hours ago

repos created, cloudflare eployed thee websites, edited dns

saw a weird spam site, so damn tired went to bed thinking it was some mislick on my side

woke up next morning and loaded up my domain, it redirected and panic set in

my SEO is probably nuked even though it has been under 24 hours

worldsavior3 hours ago

Secret ad to orbstack.

NagatoYuzuru7 hours ago

> the last time I interacted with MSRC regarding reporting a VSCode bug, it was a horrible experience where they silently fixed the bug

Classic MSRC. It has figured out that researchers will report for free regardless. Why change?

guessmyname6 hours ago

MSRC doesn’t fix bugs.

I don’t know the specifics of this case, but I’ve managed bug bounty programs in the past through Bountysource and HackerOne. One thing that occasionally happens is that a report makes its way to the development team before the security team has fully assessed it, in this case MSRC.

At that point, a developer may decide to quietly fix the issue. Sometimes that’s driven by a concern, rational or not, that being associated with a security bug could reflect poorly on them or affect future promotion opportunities. The result is that by the time the security team attempts to reproduce the report, the vulnerability is already gone.

From MSRC’s perspective, all they see is that the provided reproduction steps no longer work. They have no visibility into the internal history of the bug or whether someone already patched it. As a result, the report gets closed as invalid even though the original finding may have been legitimate.

anonbanana5 hours ago

That makes sense but doesn't excuse the behavior. Just because there is poor communication within Microsoft doesn't make it okay to silently patch a vulnerability. Also, looking at the timeline on OP's post from 2023 it seems they patched it and closed the bug on the same day which is a little sus .

theguidessuck3 hours ago

> They have no visibility into the internal history of the bug or whether someone already patched it.

Aww man, if only they owned some sort of platform for tracking those, powered by some sort of program. Doesn't even have to be a smart problem, it can be, succintly, shortly, stupid. If only.

peterkelly4 hours ago

If only there were some kind of system for recording the version history and viewing what changes had been made to the code between releases.

moi23885 hours ago

Nonsense. As if there are no versions for their software releases.

This is laziness, security absolutely could verify these steps.

natpalmer17767 hours ago

It was the status quo for a long time, then the pesky security researchers started asking for compensation instead of clout.

ammar27 hours ago

> instead of clout

I'm catching up on the infosec twitter side but it seems like it was even worse. A lot of people have the same story as me in 2023 of "they silently patch the bug and don't even credit you" which really stinks.

natpalmer17767 hours ago

It definitely reminds me of the stereotypes of big business types stepping on the little guys to climb the ladder.

I hope you get credit where credit is due in future endeavors.

opello7 hours ago

Do it for the exposure! Artists of many stripes have had to combat that for ages.

meszmate4 hours ago

I don’t really understand why more devs don’t try Neovim.

Maybe it’s just my preference, but I like having a small setup where I know what is installed and what is running. With VSCode, browser IDEs, extensions, sync, tokens, and random plugins, it gets hard to tell what actually has access to what.

strogonoff2 hours ago

I stopped using VS Code and switched to Neovim some years ago, once I noticed that the former would automatically install random Python packages with typings for libraries without stock typings. The “feature” (part of Microsoft’s official Python extension, which was the only one that worked acceptably well for me in other regards) ended up installing type definitions for a different version of a library than the one my project would use, seemed wildly insecure as it casually ran third-party unvetted code, and was evidently not configurable.

I wish I could add “and I never looked back”, but honestly in the past year or two Neovim started regularly breaking my setup (approximately every upgrade). Had some inklings it might happen eventually… Strictly speaking, 10 years in, nvim is yet to have its first stable version released—which means technically one can’t blame it for instability, but which is useful to keep in mind.

Considering going back to plain vim. I’m sure I will lose many niceties, but hopefully it would not require me to troubleshoot broken functionality in the middle of work.

shinycode3 hours ago

I noticed that is quite hard to make people change habits regarding software. There is shortcuts to learn and we might feel slow at first which reinforces the feeling of « it’s not better ». It takes a while to get used to nvim, once there it’s faster but that explain why many people stay in their confort zone

okayishdefaults3 hours ago

One of the most important things I've ever read as someone that wants to be able to break out of my comfort zone was from Uiua's website. Foreign != confusing

ulimn3 hours ago

I really like Helix. I didn't dig into Neovim much but Helix has pretty nice IDE-like features that I always missed from vim (without riddling it with plugins or using SpaceVim or such). Check it out, maybe you'll like it as well.

Noumenon728 hours ago

Thank you for essentially donating the time you spent on this exploit to raise awareness on improving VS Code's security response. You could have just given up on them but you're still trying to help.

ammar26 hours ago

Thank you, that's a very kind comment.

I have no interest in selling these vulnerabilities or sitting on them. At the same time, it feels really bad to have a vendor disrespect the hours it can take to make a proof-of-concept by just patching it silently and not crediting you or acknowledging it.

thrdbndndn6 hours ago

Very good write up but I lost it a little at the end. Could someone clarify for me?

The author said:

You cannot just use the shortcut trick to install the evil extension directly because of new publisher trust system;

You can bypass this by using local workspace extensions which has no publisher screening, but CSP blocks it;

The solution seems to be that installing a local workspace extension which binds a shortcut of 'install extension without checking publisher'.

So I assume it means:

1. you need two extensions, 1st one is local and only for the keybinding, and 2nd one is the 'real' evil one and it doesn't need to (actually can't, because of CSP) be local anymore?

2. the CSP only prevents the JS in local extension but nothing about its package.json (or the ability to add shortcuts), right?

ammar26 hours ago

1 and 2 are correct, take a look at the PoC repo here: https://github.com/ammaraskar/github-dev-token-steal-poc/tre...

We can try to just put a `my-extension/extension.js` for the most direct execution but the CSP blocks that. It's only a script-src CSP blocking it though, so fetching the package.json is still kosher. So we end up using it to contribute a keybinding instead.

pier257 hours ago

The MSRC situation is really unbelievable.

There are probably better sources but I think this video by The Primeagen is a good introduction.

https://www.youtube.com/watch?v=9kxx5xp5nTQ

parable3 hours ago

Kudos for the public disclosure. Too many people haven't been happy with MSRC and it's starting to boil over (see the Nightmare Eclipse situation, too). Maybe all of these disclosures will cause them to do some introspection and realize they're the problem. I highly doubt that, but one can dream.

nicce3 hours ago

I am not sure if this is still the best approach. They did not even try to submit based on expected "low" ranking when comparing to existing XSS submission. They should at least try or let them know many days before disclosing. You never know.

imron2 hours ago

I love vanilla vim.

october81407 hours ago

If you like VSCode but don't like Microsoft, try Zed (zed.dev).

arianvanp3 hours ago

Zed downloads random binaries on startup without any permissions prompts. No thanks.

ffemac3 hours ago

I looked into Zed because popular harness (OpenCode/KiloCode) just random downloads npm packages in the background and didn't tell you. But then I found out reports of Zed doing the same. Why we can't have nice things?

Quothling5 hours ago

I heard that Zed came with a lot of integrated AI and team sharing features that phone home, so that's an issue for anyone working with stuff like NIS2 compliance. Not that VSCode isn't a compliance nightmare as well.

ZeroCool2u6 hours ago

Zed is excellent. I know it's weird, but the last thing holding me back is being able to have a browser based Zed session the same as VSCode.

dddw5 hours ago

If you like vs. but not M$. Use VsCodium. I did, but now preffer zed, which replaced my use of vscodium and sublimetext in 1 swoop.

ThanosAkr4 hours ago

I am a bit confused. What if I just revoked OAuth access to github.dev? Wouldn't that just make the token unusable?

antimony516 hours ago

> if you had some other XSS in a webview that you can get a victim to open, you get effectively full RCE on their computer.

Github creds or the computer, can't decide which one is worse.

selectively5 hours ago

Very unethical behavior combined by very bad security posture from the vendor. Bad.

fg1377 hours ago

> To those folks, I am sorry, but this is one of the few levers I have to try to influence MSRC and the security posture of VSCode

Someone is going to be blacklisted by Microsoft.

theguidessuck3 hours ago

Damn, what a disaster. Then they won't allow him to tell them about the bugs they don't take seriously.

ares6236 hours ago

"Oh great Mythos, how do I remove all vulnerabilities from my products?"

Percolating...

Ban all vulnerability researchers

NagatoYuzuru7 hours ago

[flagged]

Asfand30992 hours ago

[dead]

lavaman1315 hours ago

[dead]

vladsiu6 hours ago

[dead]

omelas_tech3 hours ago

tl;dr: never press github.dev or open vscode.dev on a repo you don't trust

15190351614 hours ago

[dead]