Skip to content

Cookies not being sent with secure: true #10754

@jkuester

Description

@jkuester

Describe the bug
In our api code for sending cookies to the user we have some logic for setting the secure attribute. (This attribute controls whether the cookie is only allowed to be sent via HTTPS and not just HTTP.) Unfortunately, this logic depends on the value of the NODE_ENV environment variable being set to production. Otherwise, we default to secure: false. However, it seems that we are no longer setting the NODE_ENV value anywhere in our containers/config. So, I do not think secure is ever getting set to true (even in production).

(It is also worth noting that we need secure: false when running the server locally for cht-core development since that is via HTTP.)

To Reproduce
Deploy a CHT server production-style (e.g. via Docker Helper).

Run this curl command with your instance info:

curl -v -k -X POST https://192-168-1-20.local-ip.medicmobile.org:37581 -H 'Content-Type: application/json' -d '{"user":"medic","password":"password"}' 2>&1 | grep -i set-cookie

See that the result is:

< set-cookie: login=force; Path=/; SameSite=Lax

Expected behavior

The result of the curl command should include Secure;. Like this:

< set-cookie: login=force; Path=/; Secure; SameSite=La

Additional context

This secure cookie logic based on NODE_ENV was added a long time ago: ae75e27.

I found this issue while reviewing this PR which is updating the logging to not be based on NODE_ENV.


I am not exactly sure what the best solution here is. We need to be able to toggle the secure value on for production and off for development. I wonder if maybe we just make NODE_ENV=production into our api Dockerfile and call it good... 🤔 I suppose any time we are running in Docker, we are running with HTTPS, correct?