NaN

NaN

Im using an ETS table to store sessions. The Cookie is not used to when accessing the ETS table. How do I prevent the set-cookie header from being sent?

This has no effect:

defmodule Session.RemCookies do
  import Plug.Conn

  def init(opts), do: opts

  def call(conn, _opts) do
    register_before_send(conn, fn conn ->
      # Remove all Set-Cookie headers from response
      %{conn | resp_headers: Enum.reject(conn.resp_headers, fn {key, _} ->
        String.downcase(key) == "set-cookie"
      end)}
    end)
  end
end

Showing Posts 1 to 9

derek-zhou

derek-zhou

Even if you have the session stored in ETS, you still need to store the session key as a cookie. Otherwise, how does your application tell which session to use for incoming request?

NaN

NaN OP

Passed as a query param. Like I said, its not used. Its spec for a reason. Cookie cannot be used.

derek-zhou

derek-zhou

While what you described might be theoretically possible, I don’t think it is supported by Plug.Session. The relevant code is here:

https://github.com/elixir-plug/plug/blob/587f365b8e5fed8329755028154b2e582120365a/lib/plug/session.ex#L72

It looks for a cookie.

NaN

NaN OP

Im not using a cookie because its a distributed service and uses cross site access for different elements on the page… the cookie is ignored.

derek-zhou

derek-zhou

If you are set on your way, I suggest you to write your own version of Plug.Session instead of twisting its arm. Plug.Session is only ~100 LOC.

You’d need to pass this query param for every single internal links, and heaven forbid if one of your user share a link.

NaN

NaN OP

How would you approach otherwise?

lud

lud

Can you use a different header?

dimitarvp

dimitarvp

If you have a common host and the services are all subdomains then a wildcard cookie could do the trick and circumvent the problem you mentioned above.

Or use JWT.

derek-zhou

derek-zhou

I do not understand your constraint, so please take the following with a grain of salt.

You can store a security token in local storage and use it as sorta API key in a custom header. 2 downsides:

  • Initial request will not have this key and will not be customized
  • You really need to make sure all javascript you use is trustworthy
— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews