@@ -103,6 +103,48 @@ class GoogleSignIn::CallbacksControllerTest < ActionDispatch::IntegrationTest
103103 assert_response :bad_request
104104 end
105105
106+ test "protecting against open redirects given a malformed URI" do
107+ post google_sign_in . authorization_url , params : { proceed_to : 'http://www.example.com\n\r@\n\revil.example.org/login' }
108+ assert_response :redirect
109+
110+ get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : flash [ :state ] )
111+ assert_response :bad_request
112+ end
113+
114+ test "rejects proceed_to paths if they are relative" do
115+ post google_sign_in . authorization_url , params : { proceed_to : 'login' }
116+ assert_response :redirect
117+
118+ get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : flash [ :state ] )
119+ assert_response :bad_request
120+ end
121+
122+ test "accepts proceed_to paths if they are absolute" do
123+ post google_sign_in . authorization_url , params : { proceed_to : '/login' }
124+ assert_response :redirect
125+
126+ stub_token_for '4/SgCpHSVW5-Cy' , access_token : 'ya29.GlwIBo' , id_token : 'eyJhbGciOiJSUzI'
127+
128+ get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : flash [ :state ] )
129+ assert_redirected_to 'http://www.example.com/login'
130+ end
131+
132+ test "protecting against open redirects given a double-slash net path" do
133+ post google_sign_in . authorization_url , params : { proceed_to : '//evil.example.org' }
134+ assert_response :redirect
135+
136+ get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : flash [ :state ] )
137+ assert_response :bad_request
138+ end
139+
140+ test "protecting against open redirects given a triple-slash net path" do
141+ post google_sign_in . authorization_url , params : { proceed_to : '///evil.example.org' }
142+ assert_response :redirect
143+
144+ get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : flash [ :state ] )
145+ assert_response :bad_request
146+ end
147+
106148 test "receiving no proceed_to URL" do
107149 get google_sign_in . callback_url ( code : '4/SgCpHSVW5-Cy' , state : 'invalid' )
108150 assert_response :bad_request
0 commit comments