Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward opts.secure to the cookies library to prevent silent error #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wille
Copy link

@wille wille commented Oct 28, 2024

If express thinks you are running over an unsecure connection, like when X-Forwarded-Proto is http, cookie-session will silently fail to set the session cookie (unless debugging is turned on)

This PR forwards options.secure to the cookies library.

I accidentally changed how my NGINX sends x-forwarded-* headers ,and even though it was running behind HTTPS, nginx would send the X-Forwared-Proto: http header and sessions on my site would start to fail completely, resuting in a big outage for users.

Code that fails

Cookies.prototype.set = function(name, value, opts) {
  // ...
  var secure = this.secure === undefined
    ? req.protocol === 'https' || isRequestEncrypted(req)
    : Boolean(this.secure)

  // ...

  if (!secure && opts && opts.secure) {
    throw new Error('Cannot send secure cookie over unencrypted connection')
  }

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.

1 participant