You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you for this project. I really appreciate using it.
This issue is a feature request to add an integrity check for security reasons. In fact, even if there is the possibility to specify a Git tag to download a particular version of a pre-commit hook, it does not guaranty that the tag will point to the same commit between two downloads. Knowing that a Git hook is an executable, and that a Git tag can be modified to point to another commit, it becomes impossible to trust the hooks downloaded by pre-commit without reviewing them each time they are installed, which is a security risk. An attacker getting write access to a Git repository containing pre-commit hooks could add a harmful payload to them and make the latest tag point to this new malicious version for example.
To remediate this situation, I would suggest to add the commit ID as a new repos property to the configuration file, at the same imbrication-level as rev. This way, pre-commit will be able to verify that the Git tag specified by rev points to the expected Git commit.
I look forward to getting your feedback on it.
Cheers.
Reacted by Eric L. Frederich and kz-gonzalo-curbelo
there was consideration to make a "lock" file at some point but there has been no proposal or spec put forth. I can't find the original issue from a quick search -- I don't want to put it in the base configuration as it is highly prone to merge conflicts
rev doesn't have to point to a tag, you can already use a revision for that.
Great! Because all the pre-commit config files I have read so far used Git tags, I thought it was the only way to specify a version. It makes sense to me now that rev has been chosen for the name of this parameter, and not tag.
Is it also possible to specify a branch name? I think it would be worth adding a few words in the documentation to indicate what values this parameter can take, and why not a small paragraph about the security implications.
It used to be called sha but humans don't like reading shas and very much can't reason about them -- it can be a branch but the docs discourage this. I do think you're blowing security a bit out of proportion here, it's not any different than cloning a git repository from the internet or much different installing a package from say npm -- precisely why this feature hasn't been prioritized.
The value is meant to be immutable, but the framework currently doesn't care whether it actually is (you can put branches there or mutable tags all the same)
I completely agree that it should be discouraged. My point was that all the possible values should be clearly documented, preferably directly in the table where the different parameters are listed.
I do think you're blowing security a bit out of proportion here, it's not any different than cloning a git repository from the internet or much different installing a package from say npm -- precisely why this feature hasn't been prioritized.
Well, I agree that it's not a good thing to blindly use source code or install npm packages, specially knowing that those packages are not signed. However, it's not because people do it that it should be encouraged. Security issues occur regularly because of compromised dependencies.
The best way to know if a software is safe to be used is to read its source code. However, it is extremely time-consuming and not in everyone's reach. At some point, we need to trust someone else, and it makes generally sense to trust the developers of the project, hence the signing mechanism. That's why the only two ways I see to get a good balance between convenience and safety are either to use immutable references (commit IDs) after having read the source code of the pre-commit hooks, or to ask pre-commit to verify the signatures of the remote references (Git tags, commits, or branches).
I suppose the locking mechanism you mentioned is the way-to-go, in particular because most people don't sign their work. If you agree with me, I would be happy to work on the implementation as soon as I get a bit more of free time.
I'm not even sure a locking mechanism is necessary now that I think about it -- using rev: <40-char sha1> is essentially your lock.
It's what I thought initially but using a locking mechanism would be a way to detect drifts if your targeted Git tag has been changed to point to another commit since the last time you used pre-commit install.
I'm not even sure a locking mechanism is necessary now that I think about it -- using rev: <40-char sha1> is essentially your lock.
It's what I thought initially but using a locking mechanism would be a way to detect drifts if your targeted Git tag has been changed to point to another commit since the last time you used pre-commit install.
🤷♂ at that point who cares though -- you're just installing from a sha
Using a sha for the rev does work, the problem is that it breaks the autoupdate functionality.
I would propose supporting both rev and sha at the same time. Or instead of sha maybe lock?
pre-commit install-hooks should verify that the two point to the same place. pre-commit autoupdate should update based on the rev and place the new sha there as well at the time of the update. In the future if these two deviate, it'll be detected before the malicious code is ran.
If the user is using autoupdate, then they'll never have to touch the sha themselves.
I have looked at --bleeding-edge. This is not the behavior I would want. I'd do want to use a tag, for instance v2.4.0. I also want to be guaranteed that the code doesn't change out from under me if I clone and initialize the repo yesterday vs today.
As for the merge conflict issue, I don't see how having a sha along for the ride changes anything. You'd have a merge conflict on the sha in any scenario where you'd also have a a merge conflict on a rev
the ergonomics of a merge conflict are pretty important to me and I've seen them sour relationships with tools in the past, consider trying to resolve the following conflicts:
If you're paranoid (it seems you are) I'd suggest converting the shas manually until a reasonable proposal / implementation exists (as documented above)
@asottile I never suggested using a sha in place of a tag. Please re-read my posts. I even included examples. I'm suggesting to use them together at the same time.
This should not be a problem.
This config file won't be updated as often as other code. When it is modified, the majority of the time there will not be a merge conflict. This is because typically multiple people will not edit it at the same time. If they happen to, then you'd have to deal with it like any other merge conflict and not mix and match. Either take the rev and sha from one commit or the other. Just don't mix and match. This is what the diff would look like.
sha1 in the rev field plus a comment is equivalent without needing special fields - it wouldn't be too difficult to make autoupdate spit out that format
I just don't see the value in having two fields given the tag would be purely informational and the rev field already supports both (and the sha field is misnamed, deprecated, and forbidden when rev is present currently)
@asottile so having rev with a sha value and a tag comment? That is what I'm currently doing but it's a manual process. See previous comment showing how autoupdate currently handles this.
I always feel dirty putting data into comments. If the tool were able to update the comment too, that'd be better.
Activity
asottile commentedon Jun 28, 2019
rev doesn't have to point to a tag, you can already use a revision for that.
asottile commentedon Jun 28, 2019
there was consideration to make a "lock" file at some point but there has been no proposal or spec put forth. I can't find the original issue from a quick search -- I don't want to put it in the base configuration as it is highly prone to merge conflicts
SkypLabs commentedon Jun 29, 2019
Great! Because all the pre-commit config files I have read so far used Git tags, I thought it was the only way to specify a version. It makes sense to me now that
revhas been chosen for the name of this parameter, and nottag.Is it also possible to specify a branch name? I think it would be worth adding a few words in the documentation to indicate what values this parameter can take, and why not a small paragraph about the security implications.
asottile commentedon Jun 29, 2019
It used to be called
shabut humans don't like reading shas and very much can't reason about them -- it can be a branch but the docs discourage this. I do think you're blowing security a bit out of proportion here, it's not any different than cloning a git repository from the internet or much different installing a package from say npm -- precisely why this feature hasn't been prioritized.The value is meant to be immutable, but the framework currently doesn't care whether it actually is (you can put branches there or mutable tags all the same)
SkypLabs commentedon Jun 30, 2019
I completely agree that it should be discouraged. My point was that all the possible values should be clearly documented, preferably directly in the table where the different parameters are listed.
Well, I agree that it's not a good thing to blindly use source code or install npm packages, specially knowing that those packages are not signed. However, it's not because people do it that it should be encouraged. Security issues occur regularly because of compromised dependencies.
The best way to know if a software is safe to be used is to read its source code. However, it is extremely time-consuming and not in everyone's reach. At some point, we need to trust someone else, and it makes generally sense to trust the developers of the project, hence the signing mechanism. That's why the only two ways I see to get a good balance between convenience and safety are either to use immutable references (commit IDs) after having read the source code of the pre-commit hooks, or to ask pre-commit to verify the signatures of the remote references (Git tags, commits, or branches).
I suppose the locking mechanism you mentioned is the way-to-go, in particular because most people don't sign their work. If you agree with me, I would be happy to work on the implementation as soon as I get a bit more of free time.
asottile commentedon Jun 30, 2019
I'm not even sure a locking mechanism is necessary now that I think about it -- using
rev: <40-char sha1>is essentially your lock.asottile commentedon Jun 30, 2019
Maybe a convenience command to turn a config into a locked config?
SkypLabs commentedon Jun 30, 2019
It's what I thought initially but using a locking mechanism would be a way to detect drifts if your targeted Git tag has been changed to point to another commit since the last time you used
pre-commit install.asottile commentedon Jun 30, 2019
🤷♂ at that point who cares though -- you're just installing from a
shaSkypLabs commentedon Jun 30, 2019
I meant in the case where you use a Git tag in
.pre-commit-config.yaml, and not a commit ID directly.asottile commentedon Jun 30, 2019
Right so it would convert that to a sha1
Use commit ids in the pre-commit configuration
Use commit ids in the pre-commit configuration
ericfrederich commentedon Dec 3, 2019
Using a sha for the
revdoes work, the problem is that it breaks the autoupdate functionality.I would propose supporting both
revandshaat the same time. Or instead ofshamaybelock?pre-commit install-hooksshould verify that the two point to the same place.pre-commit autoupdateshould update based on therevand place the newshathere as well at the time of the update. In the future if these two deviate, it'll be detected before the malicious code is ran.If the user is using
autoupdate, then they'll never have to touch the sha themselves.Example
Nearly every other package manager or dependency manager is now supporting checksums in the form of lock files. This project should do the same.
asottile commentedon Dec 3, 2019
autoupdate works just fine, have you tried
--bleeding-edge?1 remaining item
ericfrederich commentedon Dec 3, 2019
@asottile running autoupdate replaces the sha with a tag. I'm asking that it replace the old tag with a new one and the old sha with a new one.
before
after
asottile commentedon Dec 3, 2019
I don't like repeating myself, but have you tried
--bleeding-edge? you seem to be talking past me which I do not appreciateericfrederich commentedon Dec 3, 2019
I have looked at
--bleeding-edge. This is not the behavior I would want. I'd do want to use a tag, for instancev2.4.0. I also want to be guaranteed that the code doesn't change out from under me if I clone and initialize the repo yesterday vs today.ericfrederich commentedon Dec 3, 2019
As for the merge conflict issue, I don't see how having a sha along for the ride changes anything. You'd have a merge conflict on the
shain any scenario where you'd also have a a merge conflict on arevasottile commentedon Dec 3, 2019
the ergonomics of a merge conflict are pretty important to me and I've seen them sour relationships with tools in the past, consider trying to resolve the following conflicts:
If you're paranoid (it seems you are) I'd suggest converting the shas manually until a reasonable proposal / implementation exists (as documented above)
ericfrederich commentedon Dec 3, 2019
@asottile I never suggested using a sha in place of a tag. Please re-read my posts. I even included examples. I'm suggesting to use them together at the same time.
This should not be a problem.
This config file won't be updated as often as other code. When it is modified, the majority of the time there will not be a merge conflict. This is because typically multiple people will not edit it at the same time. If they happen to, then you'd have to deal with it like any other merge conflict and not mix and match. Either take the
revandshafrom one commit or the other. Just don't mix and match. This is what the diff would look like.As an example, look at either...
... and find in the history when there has been a merge conflict involving those files.
asottile commentedon Dec 3, 2019
that's a breaking config change, it would need a new field and I don't think there's any advantage over just putting a sha1 in the rev field
ericfrederich commentedon Dec 3, 2019
If you use a sha, then you're not using a tag with all of its advantages.
autoupdateto work)Likewise, if you use a tag, then you're not using a sha with all of its advantages.
So, the advantage of having both as opposed to "just putting a sha1 in the rev field" is that you don't give up other advantages.
asottile commentedon Dec 3, 2019
sha1 in the rev field plus a comment is equivalent without needing special fields - it wouldn't be too difficult to make autoupdate spit out that format
I just don't see the value in having two fields given the tag would be purely informational and the
revfield already supports both (and theshafield is misnamed, deprecated, and forbidden whenrevis present currently)ericfrederich commentedon Dec 3, 2019
@asottile so having
revwith a sha value and a tag comment? That is what I'm currently doing but it's a manual process. See previous comment showing howautoupdatecurrently handles this.I always feel dirty putting data into comments. If the tool were able to update the comment too, that'd be better.
asottile commentedon Dec 3, 2019
yes, if that works for you we can make it happen
asottile commentedon Jan 2, 2020
This has been released as part of v1.21.0 -- thanks again for the issue 🎉!
SkypLabs commentedon Jan 3, 2020
Great! Thanks for the implementation.
Freeze the pre-commit hooks by using a hash as rev