rack-twilio-validator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/twilio-validator.rb +15 -3
- data/lib/rack/twilio-validator/version.rb +1 -1
- data/spec/twilio_validator_spec.rb +15 -1
- metadata +17 -11
@@ -16,7 +16,7 @@ module Rack
|
|
16
16
|
def _call(env)
|
17
17
|
@request = Rack::Request.new(env)
|
18
18
|
|
19
|
-
if unprotected_path? ||
|
19
|
+
if unprotected_path? || validate(env['HTTP_X_TWILIO_SIGNATURE'])
|
20
20
|
@app.call(env)
|
21
21
|
else
|
22
22
|
response = ::Twilio::TwiML::Response.new do |r|
|
@@ -37,8 +37,20 @@ module Rack
|
|
37
37
|
! protected_path?
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# Twilio currently strips the port from https requests. See
|
41
|
+
# https://www.twilio.com/docs/security under 'A Few Notes' for
|
42
|
+
# more info
|
43
|
+
def formatted_url
|
44
|
+
if @request.scheme == "https"
|
45
|
+
@request.url.gsub(/:#{@request.port}/, '')
|
46
|
+
else
|
47
|
+
@request.url
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate(signature)
|
52
|
+
validator = ::Twilio::Util::RequestValidator.new(@auth_token)
|
53
|
+
validator.validate(formatted_url, @request.params, signature)
|
42
54
|
end
|
43
55
|
end
|
44
56
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rack::TwilioValidator do
|
4
4
|
let(:auth_token) { "5cc8534fb3f86ff7e52d884562bcca18" }
|
5
|
-
let(:params) { {
|
5
|
+
let(:params) { { "foo" => "fizz", "bar" => "buzz" } }
|
6
6
|
let(:valid_signature) { "4C3R3E2C2TwiOkEwqznWMH1k3O8=" }
|
7
7
|
let(:uri) { "/twilio/endpoint"}
|
8
8
|
|
@@ -41,6 +41,20 @@ describe Rack::TwilioValidator do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
context "for a request with credentials in the url" do
|
45
|
+
it "drops the credentials in the url when validating the signature" do
|
46
|
+
post("http://username:password@example.org#{uri}", params, "HTTP_X_TWILIO_SIGNATURE" => valid_signature)
|
47
|
+
last_response.should be_ok
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "for an https request" do
|
52
|
+
it "drops the port when validating" do
|
53
|
+
post "https://example.org:7654#{uri}", params, "HTTP_X_TWILIO_SIGNATURE" => "U2ixEfmunlgHywjscRAc90fuucQ="
|
54
|
+
last_response.should be_ok
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
44
58
|
context "with an optional supplied protected path" do
|
45
59
|
let(:app) {
|
46
60
|
Rack::Builder.new do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-twilio-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
17
|
-
requirement: &
|
17
|
+
requirement: &2169224920 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2169224920
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: twilio-ruby
|
28
|
-
requirement: &
|
28
|
+
requirement: &2169223820 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2169223820
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2169222280 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2169222280
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rack-test
|
50
|
-
requirement: &
|
50
|
+
requirement: &2169221260 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2169221260
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &2169220460 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2169220460
|
70
70
|
description: Rack Middleware for validating twilio request signatures
|
71
71
|
email:
|
72
72
|
- xternal1+github@gmail.com
|
@@ -98,12 +98,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- - ! '>='
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: 2374040186925587672
|
101
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
105
|
none: false
|
103
106
|
requirements:
|
104
107
|
- - ! '>='
|
105
108
|
- !ruby/object:Gem::Version
|
106
109
|
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 2374040186925587672
|
107
113
|
requirements: []
|
108
114
|
rubyforge_project: rack-twilio-validator
|
109
115
|
rubygems_version: 1.6.2
|