18 ms·
The Python Package Index is now a GitHub secret scanning integrator
- natemcintosh 6y agoCan someone explain what exactly this means?
- nautilus12 6y agoI presume it means that if someone accidentally pushes up a token to a public github repo then it can't be used to hijack all the PyPi packages corresponding to that token to become malicious
- stevekemp 6y agoIf you commit your AWS secrets/tokens, or similar, inside a python script it will now be discovered by github automatically. They have integrations with a bunch of services to recognize the tokens, and disable them. This means malicious users can't copy/paste them, spin up servers and leave you with a big bill. (Ideally, of course it could still happen, but the aim is to prevent that kind of thing.)
- JosephRedfern 6y agoThough this has been true for a while, it's not what this announcement is about. This is specifically announcing automated scanning and reporting of PyPI keys, which if exposed, could allow a bad actor to distribute compromised Python packages via PyPi (e.g. pip)
- russfink 6y agoAnd this is a potentially huge security issue. Think about all the systems software that relies on Python packages.
- geofft 6y agoIf you accidentally commit your PyPI private token to git and push it to GitHub, PyPI will detect this and disable the token within seconds (because there are absolutely bots who will try to find it and abuse it).
- eecc 6y ago> From today, GitHub will scan every commit to a public repository for exposed PyPI API tokens. We will forward any tokens we find to PyPI, who will automatically disable them and notify their owners.
- deleted 6y ago[deleted]
- prepend 6y agoIt should reduce the possibility of pypi packages being taken over as the result of its owner being careless with theirs pypi credentials. I think it’s good because the risk of a package being taken over is low, but very damaging if it occurs in a widely used package.
- bombcar 6y agoThe API keys I’ve used (admittedly not many) all seem to be long random text strings - how does GitHub detect them? By then being used (ie in api code) or do they actually have a known format?
- Deathmax 6y agoGitHub documents the process over at https://docs.github.com/en/developers/overview/secret-scanning https://docs.github.com/en/developers/overview/secret-scanni.... You specify a regex, and you check if the secret is valid on your end.
- monkeybutton 6y agoThere must be an astounding number of false positives for common patterns like N-length string of base64 chars. Could someone upload a malicious file with millions of matching strings and watch Github DDoS a company's verification endpoint?
- neurostimulant 6y agoI imagine the scanning would be rate-limited on per-repo basis.
- monkeybutton 6y agoYeah, that would be reasonable.
- lostcolony 6y agoProbably also a max false positive rate; this isn't a guarantee, just a service, so if it detects X false positives it could just exclude the repo entirely as problematic.
- michaelcampbell 6y ago"Now you have 2 problems."
- 6y ago
- loloquwowndueo 6y agoWow today I learned this acronym. PyPI -> python package index, after using python for over a decade. Thanks!
- mschulkind 6y agoJust don't confuse it with PyPy, which is entirely different...
- daviddavis 6y agoAnd don't pronounce PyPI as pie-pie. It's pie-P-I.
- dec0dedab0de 6y agoit was much easier when it was just called the cheese shop
- lostcolony 6y agoAh. The fat detective.
- fredley 6y agoThat's why you pronounce it "Cheese Shop"
- kspacewalk2 6y agoPronounced pie-pee-aye, and not pee-pee, pie-pee or any of the other ways I heard it pronounced at work :)
- verall 6y agoBased on my workplace, I'm pretty sure it's "pee-pee". Just like 'Qt' is "cue-tee". There's no winning these battles..
- 6y ago
- amichal 6y agoThese secret scanning integrations have been very helpful. We had a client ask to take a project open source recently that had started a few years ago as closed source. We of course checked over the current version of the code and have had linters in place to look for secrets for a while but not in the very early days of the project. In that one codebase we had: - AWS IAM token for S3 upload access to a throwaway dev bucket. The bucket had already been deleted but still... Got an email about it informing me the IAM token had been revoked by AWS within 5 minutes - A Slack webhook notification URL/secret. Committed as a example on a working branch and then git rm'ed but still active. Got an email about it and token revoked by Slack automatically within 5 minutes. - A Mapbox API token. This one was funny. The token was indeed in there and functional but was in the docs/sample code for a dependency. Still, we got an email within the hour about it and were able to investigate. Edit: In this case we intentionally kept the commit history. A safer alternative (and one we normally practice) is to start a fresh repo for the open source variant.
- ed25519FUUU 6y agoAn overlooked vector is old commits. It’s often times better to squash all commits before taking a project open source, which is a real shame for obvious reasons. Commit histories can spill a lot of secrets that are easy to overlook.
- _the_inflator 6y agoAbsolutely this! Same problem here with inner source, that goes open source. I feel sorry for all our internal committers, however I know of "secrets", that went into the commit history. We are still considering our option, but tend to opt for deleting our commit history entirely and build a wall of fame for the former committers.
- psanford 6y agoThere are tools available to help look for this sort of thing (for both you and any potential attackers). TruffleHog[1] is the first one that comes to mind for me. I also like shhgit[2] for looking for secrets in repositories. (I don't think shhgit will look back in the git history for you though). [1]: https://github.com/dxa4481/truffleHog https://github.com/dxa4481/truffleHog [2]: https://github.com/eth0izzle/shhgit https://github.com/eth0izzle/shhgit
- dthul 6y agoI was seriously impressed when a few days ago I accidentally pushed my secret Discord bot token to Github and literally one second later I received a Discord message and an email letting me know that I leaked my token and that they deactivated it.
- cpcallen 6y agoThe headline sounds insidious (How dare PyPI and GitHub secretly scan me! I'm glad someone has revealed this dastardly collusion!) but it turns out they're actually doing something great.
- zitterbewegung 6y agoNaming things is the hardest thing to do in computer science.
- cbm-vic-20 6y agoThat, and cache invalidation.
- teraku 6y agoThat, and off-by-one errors
- airstrike 6y agoThere are actually only two hard problems in computer science: 0) Cache invalidation 1) Naming things 5) Asynchronous callbacks 2) Off-by-one errors 3) Scope creep 6) Bounds checking
- macksd 6y ago7) Project estimation
- DonHopkins 6y ago-1) Keeping secrets
- weeboid 6y agoLuckily, building better garbage collectors is easy: ref pointers to each cons
- RocketSyntax 6y agowould love to see tighter integration with some GitHub Secret/ Action publishing
- di 6y agoNot sure if this is what you're asking for, but the PyPA does maintain a GitHub Action for publishing to PyPI as well: https://github.com/pypa/gh-action-pypi-publish https://github.com/pypa/gh-action-pypi-publish
- linkdd 6y agoGreat news! IMHO, Github should make it mandatory for integrated services to provide this feature.
- brian_herman 6y agoThis is great hopefully we will get GitHub packages support for python soon. https://github.com/features/packages https://github.com/features/packages
- luhn 6y agoIt's on their public roadmap: https://github.com/github/roadmap/issues/94 https://github.com/github/roadmap/issues/94 Unfortunately it's marked as "Future," so it's still a ways out.
- Kaimunchi 6y agoLook into this software for device management sclera VDMS - https://youtu.be/0_7V3lECy_s https://youtu.be/0_7V3lECy_s
- melson 6y agogood one
- einpoklum 6y agoAs a non-Python person: Is it an easy mistake to make, for someone to inadvertently commit and push a "secret PyPI token"?
- macintux 6y agoSecrets in general leak into source code all the time, nothing specific about PyPI.
- hannasanarion 6y agoIf you are trying to publish your package for other people to download through the `pip` package manager, then yeah. Most python devs will probably never publish to PyPi, but this can save some headaches for those who do, especially for the first time.
- klyrs 6y agoI can certainly imagine putting a token into a deploy script in the same directory as a python package's repo. From there, it's a typo away from getting added and committed to the repo. So, it's better to keep those tokens elsewhere.
- einpoklum 6y agoIsn't it totally verboten to put secret tokens / passwords into scripts? Regardless of language? When I write, say, bash scripts which do work using ssh, I don't specify a password: The user running the script will provide their own manually, or use ssh-copy-id, or edit the authorized_keys file on the target machine if they want to save themselves some typing. That is - authentication is decoupled from my script's actual work. Why is that not how things work with PyPI?
- progval 6y agoIt is. But even if it is strongly discouraged, some people will commit it anyway. Look at any beginner's repository, there is a high chance it contains files compiled from the source of the repo (executable, .pyc, ...), the developer's IDE config (.vscode, ...), __MACOSX, ...
- leot 6y ago> to help keep their customers safe The elimination of a distinction between “safety” and “security” is unhealthy imo, as it leads to a failure to distinguish between unintentional harm caused by nature, and intentional harm caused by other people. E.g. “safety first” is only intelligible if it doesn’t also prevent you from trusting anyone (which is what would be implied by “security first” as a general priority).
- hannasanarion 6y agoDo you lock your doors?
- leot 6y agoSometimes. But I can’t say that I have a “security first” mindset, which seems analogous to “trust no one”.
- dragonwriter 6y agoI think you misunderstand what “X first” normally means, it means “X is most heavily weighted” not “the smallest condideration in domain X outweighs all other considerations in all other domains”.
- remram 6y agoFYI pypi tokens look like pypi-9NX39cdNn0AH1cCl1bMT48eKzf4Rhvw1mipk1FZTPrpR9 The integration means that GitHub knows to recognize this format, and calls some API of pypi.org when it finds one so PyPI can revoke it. As always, please allow me to lament that we don't have a standard for this, such as secret-token:pypi.org/9NX39cdNn0AH1cCl1bMT48eKzf4Rhvw1mipk1FZTPrpR9, which would let any system know that this string is a secret and that pypi.org should be notified (for example via POST pypi.org/.well-know/compromised-secret). See also https://news.ycombinator.com/item?id=25978185 https://news.ycombinator.com/item?id=25978185
- nindalf 6y agoAccording to the documentation (https://docs.github.com/en/developers/overview/secret-scanning https://docs.github.com/en/developers/overview/secret-scanni...), secret issuers specify a regex that can detect secrets they've issued. "Be as precise as possible, because this will reduce the number of false positives" - that's the guideline from GitHub. Github runs the regex on every commit that is uploaded and informs the secret provider when a match occurs.
- kevincox 6y agoI wonder if false-positives often result in GitHub sending secrets to the wrong service.
- danudey 6y agoI wonder if any of those services have a combination of bad regexes and bad validation and could be SQL injected by committing a malicious faux-token to GitHub.
- remram 6y agoI see that they document the alerting endpoint there. The only piece missing is building the URL from the token format. I hope we get there someday, and everyone can deploy this without having to replicate GitHub's registry of token formats. This page also mentions that they "strongly recommend you implement signature validation in your secret alert service", but I'm not sure why. Isn't the fact that they send valid tokens proof that they have really found a leak?
- deleted 6y ago[deleted]
- sneak 6y agoThis is some epic-level brand building in action. Pretty soon, people just entering our industry will mistakenly believe that GitHub's ownership (Microsoft) wants open source to exist and thrive.
- seanwilson 6y agoDo any APIs standardise on a simple secret key pattern that can be easily identified as a secret? For example, all secrets have a "secret-" prefix? Or is this idea unworkable? I usually try and prefix e.g. fields in config files with "secret" to make it obvious they shouldn't be committed.
- csnover 6y agoThere was a discussion a while ago about IETF RFC 8959 which proposes a secret-token URI that might be of interest: https://news.ycombinator.com/item?id=25978185 https://news.ycombinator.com/item?id=25978185
- soheil 6y agoThis makes me wonder if Github should do basic code sanity checks on every repo. Things like checking for division by zero, infinite-loops, etc. They'd have to be very conservative checks as to not trigger false positives. But if there is benefit in secret scanning for all public repos there must be benefit in detecting other types of programmer mistakes.
- leblancfg 6y agoThey acquired LGTM (https://github.com/marketplace/lgtm https://github.com/marketplace/lgtm) not too long ago, so expect this to happen.
- molticrystal 6y agoThey got a decent list of partnered companies which you can find over here: https://docs.github.com/en/code-security/secret-security/about-secret-scanning https://docs.github.com/en/code-security/secret-security/abo... Glad they got our back.
- simonw 6y agoIn case anyone is interested, it looks like this is the implementation on the PyPI side: https://github.com/pypa/warehouse/pull/8563 https://github.com/pypa/warehouse/pull/8563
- danudey 6y ago> Fixes #6051 > See #7124 reverted in #8555 due to #8554 which is addressed in #8562 (pfew...) > Should not be merged before #8562: EDIT: > > Re-revert of the code. The bug that caused revert was splitted into #8562 Software development in a nutshell, everyone.
- z77dj3kl 6y agoIs there some best practice on creating a format for secret keys? If I create an API with secret keys, should I make them something like z77dj3kl-secret-pk-[secret-stuff]? Is there an argument (security by obscurity?) that that makes it easier to spot it and abuse it? Or would it be better to encode it in the secret bits somehow, add 16 control bits that have known values?
- theoretick 6y agoFWIW There's a new RFC for specifying a URI scheme: https://tools.ietf.org/html/rfc8959 https://tools.ietf.org/html/rfc8959
- akhilpotla 6y agoIt would be nice instead if the git command prevented you from committing a file with a token in it.
- crescentfresh 6y agoHaven't seen it mentioned here and it's not specifically mentioned in their docs where they explain about secret scanning: github also does secret scanning on all public gists. Seeing as how every gist is just a repository under the hood it makes sense. I've seen devs share a snippet of code with an AWS Access Key Id/Secret in it using gists and we immediately got a notice from Amazon about that key being compromised.
- pabs3 6y agoAre the regexes behind the GitHub secret scanning open source? It would be great to check my code that isn't on GitHub.