-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SHA1 -> SHA256 #816
Comments
it's worth noting that SHA1 is achievable in POSIX, but SHA256 is much harder to make work cross-platform. |
Just need to use PowerShell everywhere, it has it built-in ( Node's crypto library supports SHA256, I think we'd use that. > var crypto = require('crypto')
undefined
> crypto.createHash('sha256').update('Hello World').digest('hex');
'a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e' |
Looks like there's three hashing functions in the codebase: "hash" in src/util/misc, uses SHA256
|
Thanks for the issue! The shasums we use are given to us by the npm registry so there's not much we can do about this unfortunately. 😢 |
@kittens - Can we compute our own hash once the file has been downloaded, and store that in the local cache? |
might as well jump straight to SHA3 |
Now it is time to reconsider the issue.
Maybe sha2/3 could be an additional field? |
It looks like "hash" in src/utils/misc.js is gone now, and I can only see md5 used in:
and https://github.com/yarnpkg/yarn/blob/master/src/util/git.js#L35 |
looks like it would be safe to change the default to sha256. I'm not sure where the yarn.lock tgz hash files are checked though. |
They are checked here
https://github.com/yarnpkg/yarn/blob/master/src/fetchers/tarball-fetcher.js#L93
…On 6 March 2017 at 19:52, Thomas Grainger ***@***.***> wrote:
looks like it would be safe to change the default to sha256. I'm not sure
where the yarn.lock tgz hash files are checked though.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#816 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACBdWHfTuPDdCEu9aZWWqPJm5IU5uJpIks5rjGPqgaJpZM4KUafq>
.
|
@bestander where is the value from the yarn.lock file passed in? |
IIRC it is hash argument in the fetch method https://github.com/yarnpkg/yarn/blob/master/src/fetchers/tarball-fetcher.js#L20 |
Hi y'all. Just dropping in to point out that the npm registry has started serving more secure hashes with packages that have been published with it. You'll find the new hashes in the On the publishing side, you should continue generating Right now, the registry only supports lmk if y'all have any questions! It's exciting to start moving on from sha1 and setting ourselves up for a smoother transition to sha3 and beyond :) edit: p.s. I saw something about generating these from the command line. If you're relying on |
Thanks for commenting this, @zkat, very much appreciated! |
Afaik this is not a large change to do now, so a PR with a fix is welcome |
@bestander Is this still open? I would love to give it a shot :) -- Also, I hope I'm not asking for too much, but can you give me an idea on how I should get started? |
@nikshepsvn yes it is, give it a go. A good start would be to check where Yarn checks hashes, for example https://github.com/yarnpkg/yarn/blob/master/src/fetchers/tarball-fetcher.js#L83. |
@bestander Thank you so much, I'll do my best to understand as much as I can and get back to you with any questions -- is that okay? |
Sure, no problem.
…On 24 August 2017 at 10:41, Nikshep Svn ***@***.***> wrote:
@bestander <https://github.com/bestander> Thank you so much, I'll do my
best to understand as much as I can and get back to you with any questions
-- is that okay?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#816 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACBdWKgBwTlq8msPvHPt3SPqwOWBF8Wsks5sbbWzgaJpZM4KUafq>
.
|
Currently NPM has SHA-512 for new packages and SHA-1 for old ones. |
Well someone send us a PR |
@BYK - So, my reasoning goes like this. The pros of having the integrity field as a string are:
The cons are:
Regarding the cons:
In my opinion, the pros outweigh the cons here. But I will of course defer to your judgement if you disagree. :) |
@imsnif I understand where you are coming from and thanks for sharing the relevant specs which helped me see a clearer picture. That said, the only reason for the large string blob concatenated with spaces seems to be the restrictions in HTML (you cannot have the same attribute name more than once in an element so when you need to express an array you either need children, which is not possible with every tag, or need a serialization method). These are indeed a list of hash specs. If you ask me, we should denormalize this data, even more, to make it explicit which part is the hash-specifier and which part is the hash itself. I don't see any value in doing another pass of string parsing where we already have a string format data supports lists and objects. I haven't been a part of package-lock.json file format so I cannot comment on how or why they made the decision to use a single string blob for this field but I do not see a good reason to store serialized data in an already serialized data format. @zkat - is it possible for you to provide the reasons why you have chosen to use this field as a string blob instead of a JSON array? |
To contradict myself, URLs themselves are serialized string blobs in an already serialized data format here but when it comes to lists, I think this makes a significant improvement in terms of reviewing changes in the lockfile. Does that make sense? :) |
@BYK - alright, I understand the reasoning. Thanks for taking the time to explain it. @zkat - I too would be very interested in hearing your reasoning, if you'd be willing. Otherwise though, I'll continue working on this (I've got some other issues to get through, so this won't block me for now). For the time being though, just to make sure, our agreed solution is @zkat's suggestion:
right? |
Or, rather:
|
@imsnif yup :) |
what's the behavior with two different sha1s? |
what's the behavior if the sha1 matches but the sha512 does not match? |
@graingert - You raise valid and important questions, whose answers I plan to articulate with tests. So would it be fine if we go into the details after I submit the PR? I think it'll be much easier. :) |
The reason for having had a string was purely to be close to the actual SRI spec. That is, providing them as single, whitespace-separated strings. I can see npm bumping the lockfileVersion in the future for the sake of making it an array, but it'll be a long time before it starts making any real impact on diffs at all. While in theory there can be a bunch of stuff in that integrity field, in practice, it's almost always going to be a single entry (until we start upgrading algorithms or using more advanced options). The idea that it would significantly affect diffs didn't really cross my mind, cause it's a relatively stable field: if you get a diff, you'll likely get a diff for the entire entry, so you won't get individual lines for each hash anyway. As far as ordering goes: I may have misspoken here as far as whether ordering within an algorithm matters. I think it's actually fine because individual hashes within an algorithm will just be tried until one succeeds. When you have multiple algorithms, though, for security reasons, you must always use the strongest one that you know you can use. So if you have sha512 and sha1, you must always use sha512 and never, ever fall back to sha1. OTOH, if you see a sha3 and sha1, and you're on a version of Yarn that does not support sha3, you can use sha1. This is a future-proofing feature. You'll notice that ssri does its own algorithm ordering, and it's fairly conservative about it (again, for security reasons). |
@BYK - slight hitch with the array approach. It is not backward compatible. Issuing the
Results in:
If I am not mistaken, this is because the current lockfile format does not support arrays. So seeing as we cannot use arrays (unless I'm missing something with the above? please do correct me as I'm fairly new to the codebase and could be overlooking something!) Edit: |
Like I said above: you can totally get away with strings until such a time when you're ready for the breaking change. |
@imsnif that's a bummer, for some reason I thought arrays were possible in the lockfile. Alright, let's go with the sting and see how bad it hurts. I don't like this but the only alternative without a breaking change seems to treat arrays as objects with numeric indexes which would both make the lockfile ( |
Has there been any progress on this? Given the strong security promises on the website, it is very disappointing to see SHA-1 checksums in use. |
Now that that PR has been merged, should this issue be closed? The only missing piece now is that some dependencies (e.g. those installed from git repositories) still don't have an |
npm has not been generating integrity hashes for git dependencies for a while, because git packages can often change hashes unless devs are careful to make builds reproducible. |
|
Perhaps it would be worth using SHA1DC as a dropin replacement? |
Closing since SHA256 support has been released more than a year ago 🙂 |
@arcanis how did this manage to get left open for so long in "high-priority" when it was already fixed? |
I have done a quick check but it looks like Yarn is using SHA1 for checksumming?
If so, I think it would be a good time to switch to SHA256.
The text was updated successfully, but these errors were encountered: