-
-
Notifications
You must be signed in to change notification settings - Fork 90
Case insensitive tokens #249
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
base: master
Are you sure you want to change the base?
Changes from all commits
649aacd
6e842c1
df4f7d4
99c0b13
68fb37a
206cd6b
d0c99e1
eb49874
9830f08
23afdac
8144f94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,14 @@ class Session < ApplicationRecord | |
# hashed version in the database | ||
attr_reader :token | ||
|
||
def token=(plaintext) | ||
self.token_digest = Passwordless.digest(plaintext) | ||
@token = (plaintext) | ||
def token=(token) | ||
token = token.upcase if Passwordless.config.case_insensitive_tokens | ||
self.token_digest = Passwordless.digest(token) | ||
@token = token | ||
end | ||
|
||
def authenticate(token) | ||
token = token.upcase if Passwordless.config.case_insensitive_tokens | ||
Comment on lines
+36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only case-insensitive so long as you're using a key generator that only outputs UPPER CASE keys. I think the option is a bit misleading then. We should do the upcasing as part of the db lookup instead, so we're case-insensitive no matter the generator output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow. I believe this should work for a key generator that uses lower case keys (or mixed case, though that'd be silly). I'll add tests to confirm this when I have a chance. Note that since the generator output is hashed before it is persisted to the database, we cannot store a mixed case token and hope to look it up with a case insensitive token. |
||
token_digest == Passwordless.digest(token) | ||
end | ||
|
||
|
@@ -81,6 +83,7 @@ def set_defaults | |
|
||
self.token, self.token_digest = loop { | ||
token = Passwordless.config.token_generator.call(self) | ||
token = token.upcase if Passwordless.config.case_insensitive_tokens | ||
digest = Passwordless.digest(token) | ||
break [token, digest] if token_digest_available?(digest) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.