Skip to content

Commit 9f497f3

Browse files
Tony Giangclaude
andcommitted
Load the OAuth consent screen in full so its form-action applies
Someone signed out when an app starts connecting signs in first, and the code form submits through Turbo. Turbo follows the redirect back to the consent screen and swaps in its body, so the document keeps the sign-in page's Content-Security-Policy, with form-action 'self'. Authorize then posts fine but the browser blocks the redirect to the app's callback. Mark the consent screen as needing a full reload, so it always arrives with its own policy, which allows the validated redirect origin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 21a5540 commit 9f497f3

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎app/views/oauth/authorizations/new.html.erb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
so the heading never repeats a claim Fizzy can't vouch for. %>
44
<% @page_title = "Connect this app to Fizzy" %>
55

6+
<%# Arriving by Turbo, as after signing in, would keep the previous page's
7+
Content-Security-Policy, whose form-action 'self' blocks the Authorize
8+
redirect to the app. A full load applies this page's own. %>
9+
<% content_for :head, turbo_page_requires_reload %>
10+
611
<% content_for :header do %>
712
<h1 class="header__title">Connect this app to Fizzy?</h1>
813

‎test/system/oauth_consent_test.rb‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,30 @@ class OauthConsentTest < ApplicationSystemTestCase
3030

3131
assert_current_path %r{\A#{Regexp.escape(callback)}\?.*code=}, url: true
3232
end
33+
34+
# Signing in submits through Turbo, which follows the redirect back to the
35+
# consent screen and swaps in its body without its headers. The document
36+
# would keep the sign-in page's form-action 'self' and block the redirect to
37+
# the client, so the consent screen must arrive as a full page load.
38+
test "authorizing after signing in mid-flow redirects the browser to the client" do
39+
client = Oauth::Client.create! name: "Loopback Tool", dynamically_registered: true,
40+
redirect_uris: %w[ http://localhost/oauth-test-callback ]
41+
callback = "http://localhost:#{Capybara.current_session.server.port}/oauth-test-callback"
42+
identity = users(:david).identity
43+
44+
visit new_oauth_authorization_url(script_name: nil, client_id: client.client_id, redirect_uri: callback,
45+
response_type: "code", code_challenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
46+
code_challenge_method: "S256", scope: "read", state: "xyz123")
47+
48+
fill_in "email_address", with: identity.email_address
49+
click_on "Let’s go"
50+
assert_selector "h1", text: "Check your email"
51+
fill_in "code", with: identity.magic_links.active.last.code
52+
send_keys :enter
53+
54+
assert_selector "h1", text: "Connect this app to Fizzy?"
55+
click_on "Authorize"
56+
57+
assert_current_path %r{\A#{Regexp.escape(callback)}\?.*code=}, url: true
58+
end
3359
end

0 commit comments

Comments
 (0)