Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(api): long lived api keys #658
base: main
Are you sure you want to change the base?
feat(api): long lived api keys #658
Changes from 43 commits
c13cbf4
2014957
cae393c
eb5ec37
7357c02
8be5af3
909c125
f68a491
fdc843a
f01d4b1
3b70a01
eaac98b
ae56c78
4e49ba9
08db2c1
f58a42b
c0261b8
c6a586f
0f32c71
4be8366
d1a44d0
22d427e
8c962d2
4a70fa7
ea90ac2
2d743ca
951993e
5021800
a7f8f35
6d179bf
66345be
0c6203f
af4055f
b19a0b8
d490e27
e30ed2c
c6a9ef0
96dbbfa
1c3fad8
71c77e8
1ae90f1
1ef2c34
5d1df8a
a7c0a17
aec152c
ebe395d
8bf2bfa
9bb2a6f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Perhaps use constants for the magic numbers in this file or add more explanations in the comments are to why these (32, 4) numbers were chosen.
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.
We should also add some sort of versioning prefix here to add backwards compatibility in case we change the API key algorithm, etc.
Example:
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.
If we do this on the database side (see pgcrypto comment) do you think the
created_at
date in the table is sufficient for this?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.
Yeah, that would definitely work! In the future, we can just use the created_on date to determine key version in case we need to be backwards compatible.
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.
We should probably use a different method here, like
bcrypt
orpbkdf2_hmac
. Both are more secure, if not a little more computationally intensive. For example,1Password
uses a version ofpbkdf2_hmac
, I believe.https://security.stackexchange.com/questions/211/how-to-securely-hash-passwords
Example:
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.
If this is for security purposes, I would also toss pgcrypto in the running there as well.
Though if its not for security purposes then I think its unnecessary to change the algorithm any encoding will do if it gets the job done.
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.
Yeah, it was mainly for security best practice. It just depends on how secure we want these API keys to be!
You are right though - if we are only looking for functionality, everything here works.
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.
Yeah, definitely need security here. I'll look at these options
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.
Think I'm going with pgcrypto here. The main advantage is server side hashing. I will update when I finish the commit.
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.
I recommend changing this to
secrets.compare_digest(calculated_checksum, checksum)
https://pycharm-security.readthedocs.io/en/latest/fixes/comparedigestfixer.html