Skip to content
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

[MCC-286290] Add # to signature escape #7

Merged
merged 5 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# MAuth-Client History

## v4.0.3
- Updated signature to decode number sign (#) in requests

## v4.0.2
- Store the config data to not load the config file multiple times

Expand Down
10 changes: 8 additions & 2 deletions lib/mauth/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ def signature_valid!(object)
expected_for_percent_reencoding = object.string_to_sign(time: object.x_mws_time, app_uuid: object.signature_app_uuid)

# do a moderately complex Euresource-style reencoding of the path
object.attributes_for_signing[:request_url] = CGI.escape(original_request_uri.to_s)
object.attributes_for_signing[:request_url].gsub!('%2F', '/') # ...and then 'simply' decode the %2F's back into /'s, just like Euresource kind of does!
object.attributes_for_signing[:request_url] = euresource_escape(original_request_uri.to_s)
expected_euresource_style_reencoding = object.string_to_sign(time: object.x_mws_time, app_uuid: object.signature_app_uuid)

# reset the object original request_uri, just in case we need it again
Expand All @@ -383,6 +382,13 @@ def signature_valid!(object)
end
end

# Note: RFC 3986 (https://www.ietf.org/rfc/rfc3986.txt) reserves the forward slash "/"
# and number sign "#" as component delimiters. Since these are valid URI components,
# they are decoded back into characters here to avoid signature invalidation
def euresource_escape(str)
CGI.escape(str).gsub(/%2F|%23/, "%2F" => "/", "%23" => "#")
end

def retrieve_public_key(app_uuid)
retrieve_security_token(app_uuid)['security_token']['public_key_str']
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mauth/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MAuth
VERSION = '4.0.2'.freeze
VERSION = '4.0.3'.freeze
end
2 changes: 1 addition & 1 deletion spec/mauth_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def x_mws_authentication
it "considers a request to be authentic even if the request_url must be CGI::escape'ed (after being escaped in Euresource's own idiosyncratic way) before authenticity is achieved" do
['/v1/users/[email protected]', "! # $ & ' ( ) * + , / : ; = ? @ [ ]"].each do |path|
# imagine what are on the requester's side now...
signed_path = CGI.escape(path).gsub!('%2F','/') # This is what Euresource does to the path on the requester's side before the signing of the outgoing request occurs.
signed_path = CGI.escape(path).gsub!(/%2F|%23/, "%2F" => "/", "%23" => "#") # This is what Euresource does to the path on the requester's side before the signing of the outgoing request occurs.
request = TestSignableRequest.new(:verb => 'GET', :request_url => signed_path)
signed_request = @signing_mc.signed(request)

Expand Down