mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 11:01:11 +08:00
we can't trust CSRF for anon the way it is designed.
The page they have loaded may be cached we need a different way of delivering the CSRF potentially
This commit is contained in:
@ -1,5 +1,10 @@
|
|||||||
class SessionController < ApplicationController
|
class SessionController < ApplicationController
|
||||||
|
|
||||||
|
# we need to allow account login with bad CSRF tokens, if people are caching, the CSRF token on the
|
||||||
|
# page is going to be empty, this means that server will see an invalid CSRF and blow the session
|
||||||
|
# once that happens you can't log in with social
|
||||||
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
requires_parameter(:login, :password)
|
requires_parameter(:login, :password)
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ class UsersController < ApplicationController
|
|||||||
|
|
||||||
before_filter :ensure_logged_in, only: [:username, :update, :change_email, :user_preferences_redirect]
|
before_filter :ensure_logged_in, only: [:username, :update, :change_email, :user_preferences_redirect]
|
||||||
|
|
||||||
|
# we need to allow account creation with bad CSRF tokens, if people are caching, the CSRF token on the
|
||||||
|
# page is going to be empty, this means that server will see an invalid CSRF and blow the session
|
||||||
|
# once that happens you can't log in with social
|
||||||
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = fetch_user_from_params
|
@user = fetch_user_from_params
|
||||||
user_serializer = UserSerializer.new(@user, scope: guardian, root: 'user')
|
user_serializer = UserSerializer.new(@user, scope: guardian, root: 'user')
|
||||||
|
@ -10,6 +10,15 @@ module ApplicationHelper
|
|||||||
include CanonicalURL::Helpers
|
include CanonicalURL::Helpers
|
||||||
include ConfigurableUrls
|
include ConfigurableUrls
|
||||||
|
|
||||||
|
def discourse_csrf_tags
|
||||||
|
# anon can not have a CSRF token cause these are all pages
|
||||||
|
# that may be cached, causing a mismatch between session CSRF
|
||||||
|
# and CSRF on page and horrible impossible to debug login issues
|
||||||
|
if current_user
|
||||||
|
csrf_meta_tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def with_format(format, &block)
|
def with_format(format, &block)
|
||||||
old_formats = formats
|
old_formats = formats
|
||||||
self.formats = [format]
|
self.formats = [format]
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<%= render :partial => "common/special_font_face" %>
|
<%= render :partial => "common/special_font_face" %>
|
||||||
<%= render :partial => "common/discourse_stylesheet" %>
|
<%= render :partial => "common/discourse_stylesheet" %>
|
||||||
|
|
||||||
<%= csrf_meta_tags %>
|
<%= discourse_csrf_tags %>
|
||||||
|
|
||||||
<%= yield :head %>
|
<%= yield :head %>
|
||||||
</head>
|
</head>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<%= render :partial => "common/special_font_face" %>
|
<%= render :partial => "common/special_font_face" %>
|
||||||
<%= render :partial => "common/discourse_stylesheet" %>
|
<%= render :partial => "common/discourse_stylesheet" %>
|
||||||
|
|
||||||
<%=csrf_meta_tags%>
|
<%= discourse_csrf_tags %>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
Reference in New Issue
Block a user