acrolink

acrolink

I have noticed that the session cookie is not set to secure, how to turn the secure flag on for Phoenix sessions?

Showing Posts 1 to 8

Gazler

Gazler

Phoenix Core Team

You should have something like this in your endpoint:

  plug Plug.Session,
    store: :cookie,
    key: "_hello_key",
    signing_salt: "change_me"

This uses Plug.Session. One of the options is secure which can be passed as an option to the plug.

  plug Plug.Session,
    store: :cookie,
+   secure: true,
    key: "_hello_key",
    signing_salt: "change_me"
13
Post #1
OvermindDL1

OvermindDL1

This isn’t default? It really should be default! It’s not like it’s useful to javascript anyway considering it is encoded… ^.^;

Gazler

Gazler

Phoenix Core Team

They are different things.

secure means that the cookie should only be sent over HTTPS (this defaults to true in plug if using HTTPS, but won’t be true if you use HTTP behind a load balancer.)

I think the configuration you are referring to is http-only which determines if the cookie is available to JavaScript or not, which does default to true for cookie storage.

https://github.com/elixir-plug/plug/blob/e60914b10ab3a880c15de844d3b231893060aaea/lib/plug/conn/cookies.ex#L64

OvermindDL1

OvermindDL1

Ah, could use a more descriptive name (:send_of_https_only or so) I’d say. :slight_smile:

Gazler

Gazler

Phoenix Core Team
OvermindDL1

OvermindDL1

Ah cool! That should be linked in the docs with more of an explanation! :slight_smile:

zenw0lf

zenw0lf

That’s more like general knowledge related to web development in general, than related to any framework really.

Is something you should/can know without touching Phoenix at all.

apoorv-2204

apoorv-2204

What to when we want to put some session cookie based on env?
I am currently using this

@dev_env? Application.compile_env(:core, [:app_env], :prod) in ["dev", :dev]

  @session_options (case(!!@dev_env?) do
                      true ->
                        [
                          max_age: 120 * 60 * 60,
                          store: OPSWeb.Session.Store,
                          key: "_OPSWeb_",
                          signing_salt: "OPSWeb="
                        ]

                      false ->
                        [
                          max_age: 120 * 60 * 60,
                          store: OPSWeb.Session.Store,
                          key: "_OPSWeb_",
                          signing_salt: "OPSWeb=",
                          secure: true,
                          http_only: true
                        ]
                    end)

but when I want to get session options via function or compile env it fails
see issue

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews