-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back the custom Base64 deocde mechanisms
- Loading branch information
Showing
8 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'base64' | ||
|
||
module JWT | ||
# Base64 helpers | ||
class Base64 | ||
class << self | ||
def url_encode(str) | ||
::Base64.encode64(str).tr('+/', '-_').gsub(/[\n=]/, '') | ||
end | ||
|
||
def url_decode(str) | ||
str += '=' * (4 - str.length.modulo(4)) | ||
::Base64.decode64(str.tr('-_', '+/')) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1cc5e8e
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.
@excpt would you consider releasing this as 2.4.2? Removing
JWT::Base64
was a breaking change for many of our apps.1cc5e8e
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.
1cc5e8e
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.
@ebarendt Just out of curiosity. Are you using these "internal" modules/classes in your app or are you referring that the more strict Base64 decoding is breaking your app?
1cc5e8e
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 have code that calls
::JWT::Base64.url_decode
. My team inherited this, and I haven't yet investigated to see if Ruby's Base64 would work instead.1cc5e8e
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 would recommend using the
::Base64.urlsafe_decode64
and::Base64.urlsafe_encode64
methods for your Base64 needs.The jwt gem unfortunately is and has to use the more loose base64 decoding that will just ignore non-alphabetic characters instead of consider the base64 payload as invalid. Think this mostly happens if the data has been manipulated by a human leaving blanks and newlines behind.
1cc5e8e
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.
Makes sense. I'm digging into our gem and making the change.
1cc5e8e
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're all set, thanks for quick responses.