News for hackers. Stuff that matters.
Re:What will happen when you commit secrets to a public Git ... by greysteil on Saturday November 07, 2020 @03:36AM (#25013848)
Cool experiment!

I PM the secret scanning team at GitHub and wanted to mention what GitHub did behind the scenes here. GitHub scans every commit to a public repo for secrets one of our secret scanning partners may have issued. We forward those candidate secrets to the issuing partner, and they take action. In some cases they auto-revoke the secret (AWS normally does this, I believe), in some cases they notify the user, and in some cases the response is configurable.

I checked that GitHub detects these tokens myself - within 1 second of the commit GitHub had notified AWS and Slack of the leak. AWS and Slack will then have taken action and informed the token owner, which in this case is Thinkst Canary, rather than Andrezj (the OP). I believe AWS normally auto-revoke, but they may have a custom setup with Thinkst Canary's tokens that allows Thinkst to continue to monitor them even once compromised.

Finally, GitHub actually delays the indexing of our search by a couple of seconds to ensure that, for normal cases, our secret scanning partners have time to take action before anyone else can find the tokens.

We're always looking to make secret scanning at GitHub better, so feedback as always welcome. It's also fascinating (and validating!) to see what happens to exposed tokens.

* List of GitHub secret scanning partners: https://docs.github.com/en/free-pro-team@latest/github/admin...

* Thnkst Canary tokens: https://www.canarytokens.org/

Re:What will happen when you commit secrets to a public Git ... by the_duke on Saturday November 07, 2020 @06:41AM (#25014524)
Couldn't auto-revokation be used for a "DOS" attack of sorts by generating a lot of randomized tokens and pushing them to any repo?

I realize that the search space is huge for many tokens types, but it seems viable.

Re:What will happen when you commit secrets to a public Git ... by thdrdt on Saturday November 07, 2020 @06:44AM (#25014540)
Selecting (reading) data is very fast most of the time. So if no token matches I don't think this will result in a DOS.
Re:What will happen when you commit secrets to a public Git ... by spydum on Saturday November 07, 2020 @07:02AM (#25014601)
I think they meant it would autoinvalidate the tokens which might be valid. I think the math on an AWS secret and access key would be ridiculous to brute force.. but other types of keys might be an interesting attack vector.
Re:What will happen when you commit secrets to a public Git ... by OJFord on Saturday November 07, 2020 @10:11AM (#25015482)
If you were guessing valid tokens why would DoSing be more valuable to you than use of the token?
Re:What will happen when you commit secrets to a public Git ... by chaorace on Sunday November 08, 2020 @12:28AM (#25023291)
Bypassing rate limits and amplification, presumably. Just generate a huge list of keys and push once to attack many services at once with the whole set.
Re:What will happen when you commit secrets to a public Git ... by gingerlime on Saturday November 07, 2020 @08:03AM (#25014834)
what about the birthday paradox however? i.e. the attacker doesn’t need to brute force a specific key, but just any key... I guess for AWS the search space is still huge enough for it not to be a problem still (but didn’t do the math)
Re:What will happen when you commit secrets to a public Git ... by time0ut on Saturday November 07, 2020 @09:14AM (#25015170)
I believe AWS secrets are 240 bits. That is a pretty massive space. I don't know how many active secrets are out there, but I think someone would need to get very lucky to collide before the attack was noticed and stopped.

Other partner's secrets may be more susceptible.

Edit: I did not consider the paired access key which is another 70 or so bits. I think you'd need to collide on both to make someone have a bad day.

Re:What will happen when you commit secrets to a public Git ... by remram on Saturday November 07, 2020 @11:27AM (#25015984)
You need to guess both to use them, but you only need to guess the secret to get it revoked. GitHub does not check that the corresponding access key is somewhere in the repo too before taking action. You are right about this being impractical though.
Re:What will happen when you commit secrets to a public Git ... by time0ut on Saturday November 07, 2020 @11:58AM (#25016257)
Ah ok. I wasn't sure how that part worked.
Re:What will happen when you commit secrets to a public Git ... by Hello71 on Saturday November 07, 2020 @09:08AM (#25015145)
seems like you could just log in directly at that rate
Re:What will happen when you commit secrets to a public Git ... by the_duke on Saturday November 07, 2020 @07:50AM (#25014781)
As spydium suggests in a sibling comment, I was not referring to overwhelming Github infrastructure but to mass invalidation of guessed tokens.
Re:What will happen when you commit secrets to a public Git ... by benburleson on Saturday November 07, 2020 @07:54AM (#25014797)
If you can guess keys and secrets, you probably wouldn't use that power to invalidate them!
Re:What will happen when you commit secrets to a public Git ... by delecti on Saturday November 07, 2020 @08:53AM (#25015073)
I suspect this is relying more on a "birthday paradox" approach. The goal wouldn't be to invalidate a particular secret, but rather that with a relatively small number of randomly generated secrets, you would be taking advantage of this setup to invalidate at least some.
Re:What will happen when you commit secrets to a public Git ... by chmod775 on Saturday November 07, 2020 @09:47AM (#25015344)
The point still stands: If you could do that, you would use them, not invalidate them.
Re:What will happen when you commit secrets to a public Git ... by the_duke on Saturday November 07, 2020 @10:12AM (#25015486)
Trying to use millions of generated tokens is not really feasible. Most services will throttle or block you quickly. Also often you would need to know the permissions the token has to get any access.

Writing millions of generated tokens to a text file and pushing them to Github is easy.

There is obviously no meaningful benefit to doing this, except potentially breaking some random deployments until they can replace the keys.

Re:What will happen when you commit secrets to a public Git ... by tobr on Saturday November 07, 2020 @03:47AM (#25013890)
Why not refuse to publish a detected secret at all until the repo owner takes an action to allow it?
Re:What will happen when you commit secrets to a public Git ... by greysteil on Saturday November 07, 2020 @04:17AM (#25014018)
There are a few considerations on that one, but one very practical reason is the developer experience of dealing with false positives.

False positives are one of the big problems in secret scanning. Some partners issue credentials with patterns that make them very hard to distinguish from innocuous strings. For example, a Datadog token looks identical to a commit SHA. We would never block developers from pushing commits to GitHub just because they had 40 character hexadecimal strings in them!

GitHub's partnership approach works around the false positive problem by having the token issuer check whether a token is real and take action only if it is. However, this is a one-way communication from GitHub - the token issuer doesn't need to tell us whether the candidate secret we sent them was real or not, and in most cases we never know.

As a result, we can't replicate the zero false positive experience in a pre-receive hook (i.e., before the commit is pushed to GitHub). There would also be performance considerations from making 30+ http requests as part of a pre-receive hook.

In future, we are looking at creating a pre-receive hook solution that focuses on patterns that have a very low false positive rate. There are already some open source solutions that do this (links below) - in fact the OP linked to one from his Twitter thread. If/when GitHub offer is, it will definitely be opt-in, rather than opt-out!

* https://github.com/thoughtworks/talisman/

* https://github.com/awslabs/git-secrets

Re:What will happen when you commit secrets to a public Git ... by 0xad on Saturday November 07, 2020 @06:09AM (#25014424)
Cool! Thanks for explanation.
Re:What will happen when you commit secrets to a public Git ... by watt on Saturday November 07, 2020 @04:06AM (#25013968)
Think about it in terms of incentives and nudges.
Re:What will happen when you commit secrets to a public Git ... by 0xad on Saturday November 07, 2020 @03:44AM (#25013876)
Awesome, thanks for the background information!
Re:What will happen when you commit secrets to a public Git ... by dorfsmay on Saturday November 07, 2020 @08:58AM (#25015101)
Do you also scan when a private repo is changed to public?
Re:What will happen when you commit secrets to a public Git ... by greysteil on Saturday November 07, 2020 @09:25AM (#25015225)
I think so, and we 100% should do, but I just did a test and the secret I committed was still working a full minute after I converted the repo. Could be that the scan was in a queue, could be that it didn't trigger.

I'll dig into it and make sure this is working and is fast - it's a critical time to do a full scan of the repo's git history.

Re:What will happen when you commit secrets to a public Git ... by OJFord on Saturday November 07, 2020 @10:13AM (#25015491)
So scanning is only done on public repos?
Re:What will happen when you commit secrets to a public Git ... by mackenzie-gg on Monday November 09, 2020 @04:21AM (#25032938)
GitGuardian scans on every event, this includes a public event (when a Repo is made public) and will alert if secrets are found within.
Re:What will happen when you commit secrets to a public Git ... by jakub_g on Saturday November 07, 2020 @08:04AM (#25014840)
Why secret scanning is enabled only for public repos but not for private ones?
Re:What will happen when you commit secrets to a public Git ... by greysteil on Saturday November 07, 2020 @09:05AM (#25015133)
Private repos need a different approach, but committing secrets to them can still be a problem.

If a secret is committed to a private repo then anyone with read access to that repo could use it. That might give those users more permissions than they're supposed to have. It's particularly a problem in large organisations, where thousands of developers may have access to a private repo, but should not necessarily have direct access to production infrastructure.

That said, the risk tradeoff when a secret is found in a private repo is different to when one is found in a public repo. If it's a personal private repo that no-one else has access to, the risk may be limited. If it's a corporate repo with hundreds of contributors, someone almost certainly wants to be aware of it. Even then, each organisation will want to respond in different ways, perhaps depending on who has access to the repo, and what access the leaked secret granted.

I'd be remiss not to say that GitHub has a beta offering for private repo secret scanning that we launched in May. It's a paid feature, targeted at large, security-conscious organisations, that scans your git history and each new commit for secrets and displays them in the GitHub UI.

Re:What will happen when you commit secrets to a public Git ... by jakub_g on Saturday November 07, 2020 @10:22AM (#25015551)
Re:What will happen when you commit secrets to a public Git ... by Lex-2008 on Saturday November 07, 2020 @08:24AM (#25014928)
Because it should be OK to commit secrets to private repos - that's why they're _private_, after all, right?
Re:What will happen when you commit secrets to a public Git ... by dorfsmay on Saturday November 07, 2020 @09:07AM (#25015141)
No, that's not not why.

If you have secrets, encrypt them.

Private repos can be turned public, intentionally or by mistake. Repos can be exported to give software to third parties. Also, git users clone repos, which means that those secrets are copied every where. Can you make sure those stay private too? Do you make your developers encrypt their laptops or delete repos from them before they leave their house or office?

Re:What will happen when you commit secrets to a public Git ... by jakub_g on Saturday November 07, 2020 @10:26AM (#25015576)
Also, it's possible that when you have a secret in a private repo, it accidentally leaks when you deploy that repo to a public server. And it's easier to do this than you'd think, e.g. by a mix of a few unrelated changes by different developers.

Also, when an attacker gets access to one private repo by some means, you don't want him to pwn your whole organization.

Re:What will happen when you commit secrets to a public Git ... by amelius on Saturday November 07, 2020 @08:34AM (#25014974)
I suppose you could still XOR your secret S with a random bitstring B, then commit both S^B and B. Am I missing something?