mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-17 13:43:05 +08:00
Use with: :clear_session on bad CSRF tokens
This commit is contained in:
parent
44732e4e59
commit
b8997d6ce2
3 changed files with 16 additions and 2 deletions
|
|
@ -19,6 +19,9 @@ config :mime, :types, %{
|
||||||
"text/plain" => ["livemd"]
|
"text/plain" => ["livemd"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# We want CSRF tokens to be logged to help users with debugging
|
||||||
|
config :plug_cowboy, :log_exceptions_with_status_code, [407..599]
|
||||||
|
|
||||||
config :livebook,
|
config :livebook,
|
||||||
app_service_name: nil,
|
app_service_name: nil,
|
||||||
app_service_url: nil,
|
app_service_url: nil,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ defmodule LivebookWeb.AuthPlug do
|
||||||
Stores in the session the secret for the given mode.
|
Stores in the session the secret for the given mode.
|
||||||
"""
|
"""
|
||||||
def store(conn, mode, value) do
|
def store(conn, mode, value) do
|
||||||
put_session(conn, key(conn.port, mode), hash(value))
|
conn
|
||||||
|
|> put_session(key(conn.port, mode), hash(value))
|
||||||
|
|> configure_session(renew: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,16 @@ defmodule LivebookWeb.Router do
|
||||||
plug :fetch_session
|
plug :fetch_session
|
||||||
plug :fetch_live_flash
|
plug :fetch_live_flash
|
||||||
plug :put_root_layout, {LivebookWeb.LayoutView, :root}
|
plug :put_root_layout, {LivebookWeb.LayoutView, :root}
|
||||||
plug :protect_from_forgery
|
# Because LIVEBOOK_SECRET_KEY_BASE authentication is randomly
|
||||||
|
# generated, the odds of getting a CSRFProtection is quite high
|
||||||
|
# and exceptions can lead to a poor user experience.
|
||||||
|
#
|
||||||
|
# During authentication, configure_session(renew: true) will
|
||||||
|
# override the configure_session(ignore: true) but the session
|
||||||
|
# will be cleared anyway. This means an attacker can authenticate
|
||||||
|
# someone in a given Livebook instance but they wouldn't be able
|
||||||
|
# to do anything once the authentication goes through.
|
||||||
|
plug :protect_from_forgery, with: :clear_session
|
||||||
plug :put_secure_browser_headers
|
plug :put_secure_browser_headers
|
||||||
plug :within_iframe_secure_headers
|
plug :within_iframe_secure_headers
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue