-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use timingSafeEqual for signature comparision #8806
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, many thanks for following up on this! 🙏 💯
Out of curiosity, do you know how the timing attack prevented by timingSafeEqual
works? 🤔 (I sort of wonder if it's a problem that we check for all user tokens one by one in order.)
Looking at the code, this exact change only fixes the case where:
Standard equal works on byte level comparison, and bails early when bytes from (input[i], expected[i]) differ. This allows you to time the request and check how early the comparison fails. The later it fails, the further in the comparison you got and hence the more of the token sequence you guessed right. Using this method fixes it as it makes the comparison a constant amount of work preventing you from using a timing attack. As you've pointed out, there's a second problem with this code. The fact that we run this comparison sequentially on a list of results from the DB. The longer it takes, the more entries we scanned. |
Thanks for explaining @easyCZ! 👍
Yes, due to scopes:
We could decide to make this constant time by getting the tokens with scopes |
Yeah, as @easyCZ points out, this change by itself is not sufficient to mitigate an attack if the surrounding code is not also safe from timing attacks, so doing something to make the surrounding code constant time is also required.
Is this correct? My understanding is that the webhook payloads are signed with a shared secret, rather than with a token used to create them. This seems to be supported by the docs. Is there a way we can use a repository's |
ec40110
to
be55ea3
Compare
Based on my quick experiment, webhooks do get transferred to the new repository when a repo is renamed. |
Ok, I think i understand this a little better now. While we are iterating over multiple tokens to find one that can verify the signature, based on this comment, we will only iterate over as many tokens as GHE installations that the user has enabled pre-builds for. Given this is likely to be very few (1 in most cases?), I don't think it's an issue here. If we wanted to have a better way of looking up repos other than by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks! This looks good to me then. 👍
And works as intended ✨ ("fun" fact: since I logged in as roboquat
, I was able to "impersonate" you @andrew-farries to do the testing 😅 but that's expected when we share accounts like that)
Description
Address this comment in a previous review of the work to support GHE.
Related Issue(s)
How to test
Use the steps in the How to test section of #8574 to add a GHE integration and ensure that prebuilds are triggered as expected.
Release Notes