pbjoiner

pbjoiner

CORSPlug 3 Sends Access-Control-Allow-Origin: * When I'm Sure I Said Otherwise

TL;DR: I inherited this and no, I’m not qualified for this work. I’m setting my allowed origins but CORSPlug says “Access-Control-Allow-Origin: *” anyway.

Here’s the deets:

elixir --version
Erlang/OTP 24 [erts-12.3.2.13] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.14.5 (compiled with Erlang/OTP 24)

mix.exs

defp deps do
	[
		{:phoenix, "~> 1.5.3"},
		{:phoenix_ecto, "~> 4.1.0"},
		{:ecto_sql, "~> 3.4.5"},
		{:postgrex, ">= 0.0.0"},
		{:phoenix_html, "~> 2.1"},
		{:phoenix_live_reload, "~> 1.0", only: :dev},
		{:plug_cowboy, "~> 2.0"},
		{:httpoison, "~> 1.7.0"},
		{:poison, ">= 0.0.0"},
		{:hound, "~> 1.0"},
		{:cors_plug, "~> 3.0"},
		{:credo, "~> 0.3", only: [:dev, :test]},
		{:jason, "~> 1.0"},
		{:ssl_verify_fun, "~> 1.1.7", override: true}
	]
end

endpoint.ex (domains obfuscated)
plug CORSPlug, origin: ["https://sandbox.site.app", ~r/https?.*client\.edu$/]

router.ex (app name obfuscated)

defmodule ClientApp.Router do
  use ClientApp.Web, :router

  pipeline :api do
    plug :accepts, ["json"]
    plug CORSPlug
  end

  scope "/", ClientApp do
    pipe_through :api
    resources "/contacts", ContactController, only: [:create, :show]
  end
end

Marked As Solved

al2o3cr

al2o3cr

I’m not sure what’s causing your specific issue, but an observation:

CORSPlug calls halt when it responds to an OPTIONS request (so the first plug wins) but merges headers for other requests (so the second plug wins) - the instances in ClientApp.Endpoint and ClientApp.Router are likely to give unexpected results unless they are configured consistently. I don’t see any reason to have both.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement