Compromising the integrity of the npm registry.
Recently it was disclosed that the NPM registry leaked the usernames, salts and sha1 hashes of registry users. Essentially this amounts to a breach of about 4k user accounts.
The issue has since been taken care of and users are being asked (not forced) to change their passwords. The leaked data has been available for a very long time, probably since the registry has been using couch. Everyone should be resetting their passwords. Now.
I first found out and notified Isaac about this on 3/1/2012. I only found out about this because I was looking for potential ways that &! could be compromised.
One of the ways we build our development and production environments is by using npm to install packages. I was curious just how hard it would be to compromise the integrity of packages published to the registry, turns out not very. It’s great to point out however that npm is meant to be a distribution channel. It’s a free and open service in which anybody can distribute packages. It’s not meant to provide any level of integrity and quality checking. As developers we are responsible for the code that executes in our environments. Maybe checking verified packages into your projects repository isn’t such a bad idea after all.
It took only 24 hours using an old spare machine to crack 25% of the passwords. Very little effort or CPU power.
Passwords cracked included prominent, well respected members of the node.js community that control publishing rights to widely used packages.
To be clear, this was not done for the sake of gaining access to those passwords and the data has been destroyed and I never tried to log in with any account. It was just a test of how hard it would be to abuse it and thus, what level of actual threat it represented.
There are some great comments on if this was a couch problem or a npm problem in this thread.
During that time I also discovered a number of persistent and reflected cross-site scripting vulnerabilities that were patched in this pull request.
Finally I would like to thank Isaac for taking the time to communicate with me over email about this, keep me updated as things progressed, and most importantly shipping a fix and being transparent with the node community.
I’m very interested in comments on this and appreciate feedback either via email (baldwin@andyet.net) or twitter @adam_baldwin
tl;dr
- Only 24 hours to crack 25% of the user passwords.
- It’s not required for you to reset your password, do so anyway.
- You are responsible for the code you run in production, not NPM.
- Serious thank you to @izs and @_jhs for shipping a fix & being transparent
filed under
node.js,
npm,
and
security
posted March 8, 2012 by Adam Baldwin
Devops and Security Vodcast: Code Quality & Helpful Tools
&yet’s ops and security guys hash it out in this latest vodcast.
Nathan Lafreniere talks about what’s in his devops toolkit, his code deployment process, how ops can help maintain code quality, and his new documentation library, ape.
Adam Baldwin discusses his new Node.js header security library for express, helmet, a few headers that most apps should be including by default now, and some random bits about realtime security.
Fortunately for you this particular cut doesn’t include Adam singing Russian Unicorn but it does feature a yeti and Adam doing what he would consider dancing.
Please let us know what you would like to hear about in the future regarding ops and security.
Credits:
“Talent”: Nathan (left) and @adam_baldwin (right).
Video filmed and produced by the awesome Ms. Mel.
filed under
devops,
node.js,
process,
qa,
security,
and
vodcast
posted February 17, 2012 by Adam Baldwin
Redis Reliability for Realtime Apps
The Problem
When I was at FOSDEM last weekend, I talked to several people who couldn’t believe that I would use Redis as a primary database in single page webapps. When mentioning that on Twitter, someone said, “Redis really only works if it’s acceptable to lose data after a crash.”
For starters, read http://redis.io/topics/persistence. What makes Redis different from other databases in terms of reliability is that a command can return “OK” before the data is written to disk (I’ll get to this). Beyond that, it is easy to take snapshots, compress append-only log files, configure fsync behavior in Redis. There are tests for dealing with disk access suddenly cut off while writing, and steps are taken to prevent this from causing corruption. In addition, you have `redis-check-aof` for dealing with log file corruption.
Note that because you have fine tuned control over how fsync works, you don’t have to rely on the operating system to make sure that operations are written to disk.
No Really, What Was the Problem Again?
Since commands fail in any database, client libraries wait for OKs, Errors, and Timeouts to deal with data reliability. Every database based application has to deal with the potential error. The difference is that we expect the pattern to be command-result based, when in fact, we can take a more asynchronous approach with Redis.
Asynchronous reliability
The real difference is that Redis will return an OK as long as it was written to RAM (see Antirez’s clarification in the comments) while other databases tend to send OK only after the data is written to disk. We can still get on par (and beyond) with other database reliability easily enough by having a very simple check that you may be doing anyway without realizing it. When sending any command or atomic group of commands to Redis in the context of a single page app, I always send some sort of `PUBLISH` at the end. This publish bubbles back up to update the user clients as well as inform any other interested party (separate cluster processes for example) about what is going on in the database application. If the client application lets the user know that it didn’t get an update corresponding with a user action within a certain amount of time, then we know the command didn’t complete. Beyond this, we can write to a Redis *master* and `LISTEN` for publishes on a Redis *slave*! Now the client application can know that the data has been saved on more than one server; that sounds pretty reliable to me.
Using this information, the client application can intelligently deal with user action reliability all the way to the slave, and inform users with a simple error, resubmit their action without prompting, or request that the server do some sort of reliability check (in or out of context of the user action), etc.
tl;dr
- Single page app sends a command
- Application server runs an atomic action on Redis *master*.
- Redis master syncs to Redis *slave*
- `PUBLISH` at the end of said atomic action routes to application server from Redis *slave*.
- `PUBLISH` routes to single page app that sent the command, and thus the client application knows that said atomic action succeeded on two servers.
- If the client application hasn’t heard a published confirmation, the client can deal with this as an error however it deems appropriate.
Further Thoughts
Data retention, reliability, scaling, and high availability are all related concepts, but not the same thing. This post specifically deals with data retention. There are existing strategies and efforts for the other related problems that aren’t covered in this post.
If data retention is your primary need from a database, I recommend giving Riak a look. I believe in picking your database based on your primary needs. With Riak, commands can wait for X number of servers in the cluster to agree on a result, and while we can do something similar on the application level with Redis, Riak comes with this baked in.
David Search commented while reviewing this post, “Most people don’t realize that a fsync doesn’t actually guarantee data is written these days either (depending on the disk type/hardware raid setup/etc).” This further strengthens the concept of confirming that data exists on multiple servers, either asynchronously as this blog post outlines, or synchronously like with Riak.
About Nathan Fritz
Nathan Fritz aka @fritzy works at &yet as the Chief Architect. He is currently working on a book called “Redis Theory and Patterns.”
If you’re building a single page app, keep in mind that &yet offers consulting, training and development services. Send Fritzy an email (nathan@andyet.net) and tell us what we can do to help.
Update: Comment From Antirez
Antirez chimed in the comments to correct this post.
“actually, it is much better than that ;)
Redis with AOF enabled returns OK only *after* the data was written on disk. Specifically (sometimes just transmitted to the OS via write() syscall, sometimes after also fsync() was called, depending on the configuration).
1) It returns OK when aof fsync mode is set to ‘no’, after the wirte(2) syscall is performed. But in this mode no fsync() is called.
2) It returns OK when aof fsync mode is set to ‘everysec’ (the default) after write(2) syscall is performed. With the exception of a really busy disk that has still a fsync operation pending after one seconds. In that case, it logs the incident on disk and forces the buffer to be flushed on disk blocking if at least another second passes and still the fsync is pending.
3) It returns OK both after write(2) and fsync(2) if the fsync mode is ‘always’, but in that setup it is extremely slow: only worth it for really special applications.
Redis persistence is not less reliable compared to other databases, it is actually more reliable in most of the cases because Redis writes in an append-only mode, so there are no crashed tables, no strange corruptions possible.”
filed under
architecture,
ops,
realtime,
and
redis
posted February 9, 2012 by Nathan Fritz
Adam Baldwin and Nathan LaFreniere are yetis.
Security expert and dev/ops badass join the &yet team January 1
Because we are huge fans of human namespace collisions and amazing people, we’re adding two new members to our team: Adam Baldwin and Nathan LaFreniere, both in transition from nGenuity, the security company Adam Baldwin co-founded and built into a well-respected consultancy that has advised the likes of GitHub, AirBNB, and LastPass on security.
We have relied on Adam and Nathan’s services through nGenuity to inform, improve, and check our development process, validating and invalidating our team’s work and process, providing education and correction along the way. We are thrilled to be able to bring these resources to bear with greater influence, while providing Adam Baldwin with the authority to improve areas in need of such.
Adam Baldwin
Adam Baldwin has served as &yet’s most essential advisor since our first year, providing me with confidence in venturing more into development as an addition to my initial web design freelance business, playing “panoptic debugger” when I struggled with it, helping us establish good policy and process as we built our team, improving our system operations, and always, always, bludgeoning us about the head regarding security.
It really can’t be expressed how much respect I and our team at &yet have for Adam and his work.
He’s uncovered Basecamp vulnerabilities that encouraged 37Signals to change their policies for handling reported vulnerabilities, found huge holes in Sprint/Verizon MiFi (that made for one of the most hilarious stories I’ve been a part of), published vulnerabilities *twice* to root Rackspace, shared research to uberhackers at DEFCON, and has provided security advice for a number of first-class web apps, including ones you’re using today and conceivably right now.
Adam Baldwin will be joining our team at &yet as CSO—it’s a double title: Chief of Software Operations and Chief Security Officer.
Adam will be adding his security consultancy, alongside &yet’s other consulting services, but will also be overseeing our team’s software processes, something he has informed, shaped, and helped externally verify since, I think, before most of our team was born.
On a personal note (a longer version of which is here), I must say it’s a real joy to be able to welcome one of my best friends into helping lead a business he helped build as much as anyone our team.
Nathan LaFreniere
As excited as I am personally to add Adam Baldwin, our dev team is even more thrilled about adding Nathan, whose services we have become well accustomed to relying on in our contract with nGenuity and in a large project where we’ve served a mutual customer.
Nathan is a multitalented dev/ops badass well-versed in automated deployment tools.
He solves operations problems with a combination of experience, innovation, and willingness to learn new tools and approaches.
He’s already gained a significant depth of experience building custom production systems for Node.js, including some tools we’ve come to rely on heavily for &bang.
Nathan’s passion for well-architected, smoothly running, and meticulously monitored servers has helped our developers sleep at night, very literally.
I know getting the luxury of having a huge amount of Nathan’s time at our developers disposal sounds to them like diving into a pool of soft kittens who don’t mind you diving on them and aren’t hurt at all by it either oh and they’re declawed and maybe wear dentures but took them out.
So that’s what we have for you today.
We think you’re gonna love it.
filed under
new hires,
ops,
and
security
posted December 16, 2011 by Adam Brault