Skip to content

fix: dynamically default PHP_SESSION_COOKIE_SECURE based on BASE_URL - #466

Merged
ostefano merged 4 commits into
MISP:masterfrom
Diogo-Rego:fix/dynamic-session-cookie-secure
Oct 17, 2026
Merged

ostefano merged 4 commits into
MISP:masterfrom
Diogo-Rego:fix/dynamic-session-cookie-secure

Conversation

@Diogo-Rego

Copy link
Copy Markdown
Contributor

Fixes #463

When deploying misp-docker over plain HTTP with a custom Fully Qualified Domain Name (FQDN) in BASE_URL (e.g., http://misp.domain.com), modern browsers refuse to store or transmit cookies with the Secure flag set over insecure connections.

Previously, PHP_SESSION_COOKIE_SECURE defaulted unconditionally to true. While browsers grant localhost exemptions, domain-based HTTP deployments dropped the session cookie on login POST requests, causing MISP to display:

"You have tripped the cross-site request forgery protection of MISP"

This PR allows PHP_SESSION_COOKIE_SECURE to gracefully and dynamically adapt to the protocol defined in BASE_URL.

Changes

  • core/files/entrypoint.sh: When PHP_SESSION_COOKIE_SECURE is unset or empty, check BASE_URL. If it starts with http://, default PHP_SESSION_COOKIE_SECURE to false; otherwise default to true. Explicit user configurations are preserved.
  • docker-compose.yml: Removed hardcoded :-true fallback from PHP_SESSION_COOKIE_SECURE so unset variables pass through cleanly for container entrypoint evaluation.
  • template.env: Updated comments explaining the dynamic default behavior.

Default PHP_SESSION_COOKIE_SECURE to false when BASE_URL starts with
http://, preventing browser session cookie drops and CSRF errors on HTTP
custom domain deployments, while preserving explicit user overrides.
@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

Hi @ostefano, could you please take a look at these changes and let me know if they are OK to move forward? I have already tested them on my end and everything is working properly.

Comment thread template.env Outdated
@ostefano

Copy link
Copy Markdown
Collaborator

@Diogo-Rego see comment

@Diogo-Rego
Diogo-Rego requested a review from ostefano October 16, 2026 15:56
@Diogo-Rego

Copy link
Copy Markdown
Contributor Author

@ostefano
Since this is now automatically inferred from the BASE_URL protocol, there is no need to expose PHP_SESSION_COOKIE_SECURE as a setting anymore.

That said, would it be better to move this protocol check logic from entrypoint.sh directly into configure_misp.sh (inside set_up_session()), handling it entirely there during configuration?

Comment thread core/files/entrypoint.sh Outdated
export PHP_SESSION_AUTO_REGENERATE=${PHP_SESSION_AUTO_REGENERATE:-false}
export PHP_SESSION_CHECK_AGENT=${PHP_SESSION_CHECK_AGENT:-false}
export PHP_SESSION_COOKIE_SECURE=${PHP_SESSION_COOKIE_SECURE:-true}
if [ -z "${PHP_SESSION_COOKIE_SECURE}" ]; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we are half way there with this changeset. Either we expose the var, and allow both compose.yml and .env to modify it, or we assume that the user can not and shall not set it, and we always enable it if possible.

In other words, if we pick (1), my bad, please revert the change in template.
If we pick (2) then we need to remove the line from compose.yml and change the conditional here.

@pascaliske would you agree?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Option (2) as well. Since BASE_URL already strictly defines whether HTTP or HTTPS is used, automating it transparently is much cleaner and avoids unnecessary configuration knobs.

I've updated the PR accordingly:

  • Removed PHP_SESSION_COOKIE_SECURE entirely from docker-compose.yml (and template.env).
  • Evaluated session.cookie_secure directly based on BASE_URL inside configure_misp.sh (false if http://*, otherwise true).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit late with my reply... I think automatically configuring this based on BASE_URL is perfectly fine.

setting

Infer session.cookie_secure directly from BASE_URL in configure_misp.sh,
enabling it whenever possible without requiring or exposing the
PHP_SESSION_COOKIE_SECURE variable in docker-compose.yml and
template.env.
@Diogo-Rego
Diogo-Rego requested a review from ostefano October 17, 2026 10:09
@ostefano
ostefano merged commit e09516d into MISP:master Oct 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSRF error on login via HTTP with custom domain BASE_URL (requires PHP_SESSION_COOKIE_SECURE=false)

3 participants